Pyrogenesis  trunk
wmman.h
Go to the documentation of this file.
1 /* Copyright (c) 2011 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef INCLUDED_WMMAN
24 #define INCLUDED_WMMAN
25 
26 //
27 // <sys/mman.h>
28 //
29 
30 // mmap prot flags
31 #define PROT_NONE 0x00
32 #define PROT_READ 0x01
33 #define PROT_WRITE 0x02
34 #define PROT_EXEC 0x04
35 
36 // mmap flags
37 #define MAP_SHARED 0x01 // writes change the underlying file
38 #define MAP_PRIVATE 0x02 // writes do not affect the file (copy-on-write)
39 #define MAP_FIXED 0x04
40 // .. non-portable
41 #define MAP_ANONYMOUS 0x10 // backed by the pagefile; fd should be -1
42 #define MAP_NORESERVE 0x20 // see below
43 
44 // note: we need a means of only "reserving" virtual address ranges
45 // for the fixed-address expandable array mechanism. the non-portable
46 // MAP_NORESERVE flag says that no space in the page file need be reserved.
47 // the caller can still try to access the entire mapping, but might get
48 // SIGBUS if there isn't enough room to commit a page. Linux currently
49 // doesn't commit mmap-ed regions anyway, but we specify this flag to
50 // make sure of that in the future.
51 
52 #define MAP_FAILED ((void*)intptr_t(-1))
53 
54 extern void* mmap(void* start, size_t len, int prot, int flags, int fd, off_t offset);
55 extern int munmap(void* start, size_t len);
56 
57 extern int mprotect(void* addr, size_t len, int prot);
58 
59 // convert POSIX PROT_* flags to their Win32 PAGE_* enumeration equivalents.
60 LIB_API unsigned MemoryProtectionFromPosix(int prot);
61 
62 #endif // #ifndef INCLUDED_WMMAN
__int64 off_t
Definition: wposix_types.h:91
LIB_API unsigned MemoryProtectionFromPosix(int prot)
Definition: wmman.cpp:30
int mprotect(void *addr, size_t len, int prot)
Definition: wmman.cpp:67
int munmap(void *start, size_t len)
Definition: wmman.cpp:222
void * mmap(void *start, size_t len, int prot, int flags, int fd, off_t offset)
Definition: wmman.cpp:202