summaryrefslogtreecommitdiff
path: root/usr/src/man/man2/shmop.2
blob: 10a6cff4da06ad2b3f39fca80fef2e328ace9b73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
'\" te
.\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
.\" Copyright 1989 AT&T
.\" 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.
.\" 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.
.\" 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]
.TH shmop 2 "10 Mar 2008" "SunOS 5.11" "System Calls"
.SH NAME
shmop, shmat, shmdt \- shared memory operations
.SH SYNOPSIS
.LP
.nf
#include <sys/types.h>
#include <sys/shm.h>

\fBvoid *\fR\fBshmat\fR(\fBint\fR \fIshmid\fR, \fBconst void *\fR\fIshmaddr\fR, \fBint\fR \fIshmflg\fR);
.fi

.LP
.nf
\fBint\fR \fBshmdt\fR(\fBchar *\fR\fIshmaddr\fR);
.fi

.SS "Standard conforming"
.LP
.nf
\fBint\fR \fBshmdt\fR(\fBconst void *\fR\fIshmaddr\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBshmat()\fR function attaches the shared memory segment associated with
the shared memory identifier specified by \fIshmid\fR to the data segment of
the calling process.
.sp
.LP
The permission required for a shared memory control operation is given as
{\fItoken\fR}, where \fItoken\fR is the type of permission needed. The types of
permission are interpreted as follows:
.sp
.in +2
.nf
00400    READ by user
00200    WRITE by user
00040    READ by group
00020    WRITE by group
00004    READ by others
00002    WRITE by others
.fi
.in -2

.sp
.LP
See the \fIShared Memory Operation Permissions\fR section of \fBIntro\fR(2) for
more information.
.sp
.LP
For shared memory segments created with the \fBSHM_SHARE_MMU\fR or
\fBSHM_PAGEABLE\fR flags, the default protections cannot be changed so as to
prevent a single process from affecting other processes sharing the same shared
segment.
.sp
.LP
When (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) is true, virtual memory resources in
addition to shared memory itself are shared among processes that use the same
shared memory.
.sp
.LP
When (\fIshmflg\fR\fB&SHM_PAGEABLE\fR) is true, virtual memory resources are
shared and the dynamic shared memory (DISM) framework is created. The dynamic
shared memory can be resized dynamically within the specified size in
\fBshmget\fR(2). The DISM shared memory is pageable unless it is locked.
.sp
.LP
The shared memory segment is attached to the data segment of the calling
process at the address specified based on one of the  following criteria:
.RS +4
.TP
.ie t \(bu
.el o
If \fIshmaddr\fR is equal to \fB(void *) 0\fR, the segment is attached to the
first available address as selected by the system.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If  \fIshmaddr\fR is equal to  \fB(void\fR \fB*)\fR \fB0\fR and (
\fIshmflg\fR\fB&SHM_SHARE_MMU\fR\fI)\fR or (\fIshmflg\fR\fB&SHM_PAGEABLE\fR) is
true, then the segment is attached to the first available suitably aligned
address. When (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) or
(\fIshmflg\fR\fB&SHM_PAGEABLE\fR) is set, however, the permission given by
\fBshmget()\fR determines whether the segment is attached for reading or
reading and writing.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fIshmaddr\fR is not equal to \fB(void *) 0\fR and
(\fIshmflg\fR\fB&SHM_RND\fR) is true, the segment is attached to the address
given by (\fIshmaddr\fR\fB-\fR  (\fIshmaddr\fR modulus \fBSHMLBA\fR)).
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fIshmaddr\fR is not equal to \fB(void *) 0\fR and
(\fIshmflg\fR\fB&SHM_RND\fR) is false, the segment is attached to the address
given by \fIshmaddr\fR.
.RE
.RS +4
.TP
.ie t \(bu
.el o
The segment is attached for reading if (\fIshmflg\fR\fB&SHM_RDONLY\fR) is true
\fB{READ}\fR, otherwise it is attached for reading and writing
\fB{READ/WRITE}\fR.
.RE
.sp
.LP
The \fBshmdt()\fR function detaches from the calling process's data segment the
shared memory segment located at the address specified by \fIshmaddr\fR. If the
application is standard-conforming (see \fBstandards\fR(5)), the \fIshmaddr\fR
argument is of type \fBconst void *\fR. Otherwise it is of type \fBchar *\fR.
.sp
.LP
Shared memory segments must be explicitly removed after the last reference to
them has been removed.
.SH RETURN VALUES
.sp
.LP
Upon successful completion, \fBshmat()\fR returns the data segment start
address of the attached shared memory segment; \fBshmdt()\fR returns \fB0\fR.
Otherwise, \fB\(mi1\fR is returned, the shared memory segment is not attached,
and \fBerrno\fR is set to indicate the error.
.SH ERRORS
.sp
.LP
The \fBshmat()\fR function will fail if:
.sp
.ne 2
.mk
.na
\fB\fBEACCES\fR\fR
.ad
.RS 10n
.rt  
Operation permission is denied to the calling process (see \fBIntro\fR(2)).
.RE

.sp
.ne 2
.mk
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
.rt  
The \fIshmid\fR argument is not a valid shared memory identifier.
.sp
The \fIshmaddr\fR argument is not equal to 0, and the value of
(\fIshmaddr\fR\fB-\fR  (\fIshmaddr\fR modulus \fBSHMLBA\fR)) is an illegal
address.
.sp
The \fIshmaddr\fR argument is not equal to 0, is an illegal address, and
(\fIshmflg\fR\fB&SHM_RND\fR) is false.
.sp
The \fIshmaddr\fR argument is not equal to 0, is not properly aligned, and
(\fIshmfg\fR\fB&SHM_SHARE_MMU\fR) is true.
.sp
\fBSHM_SHARE_MMU\fR is not supported in certain architectures.
.sp
Both (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) and \fI(shmflg\fR\fB&SHM_PAGEABLE\fR)
are true.
.sp
(\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) is true and the shared memory segment
specified by \fBshmid()\fR had previously been attached by a call to
\fBshmat()\fR in which (\fIshmflg\fR\fB&SHM_PAGEABLE\fR) was true.
.sp
(\fIshmflg\fR\fB&SHM_PAGEABLE\fR) is true and the shared memory segment
specified by \fBshmid()\fR had previously been attached by a call to
\fBshmat()\fR in which (\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) was true.
.RE

.sp
.ne 2
.mk
.na
\fB\fBEMFILE\fR\fR
.ad
.RS 10n
.rt  
The number of shared memory segments attached to the calling process would
exceed the system-imposed limit.
.RE

.sp
.ne 2
.mk
.na
\fB\fBENOMEM\fR\fR
.ad
.RS 10n
.rt  
The available data space  is not large enough to accommodate the shared memory
segment.
.RE

.sp
.LP
The \fBshmdt()\fR function will fail if:
.sp
.ne 2
.mk
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
.rt  
The \fIshmaddr\fR argument is not the data segment start address of a shared
memory segment.
.RE

.sp
.ne 2
.mk
.na
\fB\fBENOMEM\fR\fR
.ad
.RS 10n
.rt  
(\fIshmflg\fR\fB&SHM_SHARE_MMU\fR) is true and attaching to the shared memory
segment would exceed a limit or resource control on locked memory.
.RE

.SH WARNINGS
.sp
.LP
Using a fixed value for the \fIshmaddr\fR argument can adversely affect
performance on certain platforms due to D-cache aliasing.
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
tab() box;
cw(2.75i) |cw(2.75i) 
lw(2.75i) |lw(2.75i) 
.
ATTRIBUTE TYPEATTRIBUTE VALUE
_
Interface StabilityCommitted
_
MT-LevelAsync-Signal-Safe
_
StandardSee \fBstandards\fR(5).
.TE

.SH SEE ALSO
.sp
.LP
\fBIntro\fR(2), \fBexec\fR(2), \fBexit\fR(2), \fBfork\fR(2), \fBshmctl\fR(2),
\fBshmget\fR(2), \fBattributes\fR(5), \fBstandards\fR(5)