From c67173fe362781d71c59d304a3b6cf9ba25409ae Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Wed, 29 Jul 2015 20:28:06 -0700 Subject: [PATCH] Switching to real page sizes, not allocation granularity. --- src/xenia/base/memory.h | 5 +++++ src/xenia/base/memory_win.cc | 10 ++++++++++ src/xenia/cpu/thread_state.cc | 3 +-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/xenia/base/memory.h b/src/xenia/base/memory.h index ee29359db..e24dd0d94 100644 --- a/src/xenia/base/memory.h +++ b/src/xenia/base/memory.h @@ -21,8 +21,13 @@ namespace xe { namespace memory { // Returns the native page size of the system, in bytes. +// This should be ~4KiB. size_t page_size(); +// Returns the allocation granularity of the system, in bytes. +// This is likely 64KiB. +size_t allocation_granularity(); + enum class PageAccess { kNoAccess = 0, kReadOnly = 1 << 0, diff --git a/src/xenia/base/memory_win.cc b/src/xenia/base/memory_win.cc index b2d6c96a1..27bcfb152 100644 --- a/src/xenia/base/memory_win.cc +++ b/src/xenia/base/memory_win.cc @@ -15,6 +15,16 @@ namespace xe { namespace memory { size_t page_size() { + static size_t value = 0; + if (!value) { + SYSTEM_INFO si; + GetSystemInfo(&si); + value = si.dwPageSize; + } + return value; +} + +size_t allocation_granularity() { static size_t value = 0; if (!value) { SYSTEM_INFO si; diff --git a/src/xenia/cpu/thread_state.cc b/src/xenia/cpu/thread_state.cc index d0c1f3846..bf5932591 100644 --- a/src/xenia/cpu/thread_state.cc +++ b/src/xenia/cpu/thread_state.cc @@ -50,8 +50,7 @@ ThreadState::ThreadState(Processor* processor, uint32_t thread_id, // only Protect() on system page granularity. stack_size = (stack_size + 0xFFF) & 0xFFFFF000; uint32_t stack_alignment = (stack_size & 0xF000) ? 0x1000 : 0x10000; - uint32_t stack_padding = - uint32_t(xe::memory::page_size()); // Host page size. + uint32_t stack_padding = 64 * 1024; // 0x4...0x7F is 64k. uint32_t actual_stack_size = stack_padding + stack_size; bool top_down = false; switch (stack_type) {