don't commit the entire 4gb address space on Windows

This commit is contained in:
Anthony Pesch 2017-08-12 23:37:48 -04:00
parent 0d59e0baf8
commit d9d8d14a6c
2 changed files with 15 additions and 3 deletions

View File

@ -77,12 +77,24 @@ int map_shared_memory(shmem_handle_t handle, size_t offset, void *start,
DWORD file_flags = access_to_file_flags(access);
void *ptr = MapViewOfFileEx(handle, file_flags, (DWORD)(offset >> 32),
(DWORD)offset, size, start);
return ptr == start;
if (ptr != start) {
return 0;
}
/* commit the pages backing the file mapping now */
DWORD protect = access_to_protection_flags(access);
ptr = VirtualAlloc(ptr, size, MEM_COMMIT, protect);
if (!ptr) {
return 0;
}
return 1;
}
shmem_handle_t create_shared_memory(const char *filename, size_t size,
enum page_access access) {
DWORD protect = access_to_protection_flags(access);
return CreateFileMapping(INVALID_HANDLE_VALUE, NULL, protect | SEC_COMMIT,
/* note, only reserve the pages for now */
return CreateFileMapping(INVALID_HANDLE_VALUE, NULL, protect | SEC_RESERVE,
(DWORD)(size >> 32), (DWORD)(size), filename);
}

View File

@ -75,7 +75,7 @@ struct address_space {
/*
* memory
a*/
*/
#define ADDRESS_SPACE_SIZE (UINT64_C(1) << 32)
enum region_type {