diff --git a/src/xenia/core/memory.cc b/src/xenia/core/memory.cc index 015c34144..4cfadea0f 100644 --- a/src/xenia/core/memory.cc +++ b/src/xenia/core/memory.cc @@ -19,11 +19,11 @@ #define USE_LOCKS 0 #define USE_DL_PREFIX 1 #define HAVE_MORECORE 0 -#define HAVE_MMAP 0 #define HAVE_MREMAP 0 #define malloc_getpagesize 4096 #define DEFAULT_GRANULARITY 64 * 1024 #define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T +#define MALLOC_ALIGNMENT 32 #include @@ -45,6 +45,8 @@ struct xe_memory { xe_ref_t ref; + size_t system_page_size; + size_t length; void* ptr; @@ -60,6 +62,14 @@ xe_memory_ref xe_memory_create(xe_memory_options_t options) { xe_memory_ref memory = (xe_memory_ref)xe_calloc(sizeof(xe_memory)); xe_ref_init((xe_ref)memory); +#if XE_PLATFORM(WIN32) + SYSTEM_INFO si; + GetSystemInfo(&si); + memory->system_page_size = si.dwPageSize; +#else +#error need to implement page size retrieval +#endif // WIN32 + memory->length = 0xC0000000; #if XE_PLATFORM(WIN32) @@ -155,9 +165,6 @@ uint32_t xe_memory_search_aligned(xe_memory_ref memory, size_t start, uint32_t xe_memory_heap_alloc(xe_memory_ref memory, uint32_t base_addr, uint32_t size, uint32_t flags) { - if (base_addr) { - return base_addr; - } XEASSERT(base_addr == 0); XEASSERT(flags == 0); diff --git a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc index d3ccc5596..9150e884f 100644 --- a/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc +++ b/src/xenia/kernel/modules/xboxkrnl/xboxkrnl_memory.cc @@ -69,6 +69,14 @@ X_STATUS xeNtAllocateVirtualMemory( uint32_t adjusted_size = *region_size_ptr; // TODO(benvanik): adjust based on page size flags/etc? + // TODO(benvanik): support different allocation types. + // Right now we treat everything as a commit and ignore allocations that have + // already happened. + if (*base_addr_ptr) { + // Having a pointer already means that this is likely a follow-on COMMIT. + return X_STATUS_SUCCESS; + } + // Allocate. uint32_t flags = 0; uint32_t addr = xe_memory_heap_alloc( @@ -86,7 +94,6 @@ X_STATUS xeNtAllocateVirtualMemory( } -// TODO(benvanik): remove state parameter. SHIM_CALL NtAllocateVirtualMemory_shim( xe_ppc_state_t* ppc_state, KernelState* state) { uint32_t base_addr_ptr = SHIM_GET_ARG_32(0); diff --git a/src/xenia/types.h b/src/xenia/types.h index a3542eed2..047580e36 100644 --- a/src/xenia/types.h +++ b/src/xenia/types.h @@ -104,6 +104,8 @@ typedef XECACHEALIGN volatile void xe_aligned_void_t; #define XEBITMASK(a, b) (((unsigned) -1 >> (31 - (b))) & ~((1U << (a)) - 1)) #define XESELECTBITS(value, a, b) ((value & XEBITMASK(a, b)) >> a) +#define XEROUNDUP(v, multiple) ((v) + (multiple) - 1 - ((v) - 1) % (multiple)) + #define XESUCCEED() goto XECLEANUP #define XEFAIL() goto XECLEANUP #define XEEXPECT(expr) if (!(expr) ) { goto XECLEANUP; }