2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH SHMOP 2 "Mar 10, 2008"
9 shmop, shmat, shmdt \- shared memory operations
13 #include <sys/types.h>
16 \fBvoid *\fR\fBshmat\fR(\fBint\fR \fIshmid\fR, \fBconst void *\fR\fIshmaddr\fR, \fBint\fR \fIshmflg\fR);
21 \fBint\fR \fBshmdt\fR(\fBchar *\fR\fIshmaddr\fR);
24 .SS "Standard conforming"
27 \fBint\fR \fBshmdt\fR(\fBconst void *\fR\fIshmaddr\fR);
33 The \fBshmat()\fR function attaches the shared memory segment associated with
34 the shared memory identifier specified by \fIshmid\fR to the data segment of
38 The permission required for a shared memory control operation is given as
39 {\fItoken\fR}, where \fItoken\fR is the type of permission needed. The types of
40 permission are interpreted as follows:
55 See the \fIShared Memory Operation Permissions\fR section of \fBIntro\fR(2) for
59 For shared memory segments created with the \fBSHM_SHARE_MMU\fR or
60 \fBSHM_PAGEABLE\fR flags, the default protections cannot be changed so as to
61 prevent a single process from affecting other processes sharing the same shared
65 When (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) is true, virtual memory resources in
66 addition to shared memory itself are shared among processes that use the same
70 When (\fIshmflg\fR\fB&SHM_PAGEABLE\fR) is true, virtual memory resources are
71 shared and the dynamic shared memory (DISM) framework is created. The dynamic
72 shared memory can be resized dynamically within the specified size in
73 \fBshmget\fR(2). The DISM shared memory is pageable unless it is locked.
76 The shared memory segment is attached to the data segment of the calling
77 process at the address specified based on one of the following criteria:
82 If \fIshmaddr\fR is equal to \fBNULL\fR, the segment is attached to the
83 first available address as selected by the system.
89 If \fIshmaddr\fR is equal to \fB(void\fR \fB*)\fR \fB0\fR and (
90 \fIshmflg\fR\fB&SHM_SHARE_MMU\fR\fI)\fR or (\fIshmflg\fR\fB&SHM_PAGEABLE\fR) is
91 true, then the segment is attached to the first available suitably aligned
92 address. When (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) or
93 (\fIshmflg\fR\fB&SHM_PAGEABLE\fR) is set, however, the permission given by
94 \fBshmget()\fR determines whether the segment is attached for reading or
101 If \fIshmaddr\fR is not equal to \fBNULL\fR and
102 (\fIshmflg\fR\fB&SHM_RND\fR) is true, the segment is attached to the address
103 given by (\fIshmaddr\fR\fB-\fR (\fIshmaddr\fR modulus \fBSHMLBA\fR)).
109 If \fIshmaddr\fR is not equal to \fBNULL\fR and
110 (\fIshmflg\fR\fB&SHM_RND\fR) is false, the segment is attached to the address
111 given by \fIshmaddr\fR.
117 The segment is attached for reading if (\fIshmflg\fR\fB&SHM_RDONLY\fR) is true
118 \fB{READ}\fR, otherwise it is attached for reading and writing
123 The \fBshmdt()\fR function detaches from the calling process's data segment the
124 shared memory segment located at the address specified by \fIshmaddr\fR. If the
125 application is standard-conforming (see \fBstandards\fR(5)), the \fIshmaddr\fR
126 argument is of type \fBconst void *\fR. Otherwise it is of type \fBchar *\fR.
129 Shared memory segments must be explicitly removed after the last reference to
130 them has been removed.
134 Upon successful completion, \fBshmat()\fR returns the data segment start
135 address of the attached shared memory segment; \fBshmdt()\fR returns \fB0\fR.
136 Otherwise, \fB\(mi1\fR is returned, the shared memory segment is not attached,
137 and \fBerrno\fR is set to indicate the error.
141 The \fBshmat()\fR function will fail if:
148 Operation permission is denied to the calling process (see \fBIntro\fR(2)).
157 The \fIshmid\fR argument is not a valid shared memory identifier.
159 The \fIshmaddr\fR argument is not equal to 0, and the value of
160 (\fIshmaddr\fR\fB-\fR (\fIshmaddr\fR modulus \fBSHMLBA\fR)) is an illegal
163 The \fIshmaddr\fR argument is not equal to 0, is an illegal address, and
164 (\fIshmflg\fR\fB&SHM_RND\fR) is false.
166 The \fIshmaddr\fR argument is not equal to 0, is not properly aligned, and
167 (\fIshmfg\fR\fB&SHM_SHARE_MMU\fR) is true.
169 \fBSHM_SHARE_MMU\fR is not supported in certain architectures.
171 Both (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) and \fI(shmflg\fR\fB&SHM_PAGEABLE\fR)
174 (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) is true and the shared memory segment
175 specified by \fBshmid()\fR had previously been attached by a call to
176 \fBshmat()\fR in which (\fIshmflg\fR\fB&SHM_PAGEABLE\fR) was true.
178 (\fIshmflg\fR\fB&SHM_PAGEABLE\fR) is true and the shared memory segment
179 specified by \fBshmid()\fR had previously been attached by a call to
180 \fBshmat()\fR in which (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) was true.
189 The number of shared memory segments attached to the calling process would
190 exceed the system-imposed limit.
199 The available data space is not large enough to accommodate the shared memory
205 The \fBshmdt()\fR function will fail if:
212 The \fIshmaddr\fR argument is not the data segment start address of a shared
222 (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) is true and attaching to the shared memory
223 segment would exceed a limit or resource control on locked memory.
229 Using a fixed value for the \fIshmaddr\fR argument can adversely affect
230 performance on certain platforms due to D-cache aliasing.
234 See \fBattributes\fR(5) for descriptions of the following attributes:
242 ATTRIBUTE TYPE ATTRIBUTE VALUE
244 Interface Stability Committed
246 MT-Level Async-Signal-Safe
248 Standard See \fBstandards\fR(5).
254 \fBIntro\fR(2), \fBexec\fR(2), \fBexit\fR(2), \fBfork\fR(2), \fBshmctl\fR(2),
255 \fBshmget\fR(2), \fBattributes\fR(5), \fBstandards\fR(5)