mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-10-14 02:24:02 +00:00
Memory allocated through win32 VirtualAlloc() is zero-filled. Likewise for
memory mmap()'ed with MAP_ANONYMOUS (equivalent to /dev/zero mapping but faster)
This commit is contained in:
parent
735c332ab7
commit
077a232acc
@ -286,10 +286,6 @@ void * vm_acquire(size_t size, int options)
|
|||||||
|
|
||||||
next_address = (char *)addr + size;
|
next_address = (char *)addr + size;
|
||||||
|
|
||||||
// Since I don't know the standard behavior of mmap(), zero-fill here
|
|
||||||
if (memset(addr, 0, size) != addr)
|
|
||||||
return VM_MAP_FAILED;
|
|
||||||
|
|
||||||
// Remap to 33-bit space
|
// Remap to 33-bit space
|
||||||
#ifdef USE_33BIT_ADDRESSING
|
#ifdef USE_33BIT_ADDRESSING
|
||||||
if (sizeof(void *) == 8 && (options & VM_MAP_33BIT)) {
|
if (sizeof(void *) == 8 && (options & VM_MAP_33BIT)) {
|
||||||
@ -305,10 +301,6 @@ void * vm_acquire(size_t size, int options)
|
|||||||
#ifdef HAVE_WIN32_VM
|
#ifdef HAVE_WIN32_VM
|
||||||
if ((addr = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE)) == NULL)
|
if ((addr = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE)) == NULL)
|
||||||
return VM_MAP_FAILED;
|
return VM_MAP_FAILED;
|
||||||
|
|
||||||
// Zero newly allocated memory
|
|
||||||
if (memset(addr, 0, size) != addr)
|
|
||||||
return VM_MAP_FAILED;
|
|
||||||
#else
|
#else
|
||||||
if ((addr = calloc(size, 1)) == 0)
|
if ((addr = calloc(size, 1)) == 0)
|
||||||
return VM_MAP_FAILED;
|
return VM_MAP_FAILED;
|
||||||
@ -365,10 +357,6 @@ int vm_acquire_fixed(void * addr, size_t size, int options)
|
|||||||
if (mmap((caddr_t)addr, size, VM_PAGE_DEFAULT, the_map_flags, fd, 0) == (void *)MAP_FAILED)
|
if (mmap((caddr_t)addr, size, VM_PAGE_DEFAULT, the_map_flags, fd, 0) == (void *)MAP_FAILED)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Since I don't know the standard behavior of mmap(), zero-fill here
|
|
||||||
if (memset(addr, 0, size) != addr)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
// Remap to 33-bit space
|
// Remap to 33-bit space
|
||||||
#ifdef USE_33BIT_ADDRESSING
|
#ifdef USE_33BIT_ADDRESSING
|
||||||
if (sizeof(void *) == 8 && (options & VM_MAP_33BIT)) {
|
if (sizeof(void *) == 8 && (options & VM_MAP_33BIT)) {
|
||||||
@ -392,9 +380,6 @@ int vm_acquire_fixed(void * addr, size_t size, int options)
|
|||||||
LPVOID ret_addr = VirtualAlloc(req_addr, req_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
|
LPVOID ret_addr = VirtualAlloc(req_addr, req_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
|
||||||
if (ret_addr != req_addr)
|
if (ret_addr != req_addr)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Zero newly allocated memory
|
|
||||||
if (memset(addr, 0, size) != addr)
|
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
#else
|
||||||
// Unsupported
|
// Unsupported
|
||||||
|
Loading…
Reference in New Issue
Block a user