Fixing malloc alighment and duplicate calls to NtAllocateVirtualMemory.

This commit is contained in:
Ben Vanik 2013-05-27 19:58:20 -07:00
parent 1d0ec64d40
commit f78e7945d4
3 changed files with 21 additions and 5 deletions

View File

@ -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 <third_party/dlmalloc/malloc.c.h>
@ -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);

View File

@ -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);

View File

@ -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; }