Merge commit 'b31320a79e2054c6739b5229259dbf98f3afc547' into merges
[unleashed.git] / share / man / man2 / shmop.2
blob88bdc50eb5622dadc90227e2143df7c00fa9d0d6
1 '\" te
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"
8 .SH NAME
9 shmop, shmat, shmdt \- shared memory operations
10 .SH SYNOPSIS
11 .LP
12 .nf
13 #include <sys/types.h>
14 #include <sys/shm.h>
16 \fBvoid *\fR\fBshmat\fR(\fBint\fR \fIshmid\fR, \fBconst void *\fR\fIshmaddr\fR, \fBint\fR \fIshmflg\fR);
17 .fi
19 .LP
20 .nf
21 \fBint\fR \fBshmdt\fR(\fBchar *\fR\fIshmaddr\fR);
22 .fi
24 .SS "Standard conforming"
25 .LP
26 .nf
27 \fBint\fR \fBshmdt\fR(\fBconst void *\fR\fIshmaddr\fR);
28 .fi
30 .SH DESCRIPTION
31 .sp
32 .LP
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
35 the calling process.
36 .sp
37 .LP
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:
41 .sp
42 .in +2
43 .nf
44 00400    READ by user
45 00200    WRITE by user
46 00040    READ by group
47 00020    WRITE by group
48 00004    READ by others
49 00002    WRITE by others
50 .fi
51 .in -2
53 .sp
54 .LP
55 See the \fIShared Memory Operation Permissions\fR section of \fBIntro\fR(2) for
56 more information.
57 .sp
58 .LP
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
62 segment.
63 .sp
64 .LP
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
67 shared memory.
68 .sp
69 .LP
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.
74 .sp
75 .LP
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:
78 .RS +4
79 .TP
80 .ie t \(bu
81 .el o
82 If \fIshmaddr\fR is equal to \fBNULL\fR, the segment is attached to the
83 first available address as selected by the system.
84 .RE
85 .RS +4
86 .TP
87 .ie t \(bu
88 .el o
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
95 reading and writing.
96 .RE
97 .RS +4
98 .TP
99 .ie t \(bu
100 .el o
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)).
105 .RS +4
107 .ie t \(bu
108 .el o
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.
113 .RS +4
115 .ie t \(bu
116 .el o
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
119 \fB{READ/WRITE}\fR.
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.
131 .SH RETURN VALUES
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.
138 .SH ERRORS
141 The \fBshmat()\fR function will fail if:
143 .ne 2
145 \fB\fBEACCES\fR\fR
147 .RS 10n
148 Operation permission is denied to the calling process (see \fBIntro\fR(2)).
152 .ne 2
154 \fB\fBEINVAL\fR\fR
156 .RS 10n
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
161 address.
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)
172 are true.
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.
184 .ne 2
186 \fB\fBEMFILE\fR\fR
188 .RS 10n
189 The number of shared memory segments attached to the calling process would
190 exceed the system-imposed limit.
194 .ne 2
196 \fB\fBENOMEM\fR\fR
198 .RS 10n
199 The available data space  is not large enough to accommodate the shared memory
200 segment.
205 The \fBshmdt()\fR function will fail if:
207 .ne 2
209 \fB\fBEINVAL\fR\fR
211 .RS 10n
212 The \fIshmaddr\fR argument is not the data segment start address of a shared
213 memory segment.
217 .ne 2
219 \fB\fBENOMEM\fR\fR
221 .RS 10n
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.
226 .SH WARNINGS
229 Using a fixed value for the \fIshmaddr\fR argument can adversely affect
230 performance on certain platforms due to D-cache aliasing.
231 .SH ATTRIBUTES
234 See \fBattributes\fR(5) for descriptions of the following attributes:
239 box;
240 c | c
241 l | l .
242 ATTRIBUTE TYPE  ATTRIBUTE VALUE
244 Interface Stability     Committed
246 MT-Level        Async-Signal-Safe
248 Standard        See \fBstandards\fR(5).
251 .SH SEE ALSO
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)