13 #if defined(__MINGW32__) || defined(_WIN32) 18 #ifdef __USE_FILE_OFFSET64 19 # define DWORD_HI(x) (x >> 32) 20 # define DWORD_LO(x) ((x) & 0xffffffff) 22 # define DWORD_HI(x) (0) 23 # define DWORD_LO(x) (x) 26 #define UNUSED(x) (void)(x) 28 void* mmap(
void* start,
size_t length,
int prot,
int flags,
int fd, off_t offset)
33 if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
36 if (!(flags & MAP_ANON) || offset)
38 }
else if (flags & MAP_ANON)
42 if (prot & PROT_WRITE) {
44 flProtect = PAGE_EXECUTE_READWRITE;
46 flProtect = PAGE_READWRITE;
47 }
else if (prot & PROT_EXEC) {
49 flProtect = PAGE_EXECUTE_READ;
50 else if (prot & PROT_EXEC)
51 flProtect = PAGE_EXECUTE;
53 flProtect = PAGE_READONLY;
55 off_t end = length + offset;
58 mmap_fd = INVALID_HANDLE_VALUE;
60 mmap_fd = (HANDLE)_get_osfhandle(fd);
61 h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL);
65 DWORD dwDesiredAccess;
66 if (prot & PROT_WRITE)
67 dwDesiredAccess = FILE_MAP_WRITE;
69 dwDesiredAccess = FILE_MAP_READ;
71 dwDesiredAccess |= FILE_MAP_EXECUTE;
72 if (flags & MAP_PRIVATE)
73 dwDesiredAccess |= FILE_MAP_COPY;
74 void *ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length);
83 void munmap(
void* addr,
size_t length)
87 UnmapViewOfFile(addr);