1shmop(2) System Calls shmop(2)
2
3
4
6 shmop, shmat, shmdt - shared memory operations
7
9 #include <sys/types.h>
10 #include <sys/shm.h>
11
12 void *shmat(int shmid, const void *shmaddr, int shmflg);
13
14
15 int shmdt(char *shmaddr);
16
17
18 Standard conforming
19 int shmdt(const void *shmaddr);
20
21
23 The shmat() function attaches the shared memory segment associated with
24 the shared memory identifier specified by shmid to the data segment of
25 the calling process.
26
27
28 The permission required for a shared memory control operation is given
29 as {token}, where token is the type of permission needed. The types of
30 permission are interpreted as follows:
31
32 00400 READ by user
33 00200 WRITE by user
34 00040 READ by group
35 00020 WRITE by group
36 00004 READ by others
37 00002 WRITE by others
38
39
40
41 See the Shared Memory Operation Permissions section of Intro(2) for
42 more information.
43
44
45 For shared memory segments created with the SHM_SHARE_MMU or SHM_PAGE‐
46 ABLE flags, the default protections cannot be changed so as to prevent
47 a single process from affecting other processes sharing the same shared
48 segment.
49
50
51 When (shmflg&SHM_SHARE_MMU) is true, virtual memory resources in addi‐
52 tion to shared memory itself are shared among processes that use the
53 same shared memory.
54
55
56 When (shmflg&SHM_PAGEABLE) is true, virtual memory resources are shared
57 and the dynamic shared memory (DISM) framework is created. The dynamic
58 shared memory can be resized dynamically within the specified size in
59 shmget(2). The DISM shared memory is pageable unless it is locked.
60
61
62 The shared memory segment is attached to the data segment of the call‐
63 ing process at the address specified based on one of the following
64 criteria:
65
66 o If shmaddr is equal to (void *) 0, the segment is attached
67 to the first available address as selected by the system.
68
69 o If shmaddr is equal to (void *) 0 and ( shm‐
70 flg&SHM_SHARE_MMU) or (shmflg&SHM_PAGEABLE) is true, then
71 the segment is attached to the first available suitably
72 aligned address. When (shmflg&SHM_SHARE_MMU) or (shm‐
73 flg&SHM_PAGEABLE) is set, however, the permission given by
74 shmget() determines whether the segment is attached for
75 reading or reading and writing.
76
77 o If shmaddr is not equal to (void *) 0 and (shmflg&SHM_RND)
78 is true, the segment is attached to the address given by
79 (shmaddr- (shmaddr modulus SHMLBA)).
80
81 o If shmaddr is not equal to (void *) 0 and (shmflg&SHM_RND)
82 is false, the segment is attached to the address given by
83 shmaddr.
84
85 o The segment is attached for reading if (shmflg&SHM_RDONLY)
86 is true {READ}, otherwise it is attached for reading and
87 writing {READ/WRITE}.
88
89
90 The shmdt() function detaches from the calling process's data segment
91 the shared memory segment located at the address specified by shmaddr.
92 If the application is standard-conforming (see standards(5)), the
93 shmaddr argument is of type const void *. Otherwise it is of type char
94 *.
95
96
97 Shared memory segments must be explicitly removed after the last refer‐
98 ence to them has been removed.
99
101 Upon successful completion, shmat() returns the data segment start
102 address of the attached shared memory segment; shmdt() returns 0. Oth‐
103 erwise, −1 is returned, the shared memory segment is not attached, and
104 errno is set to indicate the error.
105
107 The shmat() function will fail if:
108
109 EACCES Operation permission is denied to the calling process (see
110 Intro(2)).
111
112
113 EINVAL The shmid argument is not a valid shared memory identifier.
114
115 The shmaddr argument is not equal to 0, and the value of
116 (shmaddr- (shmaddr modulus SHMLBA)) is an illegal address.
117
118 The shmaddr argument is not equal to 0, is an illegal
119 address, and (shmflg&SHM_RND) is false.
120
121 The shmaddr argument is not equal to 0, is not properly
122 aligned, and (shmfg&SHM_SHARE_MMU) is true.
123
124 SHM_SHARE_MMU is not supported in certain architectures.
125
126 Both (shmflg&SHM_SHARE_MMU) and (shmflg&SHM_PAGEABLE) are
127 true.
128
129 (shmflg&SHM_SHARE_MMU) is true and the shared memory segment
130 specified by shmid() had previously been attached by a call
131 to shmat() in which (shmflg&SHM_PAGEABLE) was true.
132
133 (shmflg&SHM_PAGEABLE) is true and the shared memory segment
134 specified by shmid() had previously been attached by a call
135 to shmat() in which (shmflg&SHM_SHARE_MMU) was true.
136
137
138 EMFILE The number of shared memory segments attached to the calling
139 process would exceed the system-imposed limit.
140
141
142 ENOMEM The available data space is not large enough to accommodate
143 the shared memory segment.
144
145
146
147 The shmdt() function will fail if:
148
149 EINVAL The shmaddr argument is not the data segment start address of
150 a shared memory segment.
151
152
153 ENOMEM (shmflg&SHM_SHARE_MMU) is true and attaching to the shared
154 memory segment would exceed a limit or resource control on
155 locked memory.
156
157
159 Using a fixed value for the shmaddr argument can adversely affect per‐
160 formance on certain platforms due to D-cache aliasing.
161
163 See attributes(5) for descriptions of the following attributes:
164
165
166
167
168 ┌─────────────────────────────┬─────────────────────────────┐
169 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
170 ├─────────────────────────────┼─────────────────────────────┤
171 │Interface Stability │Committed │
172 ├─────────────────────────────┼─────────────────────────────┤
173 │MT-Level │Async-Signal-Safe │
174 ├─────────────────────────────┼─────────────────────────────┤
175 │Standard │See standards(5). │
176 └─────────────────────────────┴─────────────────────────────┘
177
179 Intro(2), exec(2), exit(2), fork(2), shmctl(2), shmget(2),
180 attributes(5), standards(5)
181
182
183
184SunOS 5.11 10 Mar 2008 shmop(2)