Commit 4f8facd0 by Nicolas Capens Committed by Nicolas Capens

Separate memory page size determination into a function.

BUG=15907357 Change-Id: I6f930527978e9e3672f48e38da6ac80efbf8cd22 Reviewed-on: https://swiftshader-review.googlesource.com/1140Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent b913188e
......@@ -31,6 +31,24 @@
#undef allocateZero
#undef deallocateZero
size_t memoryPageSize()
{
static int pageSize = 0;
if(pageSize == 0)
{
#if defined(_WIN32)
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
pageSize = systemInfo.dwPageSize;
#else
pageSize = sysconf(_SC_PAGESIZE);
#endif
}
return pageSize;
}
struct Allocation
{
// size_t bytes;
......@@ -79,15 +97,7 @@ void deallocate(void *memory)
void *allocateExecutable(size_t bytes)
{
int pageSize = 4096;
#if defined(_WIN32)
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
pageSize = systemInfo.dwPageSize;
#else
pageSize = getpagesize();
#endif
size_t pageSize = memoryPageSize();
return allocate((bytes + pageSize - 1) & -pageSize, pageSize);
}
......
......@@ -14,6 +14,8 @@
#include <stddef.h>
size_t memoryPageSize();
void *allocate(size_t bytes, int alignment = 16);
void *allocateZero(size_t bytes, int alignment = 16);
void deallocate(void *memory);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment