Page MenuHomeFreeBSD

D9066.id23967.diff
No OneTemporary

D9066.id23967.diff

Index: lib/libc/sys/shm_open.2
===================================================================
--- lib/libc/sys/shm_open.2
+++ lib/libc/sys/shm_open.2
@@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 18, 2013
+.Dd January 13, 2017
.Dt SHM_OPEN 2
.Os
.Sh NAME
@@ -171,7 +171,7 @@
.Dv O_TRUNC
flags may be used in portable programs.
.Pp
-The result of using
+POSIX specifications state that the result of using
.Xr open 2 ,
.Xr read 2 ,
or
@@ -179,19 +179,23 @@
on a shared memory object, or on the descriptor returned by
.Fn shm_open ,
is undefined.
-It is also undefined whether the shared memory object itself, or its
-contents, persist across reboots.
-.Pp
-In FreeBSD,
+However, the
+.Fx
+kernel implementation explicitly includes support for
.Xr read 2
and
-.Xr write 2
-on a shared memory object will fail with
-.Er EOPNOTSUPP
-and neither shared memory objects nor their contents persist across reboots.
+.Xr write 2 .
+.Pp
+Neither shared memory objects nor their contents persist across reboots.
+.Pp
+Writes to shared-memory objects are not possible until
+.Xr ftruncate 2
+has been called on them.
+See
+.Sx EXAMPLES .
.Sh ERRORS
-The following errors are defined for
-.Fn shm_open :
+.Fn shm_open
+fails with these error codes for these conditions:
.Bl -tag -width Er
.It Bq Er EINVAL
A flag other than
@@ -235,8 +239,8 @@
The required permissions (for reading or reading and writing) are denied.
.El
.Pp
-The following errors are defined for
-.Fn shm_unlink :
+.Fn shm_unlink
+fails with these error codes for these conditions:
.Bl -tag -width Er
.It Bq Er EFAULT
The
@@ -251,6 +255,26 @@
.Fn shm_unlink
requires write permission to the shared memory object.
.El
+.Sh EXAMPLES
+This example fails without the call to
+.Xr ftruncate 2 :
+.Bd -literal -compact
+
+ uint8_t buffer[getpagesize()];
+ ssize_t len;
+ int fd;
+
+ fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, 0600);
+ if (fd < 0)
+ err(EX_OSERR, "%s: shm_open", __func__);
+ if (ftruncate(fd, getpagesize()) < 0)
+ err(EX_IOERR, "%s: ftruncate", __func__);
+ len = pwrite(fd, buffer, getpagesize(), 0);
+ if (len < 0)
+ err(EX_IOERR, "%s: pwrite", __func__);
+ if (len != getpagesize())
+ errx(EX_IOERR, "%s: pwrite length mismatch", __func__);
+.Ed
.Sh SEE ALSO
.Xr close 2 ,
.Xr fstat 2 ,

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 11, 12:07 PM (12 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26861799
Default Alt Text
D9066.id23967.diff (2 KB)

Event Timeline