-
Notifications
You must be signed in to change notification settings - Fork 0
/
shmop.html
389 lines (284 loc) · 11.2 KB
/
shmop.html
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:27:04 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>SHMOP</title>
</head>
<body>
<h1 align="center">SHMOP</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">shmat, shmdt -
System V shared memory operations</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<sys/types.h> <br>
#include <sys/shm.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>void
*shmat(int</b> <i>shmid</i><b>, const void
*</b><i>shmaddr</i><b>, int</b> <i>shmflg</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
shmdt(const void *</b><i>shmaddr</i><b>);</b></p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>shmat() <br>
shmat</b>() attaches the System V shared memory segment
identified by <i>shmid</i> to the address space of the
calling process. The attaching address is specified by
<i>shmaddr</i> with one of the following criteria:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>If <i>shmaddr</i> is NULL, the system chooses a suitable
(unused) page-aligned address to attach the segment.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>If <i>shmaddr</i> isn’t NULL and <b>SHM_RND</b> is
specified in <i>shmflg</i>, the attach occurs at the address
equal to <i>shmaddr</i> rounded down to the nearest multiple
of <b>SHMLBA</b>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="85%">
<p>Otherwise, <i>shmaddr</i> must be a page-aligned address
at which the attach occurs.</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">In addition to
<b>SHM_RND</b>, the following flags may be specified in the
<i>shmflg</i> bit-mask argument: <b><br>
SHM_EXEC</b> (Linux-specific; since Linux 2.6.9)</p>
<p style="margin-left:22%;">Allow the contents of the
segment to be executed. The caller must have execute
permission on the segment.</p>
<p style="margin-left:11%;"><b>SHM_RDONLY</b></p>
<p style="margin-left:22%;">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, and the process must
have read and write permission for the segment. There is no
notion of a write-only shared memory segment.</p>
<p style="margin-left:11%;"><b>SHM_REMAP</b>
(Linux-specific)</p>
<p style="margin-left:22%;">This flag specifies that the
mapping of the segment should replace any existing mapping
in the range starting at <i>shmaddr</i> and continuing for
the size of the segment. (Normally, an <b>EINVAL</b> error
would result if a mapping already exists in this address
range.) In this case, <i>shmaddr</i> must not be NULL.</p>
<p style="margin-left:11%; margin-top: 1em">The
<b>brk</b>(2) value of the calling process is not altered by
the attach. The segment will automatically be detached at
process exit. The same segment may be attached as a read and
as a read-write one, and more than once, in the
process’s address space.</p>
<p style="margin-left:11%; margin-top: 1em">A successful
<b>shmat</b>() call updates the members of the
<i>shmid_ds</i> structure (see <b>shmctl</b>(2)) associated
with the shared memory segment as follows:</p>
<p style="margin-left:22%; margin-top: 1em"><i>shm_atime</i>
is set to the current time.</p>
<p style="margin-left:22%; margin-top: 1em"><i>shm_lpid</i>
is set to the process-ID of the calling process.</p>
<p style="margin-left:22%; margin-top: 1em"><i>shm_nattch</i>
is incremented by one.</p>
<p style="margin-left:11%; margin-top: 1em"><b>shmdt() <br>
shmdt</b>() detaches the shared memory segment located at
the address specified by <i>shmaddr</i> from the address
space of the calling process. The to-be-detached segment
must be currently attached with <i>shmaddr</i> equal to the
value returned by the attaching <b>shmat</b>() call.</p>
<p style="margin-left:11%; margin-top: 1em">On a successful
<b>shmdt</b>() call, the system updates the members of the
<i>shmid_ds</i> structure associated with the shared memory
segment as follows:</p>
<p style="margin-left:22%; margin-top: 1em"><i>shm_dtime</i>
is set to the current time.</p>
<p style="margin-left:22%; margin-top: 1em"><i>shm_lpid</i>
is set to the process-ID of the calling process.</p>
<p style="margin-left:22%; margin-top: 1em"><i>shm_nattch</i>
is decremented by one. If it becomes 0 and the segment is
marked for deletion, the segment is deleted.</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
<b>shmat</b>() returns the address of the attached shared
memory segment; on error, <i>(void *) -1</i> is
returned, and <i>errno</i> is set to indicate the cause of
the error.</p>
<p style="margin-left:11%; margin-top: 1em">On success,
<b>shmdt</b>() returns 0; on error -1 is returned, and
<i>errno</i> is set to indicate the cause of the error.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">When
<b>shmat</b>() fails, <i>errno</i> is set to one of the
following:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EACCES</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The calling process does not have the required
permissions for the requested attach type, and does not have
the <b>CAP_IPC_OWNER</b> capability in the user namespace
that governs its IPC namespace.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EIDRM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p><i>shmid</i> points to a removed identifier.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Invalid <i>shmid</i> value, unaligned (i.e., not
page-aligned and <b>SHM_RND</b> was not specified) or
invalid <i>shmaddr</i> value, or can’t attach segment
at <i>shmaddr</i>, or <b>SHM_REMAP</b> was specified and
<i>shmaddr</i> was NULL.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ENOMEM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>Could not allocate memory for the descriptor or for the
page tables.</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">When
<b>shmdt</b>() fails, <i>errno</i> is set as follows:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">There is no shared memory
segment attached at <i>shmaddr</i>; or, <i>shmaddr</i> is
not aligned on a page boundary.</p></td></tr>
</table>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">POSIX.1-2001,
POSIX.1-2008, SVr4.</p>
<p style="margin-left:11%; margin-top: 1em">In SVID 3 (or
perhaps earlier), the type of the <i>shmaddr</i> argument
was changed from <i>char *</i> into <i>const
void *</i>, and the returned type of <b>shmat</b>()
from <i>char *</i> into <i>void *</i>.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">After a
<b>fork</b>(2), the child inherits the attached shared
memory segments.</p>
<p style="margin-left:11%; margin-top: 1em">After an
<b>execve</b>(2), all attached shared memory segments are
detached from the process.</p>
<p style="margin-left:11%; margin-top: 1em">Upon
<b>_exit</b>(2), all attached shared memory segments are
detached from the process.</p>
<p style="margin-left:11%; margin-top: 1em">Using
<b>shmat</b>() with <i>shmaddr</i> equal to NULL is the
preferred, portable way of attaching a shared memory
segment. Be aware that the shared memory segment attached in
this way may be attached at different addresses in different
processes. Therefore, any pointers maintained within the
shared memory must be made relative (typically to the
starting address of the segment), rather than absolute.</p>
<p style="margin-left:11%; margin-top: 1em">On Linux, it is
possible to attach a shared memory segment even if it is
already marked to be deleted. However, POSIX.1 does not
specify this behavior and many other implementations do not
support it.</p>
<p style="margin-left:11%; margin-top: 1em">The following
system parameter affects <b>shmat</b>():</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>SHMLBA</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">Segment low boundary address
multiple. When explicitly specifying an attach address in a
call to <b>shmat</b>(), 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</b> is normally some multiple of the system page
size. (On many Linux architectures, <b>SHMLBA</b> is the
same as the system page size.)</p></td></tr>
</table>
<p style="margin-left:11%; margin-top: 1em">The
implementation places no intrinsic per-process limit on the
number of shared memory segments (<b>SHMSEG</b>).</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>brk</b>(2),
<b>mmap</b>(2), <b>shmctl</b>(2), <b>shmget</b>(2),
<b>capabilities</b>(7), <b>shm_overview</b>(7),
<b>sysvipc</b>(7)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>