Implement POSIX.1b shared memory objects. In this implementation,
shared memory objects are regular files; the shm_open(3) routine uses fcntl(2) to set a flag on the descriptor which tells mmap(2) to automatically apply MAP_NOSYNC. Not objected to by: bde, dillon, dufault, jasone
This commit is contained in:
parent
b39b38ecd0
commit
aa543039b5
@ -106,12 +106,12 @@
|
||||
/* bits to save after open */
|
||||
#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
|
||||
/* bits settable by fcntl(F_SETFL, ...) */
|
||||
#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
|
||||
#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The O_* flags used to have only F* names, which were used in the kernel
|
||||
* and by fcntl. We retain the F* names for the kernel f_flags field
|
||||
* and by fcntl. We retain the F* names for the kernel f_flag field
|
||||
* and for backward compatibility for fcntl.
|
||||
*/
|
||||
#ifndef _POSIX_SOURCE
|
||||
@ -123,6 +123,22 @@
|
||||
#define O_NDELAY O_NONBLOCK /* compat */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We are out of bits in f_flag (which is a short). However,
|
||||
* the flag bits not set in FMASK are only meaningful in the
|
||||
* initial open syscall. Those bits can thus be given a
|
||||
* different meaning for fcntl(2).
|
||||
*/
|
||||
#ifndef _POSIX_SOURCE
|
||||
|
||||
/*
|
||||
* Set by shm_open(3) to get automatic MAP_ASYNC behavior
|
||||
* for POSIX shared memory objects (which are otherwise
|
||||
* implemented as plain files).
|
||||
*/
|
||||
#define FPOSIXSHM O_NOFOLLOW
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Constants used for fcntl(2)
|
||||
*/
|
||||
|
@ -160,6 +160,10 @@
|
||||
#define _POSIX_MEMLOCK_RANGE
|
||||
#endif
|
||||
|
||||
/* ??? #define _POSIX_FSYNC 1 */
|
||||
#define _POSIX_MAPPED_FILES 1
|
||||
#define _POSIX_SHARED_MEMORY_OBJECTS 1
|
||||
|
||||
/* POSIX.1B sysconf options */
|
||||
#define _SC_ASYNCHRONOUS_IO 28
|
||||
#define _SC_MAPPED_FILES 29
|
||||
|
@ -282,6 +282,16 @@ mmap(p, uap)
|
||||
return (EBADF);
|
||||
if (fp->f_type != DTYPE_VNODE)
|
||||
return (EINVAL);
|
||||
/*
|
||||
* POSIX shared-memory objects are defined to have
|
||||
* kernel persistence, and are not defined to support
|
||||
* read(2)/write(2) -- or even open(2). Thus, we can
|
||||
* use MAP_ASYNC to trade on-disk coherence for speed.
|
||||
* The shm_open(3) library routine turns on the FPOSIXSHM
|
||||
* flag to request this behavior.
|
||||
*/
|
||||
if (fp->f_flag & FPOSIXSHM)
|
||||
flags |= MAP_NOSYNC;
|
||||
vp = (struct vnode *) fp->f_data;
|
||||
if (vp->v_type != VREG && vp->v_type != VCHR)
|
||||
return (EINVAL);
|
||||
|
Loading…
Reference in New Issue
Block a user