Implementing (maybe working) Win32 memory.cc.

This commit is contained in:
Ben Vanik 2013-01-30 01:45:55 -08:00
parent ae4d8ad40e
commit 9e05d44723
2 changed files with 20 additions and 7 deletions

View File

@ -9,7 +9,9 @@
#include <xenia/core/memory.h> #include <xenia/core/memory.h>
#if !XE_PLATFORM(WIN32)
#include <sys/mman.h> #include <sys/mman.h>
#endif // WIN32
#define MSPACES 1 #define MSPACES 1
#define USE_LOCKS 1 #define USE_LOCKS 1
@ -56,10 +58,17 @@ xe_memory_ref xe_memory_create(xe_pal_ref pal, xe_memory_options_t options) {
xe_ref_init((xe_ref)memory); xe_ref_init((xe_ref)memory);
memory->length = 0xC0000000; memory->length = 0xC0000000;
#if XE_PLATFORM(WIN32)
memory->ptr = VirtualAlloc(0, memory->length,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
#else
memory->ptr = mmap(0, memory->length, PROT_READ | PROT_WRITE, memory->ptr = mmap(0, memory->length, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0); MAP_PRIVATE | MAP_ANON, -1, 0);
XEEXPECTNOTNULL(memory->ptr);
XEEXPECT(memory->ptr != MAP_FAILED); XEEXPECT(memory->ptr != MAP_FAILED);
#endif // WIN32
XEEXPECTNOTNULL(memory->ptr);
// Allocate the mspace for our heap. // Allocate the mspace for our heap.
// We skip the first page to make writes to 0 easier to find. // We skip the first page to make writes to 0 easier to find.
@ -71,16 +80,20 @@ xe_memory_ref xe_memory_create(xe_pal_ref pal, xe_memory_options_t options) {
return memory; return memory;
XECLEANUP: XECLEANUP:
if (memory->heap) {
destroy_mspace(memory->heap);
}
xe_memory_release(memory); xe_memory_release(memory);
return NULL; return NULL;
} }
void xe_memory_dealloc(xe_memory_ref memory) { void xe_memory_dealloc(xe_memory_ref memory) {
destroy_mspace(memory->heap); if (memory->heap) {
destroy_mspace(memory->heap);
}
#if XE_PLATFORM(WIN32)
XEIGNORE(VirtualFree(memory->ptr, memory->length, MEM_RELEASE));
#else
munmap(memory->ptr, memory->length); munmap(memory->ptr, memory->length);
#endif // WIN32
} }
xe_memory_ref xe_memory_retain(xe_memory_ref memory) { xe_memory_ref xe_memory_retain(xe_memory_ref memory) {

View File

@ -1853,8 +1853,8 @@ static FORCEINLINE void x86_clear_lock(int* sl) {
#define CLEAR_LOCK(sl) x86_clear_lock(sl) #define CLEAR_LOCK(sl) x86_clear_lock(sl)
#else /* Win32 MSC */ #else /* Win32 MSC */
#define CAS_LOCK(sl) interlockedexchange(sl, (LONG)1) #define CAS_LOCK(sl) interlockedexchange((volatile unsigned int*)sl, 1)
#define CLEAR_LOCK(sl) interlockedexchange (sl, (LONG)0) #define CLEAR_LOCK(sl) interlockedexchange((volatile unsigned int*)sl, 0)
#endif /* ... gcc spins locks ... */ #endif /* ... gcc spins locks ... */