mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-01-11 10:30:09 +00:00
- Try to map memory contiguously with base addresses returned in increasing
order. No host memory region used for Mac emulation (ScratchMem, RAM, ROM, frame buffer) shall be allocated below the RAM space. Actually, MEMBaseDiff should be set to the min(above-mentioned address spaces). ==> Temporary fix for 64-bit addressing systems (e.g. Linux/ia64)
This commit is contained in:
parent
64eb0dcad1
commit
3896344ca1
@ -319,16 +319,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if USE_SCRATCHMEM_SUBTERFUGE
|
||||
// Allocate scratch memory
|
||||
ScratchMem = (uint8 *)vm_acquire(SCRATCH_MEM_SIZE);
|
||||
if (ScratchMem == VM_MAP_FAILED) {
|
||||
ErrorAlert(STR_NO_MEM_ERR);
|
||||
QuitEmulator();
|
||||
}
|
||||
ScratchMem += SCRATCH_MEM_SIZE/2; // ScratchMem points to middle of block
|
||||
#endif
|
||||
|
||||
// Create areas for Mac RAM and ROM
|
||||
#if REAL_ADDRESSING
|
||||
if (memory_mapped_from_zero) {
|
||||
@ -346,6 +336,16 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_SCRATCHMEM_SUBTERFUGE
|
||||
// Allocate scratch memory
|
||||
ScratchMem = (uint8 *)vm_acquire(SCRATCH_MEM_SIZE);
|
||||
if (ScratchMem == VM_MAP_FAILED) {
|
||||
ErrorAlert(STR_NO_MEM_ERR);
|
||||
QuitEmulator();
|
||||
}
|
||||
ScratchMem += SCRATCH_MEM_SIZE/2; // ScratchMem points to middle of block
|
||||
#endif
|
||||
|
||||
#if DIRECT_ADDRESSING
|
||||
// RAMBaseMac shall always be zero
|
||||
MEMBaseDiff = (uintptr)RAMBaseHost;
|
||||
|
@ -39,6 +39,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MMAP_VM
|
||||
static char * next_address = 0;
|
||||
#ifdef HAVE_MMAP_ANON
|
||||
#define map_flags (MAP_PRIVATE | MAP_ANON)
|
||||
#define zero_fd -1
|
||||
@ -95,9 +96,11 @@ void * vm_acquire(size_t size)
|
||||
return VM_MAP_FAILED;
|
||||
#else
|
||||
#ifdef HAVE_MMAP_VM
|
||||
if ((addr = mmap(0, size, VM_PAGE_DEFAULT, map_flags, zero_fd, 0)) == MAP_FAILED)
|
||||
if ((addr = mmap(next_address, size, VM_PAGE_DEFAULT, map_flags, zero_fd, 0)) == MAP_FAILED)
|
||||
return VM_MAP_FAILED;
|
||||
|
||||
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;
|
||||
@ -154,6 +157,10 @@ int vm_acquire_fixed(void * addr, size_t size)
|
||||
|
||||
int vm_release(void * addr, size_t size)
|
||||
{
|
||||
// Safety check: don't try to release memory that was not allocated
|
||||
if (addr == VM_MAP_FAILED)
|
||||
return 0;
|
||||
|
||||
#ifdef HAVE_MACH_VM
|
||||
int ret_code = vm_deallocate(mach_task_self(), (vm_address_t)addr, size);
|
||||
return ret_code == KERN_SUCCESS ? 0 : -1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user