1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Public Domain
5  * License:   Public Domain
6  * Authors:   Sean Kelly
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 module tango.stdc.posix.sys.mman;
10 
11 private import tango.stdc.posix.config;
12 public import tango.stdc.stddef;          // for size_t
13 public import tango.stdc.posix.sys.types; // for off_t, mode_t
14 
15 extern (C):
16 
17 //
18 // Advisory Information (ADV)
19 //
20 /*
21 int posix_madvise(void*, size_t, int);
22 */
23 
24 //
25 // Advisory Information and either Memory Mapped Files or Shared Memory Objects (MC1)
26 //
27 /*
28 POSIX_MADV_NORMAL
29 POSIX_MADV_SEQUENTIAL
30 POSIX_MADV_RANDOM
31 POSIX_MADV_WILLNEED
32 POSIX_MADV_DONTNEED
33 */
34 
35 version( linux )
36 {
37     const POSIX_MADV_NORMAL     = 0;
38     const POSIX_MADV_RANDOM     = 1;
39     const POSIX_MADV_SEQUENTIAL = 2;
40     const POSIX_MADV_WILLNEED   = 3;
41     const POSIX_MADV_DONTNEED   = 4;
42 }
43 else version( darwin )
44 {
45     const POSIX_MADV_NORMAL     = 0;
46     const POSIX_MADV_RANDOM     = 1;
47     const POSIX_MADV_SEQUENTIAL = 2;
48     const POSIX_MADV_WILLNEED   = 3;
49     const POSIX_MADV_DONTNEED   = 4;
50 }
51 else version( FreeBSD )
52 {
53     const POSIX_MADV_NORMAL     = 0;
54     const POSIX_MADV_RANDOM     = 1;
55     const POSIX_MADV_SEQUENTIAL = 2;
56     const POSIX_MADV_WILLNEED   = 3;
57     const POSIX_MADV_DONTNEED   = 4;
58 }
59 else version( solaris )
60 {
61 	enum
62 	{
63 		POSIX_MADV_NORMAL     = 0,
64 	    POSIX_MADV_RANDOM     = 1,
65 	    POSIX_MADV_SEQUENTIAL = 2,
66 	    POSIX_MADV_WILLNEED   = 3,
67 	    POSIX_MADV_DONTNEED   = 4
68 	}
69 }
70 
71 //
72 // Memory Mapped Files, Shared Memory Objects, or Memory Protection (MC2)
73 //
74 /*
75 PROT_READ
76 PROT_WRITE
77 PROT_EXEC
78 PROT_NONE
79 */
80 
81 version( linux )
82 {
83     const PROT_NONE     = 0x0;
84     const PROT_READ     = 0x1;
85     const PROT_WRITE    = 0x2;
86     const PROT_EXEC     = 0x4;
87 }
88 else version( darwin )
89 {
90     const PROT_NONE     = 0x00;
91     const PROT_READ     = 0x01;
92     const PROT_WRITE    = 0x02;
93     const PROT_EXEC     = 0x04;
94 }
95 else version( FreeBSD )
96 {
97     const PROT_NONE     = 0x00;
98     const PROT_READ     = 0x01;
99     const PROT_WRITE    = 0x02;
100     const PROT_EXEC     = 0x04;
101 }
102 else version( solaris )
103 {
104 	enum
105 	{
106 		PROT_NONE     = 0x00,
107 	    PROT_READ     = 0x01,
108 	    PROT_WRITE    = 0x02,
109 	    PROT_EXEC     = 0x04
110 	}
111 }
112 
113 //
114 // Memory Mapped Files, Shared Memory Objects, or Typed Memory Objects (MC3)
115 //
116 /*
117 void* mmap(void*, size_t, int, int, int, off_t);
118 int munmap(void*, size_t);
119 */
120 
121 version( linux )
122 {
123     //void* mmap(void*, size_t, int, int, int, off_t);
124     int   munmap(void*, size_t);
125 
126   static if( __USE_LARGEFILE64 )
127   {
128     void* mmap64(void*, size_t, int, int, int, off_t);
129     alias mmap64 mmap;
130   }
131   else
132   {
133     void* mmap(void*, size_t, int, int, int, off_t);
134   }
135 }
136 else version( darwin )
137 {
138     void* mmap(void*, size_t, int, int, int, off_t);
139     int   munmap(void*, size_t);
140 }
141 else version( FreeBSD )
142 {
143     void* mmap(void*, size_t, int, int, int, off_t);
144     int   munmap(void*, size_t);
145 }
146 else version( solaris )
147 {
148     int   munmap(void*, size_t);
149 
150   version(X86_64)
151 	void* mmap(void*, size_t, int, int, int, off_t);
152   else static if( __USE_LARGEFILE64 )
153   {
154     void* mmap64(void*, size_t, int, int, int, off_t);
155     alias mmap64 mmap;
156   }
157   else
158     void* mmap(void*, size_t, int, int, int, off_t);
159 }
160 
161 //
162 // Memory Mapped Files (MF)
163 //
164 /*
165 MAP_SHARED (MF|SHM)
166 MAP_PRIVATE (MF|SHM)
167 MAP_FIXED  (MF|SHM)
168 MAP_FAILED (MF|SHM)
169 
170 MS_ASYNC (MF|SIO)
171 MS_SYNC (MF|SIO)
172 MS_INVALIDATE (MF|SIO)
173 
174 int msync(void*, size_t, int); (MF|SIO)
175 */
176 
177 version( linux )
178 {
179     const MAP_SHARED    = 0x01;
180     const MAP_PRIVATE   = 0x02;
181     const MAP_FIXED     = 0x10;
182     const MAP_ANON      = 0x20; // non-standard
183 
184     const MAP_FAILED    = cast(void*) -1;
185 
186     enum
187     {
188         MS_ASYNC        = 1,
189         MS_SYNC         = 4,
190         MS_INVALIDATE   = 2
191     }
192 
193     int msync(void*, size_t, int);
194 }
195 else version( darwin )
196 {
197     const MAP_SHARED    = 0x0001;
198     const MAP_PRIVATE   = 0x0002;
199     const MAP_FIXED     = 0x0010;
200     const MAP_ANON      = 0x1000; // non-standard
201 
202     const MAP_FAILED    = cast(void*)-1;
203 
204     const MS_ASYNC      = 0x0001;
205     const MS_INVALIDATE = 0x0002;
206     const MS_SYNC       = 0x0010;
207 
208     int msync(void*, size_t, int);
209 }
210 else version( FreeBSD )
211 {
212     const MAP_SHARED    = 0x0001;
213     const MAP_PRIVATE   = 0x0002;
214     const MAP_FIXED     = 0x0010;
215     const MAP_ANON      = 0x1000; // non-standard
216 
217     const MAP_FAILED    = cast(void*)-1;
218 
219     const MS_SYNC       = 0x0000;
220     const MS_ASYNC      = 0x0001;
221     const MS_INVALIDATE = 0x0002;
222 
223     int msync(void*, size_t, int);
224 }
225 version( solaris )
226 {
227     const MAP_SHARED    = 0x001;
228     const MAP_PRIVATE   = 0x002;
229     const MAP_FIXED     = 0x010;
230     const MAP_ANON      = 0x100;
231 
232     const MAP_FAILED    = cast(void*) -1;
233 
234     enum
235     {
236         MS_ASYNC        = 0x1,
237         MS_SYNC         = 0x4,
238         MS_INVALIDATE   = 0x2
239     }
240 
241     int msync(void*, size_t, int);
242 }
243 
244 //
245 // Process Memory Locking (ML)
246 //
247 /*
248 MCL_CURRENT
249 MCL_FUTURE
250 
251 int mlockall(int);
252 int munlockall();
253 */
254 
255 version( linux )
256 {
257     const MCL_CURRENT   = 1;
258     const MCL_FUTURE    = 2;
259 
260     int mlockall(int);
261     int munlockall();
262 
263 }
264 else version( darwin )
265 {
266     const MCL_CURRENT   = 0x0001;
267     const MCL_FUTURE    = 0x0002;
268 
269     int mlockall(int);
270     int munlockall();
271 }
272 else version( FreeBSD )
273 {
274     const MCL_CURRENT   = 0x0001;
275     const MCL_FUTURE    = 0x0002;
276 
277     int mlockall(int);
278     int munlockall();
279 }
280 else version( solaris )
281 {
282 	const MCL_CURRENT   = 0x0001;
283     const MCL_FUTURE    = 0x0002;
284 
285     int mlockall(int);
286     int munlockall();
287 }
288 
289 //
290 // Range Memory Locking (MLR)
291 //
292 /*
293 int mlock(in void*, size_t);
294 int munlock(in void*, size_t);
295 */
296 
297 version( linux )
298 {
299     int mlock(in void*, size_t);
300     int munlock(in void*, size_t);
301 }
302 else version( darwin )
303 {
304     int mlock(in void*, size_t);
305     int munlock(in void*, size_t);
306 }
307 else version( FreeBSD )
308 {
309     int mlock(in void*, size_t);
310     int munlock(in void*, size_t);
311 }
312 else version( solaris )
313 {
314     int mlock(in void*, size_t);
315     int munlock(in void*, size_t);
316 }
317 
318 //
319 // Memory Protection (MPR)
320 //
321 /*
322 int mprotect(void*, size_t, int);
323 */
324 
325 version( linux )
326 {
327     int mprotect(void*, size_t, int);
328 }
329 else version( darwin )
330 {
331     int mprotect(void*, size_t, int);
332 }
333 else version( FreeBSD )
334 {
335     int mprotect(void*, size_t, int);
336 }
337 else version( solaris )
338 {
339     int mprotect(void*, size_t, int);
340 }
341 
342 //
343 // Shared Memory Objects (SHM)
344 //
345 /*
346 int shm_open(in char*, int, mode_t);
347 int shm_unlink(in char*);
348 */
349 
350 version( linux )
351 {
352     int shm_open(in char*, int, mode_t);
353     int shm_unlink(in char*);
354 }
355 else version( darwin )
356 {
357     int shm_open(in char*, int, mode_t);
358     int shm_unlink(in char*);
359 }
360 else version( FreeBSD )
361 {
362     int shm_open(in char*, int, mode_t);
363     int shm_unlink(in char*);
364 }
365 else version( solaris )
366 {
367     int shm_open(in char*, int, mode_t);
368     int shm_unlink(in char*);
369 }
370 
371 //
372 // Typed Memory Objects (TYM)
373 //
374 /*
375 POSIX_TYPED_MEM_ALLOCATE
376 POSIX_TYPED_MEM_ALLOCATE_CONTIG
377 POSIX_TYPED_MEM_MAP_ALLOCATABLE
378 
379 struct posix_typed_mem_info
380 {
381     size_t posix_tmi_length;
382 }
383 
384 int posix_mem_offset(in void*, size_t, off_t *, size_t *, int *);
385 int posix_typed_mem_get_info(int, struct posix_typed_mem_info *);
386 int posix_typed_mem_open(in char*, int, int);
387 */