.\"
.\" FIXME . Add an example program to this page.
.\"
-.TH SHMOP 2 2014-04-28 "Linux" "Linux Programmer's Manual"
+.TH SHMOP 2 2019-08-02 "Linux" "Linux Programmer's Manual"
.SH NAME
shmat, shmdt \- System V shared memory operations
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.B #include <sys/shm.h>
-
+.PP
.BI "void *shmat(int " shmid ", const void *" shmaddr ", int " shmflg );
-
+.PP
.BI "int shmdt(const void *" shmaddr );
.fi
.SH DESCRIPTION
If
.I shmaddr
is NULL,
-the system chooses a suitable (unused) address at which to attach
+the system chooses a suitable (unused) page-aligned address to attach
the segment.
.IP *
If
The caller must have execute permission on the segment.
.TP
.BR SHM_RDONLY
-Attach the segment read-only access.
+Attach the segment for read-only access.
The process must have read permission for the segment.
If this flag is not specified,
the segment is attached for read and write access,
is returned, and
.I errno
is set to indicate the cause of the error.
-
+.PP
On success,
.BR shmdt ()
returns 0; on error \-1 is returned, and
The calling process does not have the required permissions for
the requested attach type, and does not have the
.B CAP_IPC_OWNER
-capability.
+capability in the user namespace that governs its IPC namespace.
.TP
.B EIDRM
\fIshmid\fP points to a removed identifier.
.I shmaddr
is not aligned on a page boundary.
.SH CONFORMING TO
-SVr4, POSIX.1-2001.
+POSIX.1-2001, POSIX.1-2008, SVr4.
.\" SVr4 documents an additional error condition EMFILE.
-
+.PP
In SVID 3 (or perhaps earlier),
the type of the \fIshmaddr\fP argument was changed from
.I "char\ *"
.I "char\ *"
into
.IR "void\ *" .
-(Linux libc4 and libc5 have the
-.I "char\ *"
-prototypes; glibc2 has
-.IR "void\ *" .)
.SH NOTES
.PP
After a
.BR fork (2),
the child inherits the attached shared memory segments.
-
+.PP
After an
.BR execve (2),
all attached shared memory segments are detached from the process.
-
+.PP
Upon
.BR _exit (2),
all attached shared memory segments are detached from the process.
-
+.PP
Using
.BR shmat ()
with
.PP
On Linux, it is possible to attach a shared memory segment even if it
is already marked to be deleted.
-However, POSIX.1-2001 does not specify this behavior and
+However, POSIX.1 does not specify this behavior and
many other implementations do not support it.
-.LP
+.PP
The following system parameter affects
.BR shmat ():
.TP
-.\" FIXME A good explanation of the rationale for the existence
-.\" of SHMLBA would be useful here
.B SHMLBA
Segment low boundary address multiple.
-Must be page aligned.
-For the current implementation, the
+When explicitly specifying an attach address in a call to
+.BR shmat (),
+the caller should ensure that the address is a multiple of this value.
+This is necessary on some architectures,
+in order either to ensure good CPU cache performance or to ensure that
+different attaches of the same segment have consistent views
+within the CPU cache.
+.B SHMLBA
+is normally some multiple of the system page size.
+(On many Linux architectures,
.B SHMLBA
-value is
-.BR PAGE_SIZE .
-.\" FIXME That last sentence isn't true for all Linux
-.\" architectures (i.e., SHMLBA != PAGE_SIZE for some architectures)
-.\" -- MTK, Nov 04
+is the same as the system page size.)
.PP
The implementation places no intrinsic per-process limit on the
number of shared memory segments
.BR shmget (2),
.BR capabilities (7),
.BR shm_overview (7),
-.BR svipc (7)
+.BR sysvipc (7)