Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Basilisk II crash on Linux aarch64 #141

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion BasiliskII/src/CrossPlatform/vm_alloc.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ typedef unsigned long vm_uintptr_t;
#define MAP_ANONYMOUS 0
#endif

/* NOTE: on linux MAP_32BIT is only implemented on AMD64
it is a null op on all other architectures
thus the MAP_BASE setting below is the only thing
ensuring low addresses on aarch64 for example */
#define MAP_EXTRA_FLAGS (MAP_32BIT)

#ifdef HAVE_MMAP_VM
Expand All @@ -91,6 +95,16 @@ typedef unsigned long vm_uintptr_t;
don't get addresses above when the program is run on AMD64.
NOTE: this is empirically determined on Linux/x86. */
#define MAP_BASE 0x10000000
#elif DIRECT_ADDRESSING
/* linux does not implement any useful fallback behavior
such as allocating the next available address
and the first 4k-64k of address space is marked unavailable
for security reasons (see https://wiki.debian.org/mmap_min_addr)
so we must start requesting after the first page
or we get a high 64bit address that will crash direct addressing

leaving NULL unmapped is a good idea anyway for debugging reasons */
#define MAP_BASE 0x00010000
#else
#define MAP_BASE 0x00000000
#endif
Expand Down Expand Up @@ -255,9 +269,12 @@ void * vm_acquire(size_t size, int options)
if ((addr = mmap((caddr_t)next_address, size, VM_PAGE_DEFAULT, the_map_flags, fd, 0)) == (void *)MAP_FAILED)
return VM_MAP_FAILED;

// Sanity checks for 64-bit platforms
#if DIRECT_ADDRESSING
SegHaxx marked this conversation as resolved.
Show resolved Hide resolved
// Sanity check to prevent crash on 64-bit when direct addressing
// FIXME: this results in a misleading "out of memory" error to the user when it fails
if (sizeof(void *) == 8 && (options & VM_MAP_32BIT) && !((char *)addr <= (char *)0xffffffff))
return VM_MAP_FAILED;
#endif

next_address = (char *)addr + size;
#elif defined(HAVE_WIN32_VM)
Expand Down