1 /**
2 * D header file for POSIX.
3 *
4 * Copyright: Copyright Sean Kelly 2005 - 2009.
5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 * Authors: Sean Kelly
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8 */
9
10 /* Copyright Sean Kelly 2005 - 2009.
11 * Distributed under the Boost Software License, Version 1.0.
12 * (See accompanying file LICENSE or copy at
13 * http://www.boost.org/LICENSE_1_0.txt)
14 */
15 module core.sys.posix.sys.shm;
16
17 import core.sys.posix.config;
18 public import core.sys.posix.sys.types; // for pid_t, time_t, key_t
19 public import core.sys.posix.sys.ipc;
20
21 version (OSX)
22 version = Darwin;
23 else version (iOS)
24 version = Darwin;
25 else version (TVOS)
26 version = Darwin;
27 else version (WatchOS)
28 version = Darwin;
29
version(Posix)30 version (Posix):
31 extern (C) nothrow @nogc:
32 @system:
33
34 //
35 // XOpen (XSI)
36 //
37 /*
38 SHM_RDONLY
39 SHM_RND
40
41 shmatt_t
42
43 struct shmid_ds
44 {
45 ipc_perm shm_perm;
46 size_t shm_segsz;
47 pid_t shm_lpid;
48 pid_t shm_cpid;
49 shmatt_t shm_nattch;
50 time_t shm_atime;
51 time_t shm_dtime;
52 time_t shm_ctime;
53 }
54 */
55
56 version (linux)
57 {
58 enum SHM_RDONLY = 0x01000; // 010000
59 enum SHM_RND = 0x02000; // 020000
60 enum SHM_REMAP = 0x4000; // 040000
61
62 alias c_ulong shmatt_t;
63
64 /* For any changes, please check /usr/include/bits/shm.h */
65 struct shmid_ds
66 {
67 ipc_perm shm_perm;
68 size_t shm_segsz;
69 time_t shm_atime;
70 version (X86_64) {} else c_ulong __unused1;
71 time_t shm_dtime;
72 version (X86_64) {} else c_ulong __unused2;
73 time_t shm_ctime;
74 version (X86_64) {} else c_ulong __unused3;
75 pid_t shm_cpid;
76 pid_t shm_lpid;
77 shmatt_t shm_nattch;
78 c_ulong __unused4;
79 c_ulong __unused5;
80 }
81 }
82 else version (FreeBSD)
83 {
84 enum SHM_RDONLY = 0x01000; // 010000
85 enum SHM_RND = 0x02000; // 020000
86
87 alias c_ulong shmatt_t;
88
89 struct shmid_ds_old // <= FreeBSD7
90 {
91 ipc_perm_old shm_perm;
92 int shm_segsz;
93 pid_t shm_lpid;
94 pid_t shm_cpid;
95 short shm_nattch;
96 time_t shm_atime;
97 time_t shm_dtime;
98 time_t shm_ctime;
99 void* shm_internal;
100 }
101
102 struct shmid_ds
103 {
104 ipc_perm shm_perm;
105 int shm_segsz;
106 pid_t shm_lpid;
107 pid_t shm_cpid;
108 short shm_nattch;
109 time_t shm_atime;
110 time_t shm_dtime;
111 time_t shm_ctime;
112 }
113 }
114 else version (NetBSD)
115 {
116 enum SHM_RDONLY = 0x01000; // 010000
117 enum SHM_RND = 0x02000; // 020000
118
119 alias c_ulong shmatt_t;
120
121 struct shmid_ds
122 {
123 ipc_perm shm_perm;
124 size_t shm_segsz;
125 pid_t shm_lpid;
126 pid_t shm_cpid;
127 short shm_nattch;
128 time_t shm_atime;
129 time_t shm_dtime;
130 time_t shm_ctime;
131 void* shm_internal;
132 }
133 }
134 else version (OpenBSD)
135 {
136 enum SHM_RDONLY = 0x01000; // 010000
137 enum SHM_RND = 0x02000; // 020000
138
139 alias short shmatt_t;
140
141 struct shmid_ds
142 {
143 ipc_perm shm_perm;
144 int shm_segsz;
145 pid_t shm_lpid;
146 pid_t shm_cpid;
147 shmatt_t shm_nattch;
148 time_t shm_atime;
149 c_long __shm_atimensec;
150 time_t shm_dtime;
151 c_long __shm_dtimensec;
152 time_t shm_ctime;
153 c_long __shm_ctimensec;
154 void* shm_internal;
155 }
156 }
157 else version (DragonFlyBSD)
158 {
159 enum SHM_RDONLY = 0x01000; // 010000
160 enum SHM_RND = 0x02000; // 020000
161
162 alias c_ulong shmatt_t;
163
164 struct shmid_ds
165 {
166 ipc_perm shm_perm;
167 int shm_segsz;
168 pid_t shm_lpid;
169 pid_t shm_cpid;
170 short shm_nattch;
171 time_t shm_atime;
172 time_t shm_dtime;
173 time_t shm_ctime;
174 private void* shm_internal;
175 }
176 }
177 else version (Darwin)
178 {
179
180 }
181 else version (Solaris)
182 {
183
184 }
185 else
186 {
187 static assert(false, "Unsupported platform");
188 }
189
190 /*
191 SHMLBA
192
193 void* shmat(int, const scope void*, int);
194 int shmctl(int, int, shmid_ds*);
195 int shmdt(const scope void*);
196 int shmget(key_t, size_t, int);
197 */
198
199 version (CRuntime_Glibc)
200 {
201 int __getpagesize();
202 alias __getpagesize SHMLBA;
203
204 void* shmat(int, const scope void*, int);
205 int shmctl(int, int, shmid_ds*);
206 int shmdt(const scope void*);
207 int shmget(key_t, size_t, int);
208 }
209 else version (FreeBSD)
210 {
211 enum SHMLBA = 1 << 12; // PAGE_SIZE = (1<<PAGE_SHIFT)
212
213 void* shmat(int, const scope void*, int);
214 int shmctl(int, int, shmid_ds*);
215 int shmdt(const scope void*);
216 int shmget(key_t, size_t, int);
217 }
218 else version (NetBSD)
219 {
220 enum SHMLBA = 1 << 12; // PAGE_SIZE = (1<<PAGE_SHIFT)
221
222 void* shmat(int, const scope void*, int);
223 int shmctl(int, int, shmid_ds*);
224 int shmdt(const scope void*);
225 int shmget(key_t, size_t, int);
226 }
227 else version (OpenBSD)
228 {
229 enum SHMLBA = 1 << _MAX_PAGE_SHIFT;
230
231 void* shmat(int, const scope void*, int);
232 int shmctl(int, int, shmid_ds*);
233 int shmdt(const scope void*);
234 int shmget(key_t, size_t, int);
235 }
236 else version (DragonFlyBSD)
237 {
238 enum SHMLBA = 1 << 12; // PAGE_SIZE = (1<<PAGE_SHIFT)
239
240 void* shmat(int, const scope void*, int);
241 int shmctl(int, int, shmid_ds*);
242 int shmdt(const scope void*);
243 int shmget(key_t, size_t, int);
244 }
245 else version (Darwin)
246 {
247
248 }
249 else version (Solaris)
250 {
251
252 }
253 else version (CRuntime_Musl)
254 {
255 enum SHMLBA = 4096;
256
257 void* shmat(int, const scope void*, int);
258 int shmctl(int, int, shmid_ds*);
259 int shmdt(const scope void*);
260 int shmget(key_t, size_t, int);
261 }
262 else version (CRuntime_Bionic)
263 {
264 enum SHMLBA = 4096;
265
266 deprecated("Not useful on Android because it's disallowed by SELinux")
267 {
268 void* shmat(int, const scope void*, int);
269 int shmctl(int, int, shmid_ds*);
270 int shmdt(const scope void*);
271 int shmget(key_t, size_t, int);
272 }
273 }
274 else version (CRuntime_UClibc)
275 {
276 int __getpagesize();
277 alias __getpagesize SHMLBA;
278
279 void* shmat(int, const scope void*, int);
280 int shmctl(int, int, shmid_ds*);
281 int shmdt(const scope void*);
282 int shmget(key_t, size_t, int);
283 }
284 else
285 {
286 static assert(false, "Unsupported platform");
287 }
288