PageRenderTime 145ms CodeModel.GetById 61ms app.highlight 53ms RepoModel.GetById 23ms app.codeStats 0ms

/src/core/sys/posix/sys/mman.d

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