Use VirtualAlloc() instead of mmap() on Windows
This commit is contained in:
parent
e65f269766
commit
f7e077d8ef
@ -1,9 +1,13 @@
|
||||
#include "System.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdint.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
#include "windows.h"
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
unsigned long System::page_size;
|
||||
unsigned int System::page_size_log;
|
||||
@ -63,18 +67,30 @@ bool System::init(char * argv[])
|
||||
|
||||
void * System::alloc_pages(int num)
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
return VirtualAlloc(
|
||||
NULL,
|
||||
num << System::page_size_log,
|
||||
MEM_COMMIT | MEM_RESERVE,
|
||||
PAGE_READWRITE);
|
||||
#else
|
||||
return mmap(
|
||||
NULL,
|
||||
num * System::page_size,
|
||||
num << System::page_size_log,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS,
|
||||
-1,
|
||||
0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void System::free_pages(void * addr, int num)
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
(void)VirtualFree(addr, 0, MEM_RELEASE);
|
||||
#else
|
||||
(void)munmap(addr, num << System::page_size_log);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string System::executable_path()
|
||||
|
Loading…
x
Reference in New Issue
Block a user