version 1 showing authors affecting page license.
.
Rev |
Author |
# |
Line |
1 |
perry |
1 |
SHMOP |
|
|
2 |
!!!SHMOP |
|
|
3 |
NAME |
|
|
4 |
SYNOPSIS |
|
|
5 |
DESCRIPTION |
|
|
6 |
SYSTEM CALLS |
|
|
7 |
RETURN VALUE |
|
|
8 |
ERRORS |
|
|
9 |
NOTES |
|
|
10 |
CONFORMING TO |
|
|
11 |
SEE ALSO |
|
|
12 |
---- |
|
|
13 |
!!NAME |
|
|
14 |
|
|
|
15 |
|
|
|
16 |
shmop - shared memory operations |
|
|
17 |
!!SYNOPSIS |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
__# include |
|
|
21 |
____void *shmat ( int__ ''shmid''__, const void *__''shmaddr''__, int__ ''shmflg'' __)__ |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
__int shmdt ( const void |
|
|
25 |
*__''shmaddr''__)__ |
|
|
26 |
!!DESCRIPTION |
|
|
27 |
|
|
|
28 |
|
|
|
29 |
The function __shmat__ attaches the shared memory segment |
|
|
30 |
identified by __shmid__ to the data segment of the |
|
|
31 |
calling process. The attaching address is specified by |
|
|
32 |
''shmaddr'' with one of the following |
|
|
33 |
criteria: |
|
|
34 |
|
|
|
35 |
|
|
|
36 |
If ''shmaddr'' is __0__, the system tries to find an |
|
|
37 |
unmapped region in the range 1 - 1.5G starting from the |
|
|
38 |
upper value and coming down from there. |
|
|
39 |
|
|
|
40 |
|
|
|
41 |
If ''shmaddr'' isn't __0__ and __SHM_RND__ is |
|
|
42 |
asserted in ''shmflg'', the attach occurs at address |
|
|
43 |
equal to the rounding down of ''shmaddr'' to a multiple |
|
|
44 |
of __SHMLBA__. Otherwise ''shmaddr'' must be a page |
|
|
45 |
aligned address at which the attach occurs. |
|
|
46 |
|
|
|
47 |
|
|
|
48 |
If __SHM_RDONLY__ is asserted in ''shmflg'', the |
|
|
49 |
segment is attached for reading and the process must have |
|
|
50 |
read access permissions to the segment. Otherwise the |
|
|
51 |
segment is attached for read and write and the process must |
|
|
52 |
have read and write access permissions to the segment. There |
|
|
53 |
is no notion of write-only shared memory |
|
|
54 |
segment. |
|
|
55 |
|
|
|
56 |
|
|
|
57 |
The __brk__ value of the calling process is not altered |
|
|
58 |
by the attach. The segment will automatically detached at |
|
|
59 |
process exit. The same segment may be attached as a read and |
|
|
60 |
as a read-write one, and more than once, in the process's |
|
|
61 |
address space. |
|
|
62 |
|
|
|
63 |
|
|
|
64 |
On a successful __shmat__ call the system updates the |
|
|
65 |
members of the structure __shmid_ds__ associated to the |
|
|
66 |
shared memory segment as follows: |
|
|
67 |
|
|
|
68 |
|
|
|
69 |
__shm_atime__ is set to the current time. |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
__shm_lpid__ is set to the process-ID of the calling |
|
|
73 |
process. |
|
|
74 |
|
|
|
75 |
|
|
|
76 |
__shm_nattch__ is incremented by one. |
|
|
77 |
|
|
|
78 |
|
|
|
79 |
Note that the attach succeeds also if the shared memory |
|
|
80 |
segment is marked as to be deleted. |
|
|
81 |
|
|
|
82 |
|
|
|
83 |
The function __shmdt__ detaches from the calling |
|
|
84 |
process's data segment the shared memory segment located at |
|
|
85 |
the address specified by ''shmaddr''. The detaching |
|
|
86 |
shared memory segment must be one among the currently |
|
|
87 |
attached ones (to the process's address space) with |
|
|
88 |
''shmaddr'' equal to the value returned by the its |
|
|
89 |
attaching __shmat__ call. |
|
|
90 |
|
|
|
91 |
|
|
|
92 |
On a successful __shmdt__ call the system updates the |
|
|
93 |
members of the structure __shmid_ds__ associated to the |
|
|
94 |
shared memory segment as follows: |
|
|
95 |
|
|
|
96 |
|
|
|
97 |
__shm_dtime__ is set to the current time. |
|
|
98 |
|
|
|
99 |
|
|
|
100 |
__shm_lpid__ is set to the process-ID of the calling |
|
|
101 |
process. |
|
|
102 |
|
|
|
103 |
|
|
|
104 |
__shm_nattch__ is decremented by one. If it becomes 0 and |
|
|
105 |
the segment is marked for deletion, the segment is |
|
|
106 |
deleted. |
|
|
107 |
|
|
|
108 |
|
|
|
109 |
The occupied region in the user space of the calling process |
|
|
110 |
is unmapped. |
|
|
111 |
!!SYSTEM CALLS |
|
|
112 |
|
|
|
113 |
|
|
|
114 |
__fork()__ |
|
|
115 |
|
|
|
116 |
|
|
|
117 |
After a __fork()__ the child inherits the attached shared |
|
|
118 |
memory segments. |
|
|
119 |
|
|
|
120 |
|
|
|
121 |
__exec()__ |
|
|
122 |
|
|
|
123 |
|
|
|
124 |
After an __exec()__ all attached shared memory segments |
|
|
125 |
are detached (not destroyed). |
|
|
126 |
|
|
|
127 |
|
|
|
128 |
__exit()__ |
|
|
129 |
|
|
|
130 |
|
|
|
131 |
Upon __exit()__ all attached shared memory segments are |
|
|
132 |
detached (not destroyed). |
|
|
133 |
!!RETURN VALUE |
|
|
134 |
|
|
|
135 |
|
|
|
136 |
On a failure both functions return __-1__ with |
|
|
137 |
__errno__ indicating the error, otherwise __shmat__ |
|
|
138 |
returns the address of the attached shared memory segment, |
|
|
139 |
and __shmdt__ returns __0__. |
|
|
140 |
!!ERRORS |
|
|
141 |
|
|
|
142 |
|
|
|
143 |
When __shmat__ fails, at return __errno__ will be set |
|
|
144 |
to one among the following values: |
|
|
145 |
|
|
|
146 |
|
|
|
147 |
__EACCES__ |
|
|
148 |
|
|
|
149 |
|
|
|
150 |
The calling process has no access permissions for the |
|
|
151 |
requested attach type. |
|
|
152 |
|
|
|
153 |
|
|
|
154 |
__EINVAL__ |
|
|
155 |
|
|
|
156 |
|
|
|
157 |
Invalid ''shmid'' value, unaligned (i.e., not |
|
|
158 |
page-aligned and __SHM_RND__ was not specified) or |
|
|
159 |
invalid ''shmaddr'' value, or failing attach at |
|
|
160 |
__brk__. |
|
|
161 |
|
|
|
162 |
|
|
|
163 |
__ENOMEM__ |
|
|
164 |
|
|
|
165 |
|
|
|
166 |
Could not allocate memory for the descriptor or for the page |
|
|
167 |
tables. |
|
|
168 |
|
|
|
169 |
|
|
|
170 |
The function __shmdt__ can fails only if there is no |
|
|
171 |
shared memory segment attached at ''shmaddr'', in such a |
|
|
172 |
case at return __errno__ will be set to |
|
|
173 |
__EINVAL__. |
|
|
174 |
!!NOTES |
|
|
175 |
|
|
|
176 |
|
|
|
177 |
On executing a fork(2) system call, the child |
|
|
178 |
inherits all the attached shared memory |
|
|
179 |
segments. |
|
|
180 |
|
|
|
181 |
|
|
|
182 |
The shared memory segments attached to a process executing |
|
|
183 |
an execve(2) system call will not be attached to the |
|
|
184 |
resulting process. |
|
|
185 |
|
|
|
186 |
|
|
|
187 |
The following is a system parameter affecting a __shmat__ |
|
|
188 |
system call: |
|
|
189 |
|
|
|
190 |
|
|
|
191 |
__SHMLBA__ |
|
|
192 |
|
|
|
193 |
|
|
|
194 |
Segment low boundary address multiple. Must be page aligned. |
|
|
195 |
For the current implementation the __SHMBLA__ value is |
|
|
196 |
__PAGE_SIZE__. |
|
|
197 |
|
|
|
198 |
|
|
|
199 |
The implementation has no intrinsic limit to the per process |
|
|
200 |
maximum number of shared memory segments |
|
|
201 |
(__SHMSEG__) |
|
|
202 |
!!CONFORMING TO |
|
|
203 |
|
|
|
204 |
|
|
|
205 |
SVr4, SVID. SVr4 documents an additional error condition |
|
|
206 |
EMFILE. In SVID-v4 the type of the ''shmaddr'' argument |
|
|
207 |
was changed from __char *__ into __const void *__, and |
|
|
208 |
the returned type of ''shmat''() from __char *__ into |
|
|
209 |
__void *__. (Linux libc4 and libc5 have the __char *__ |
|
|
210 |
prototypes; glibc2 has __void *__.) |
|
|
211 |
!!SEE ALSO |
|
|
212 |
|
|
|
213 |
|
|
|
214 |
ipc(5), shmctl(2), |
|
|
215 |
shmget(2) |
|
|
216 |
---- |