From dc998f7b201ee96a61e2ce8f3222624053d9f644 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Tue, 5 Nov 2024 10:33:12 -0800 Subject: [PATCH] Platform-independent heap pos This appears to work on both Linux and macOS, and passes all tests. --- ffi/vmlib/build.rs | 10 ---------- vm/entrypoint/src/syscalls/memory.rs | 15 +++++---------- 2 files changed, 5 insertions(+), 20 deletions(-) delete mode 100644 ffi/vmlib/build.rs diff --git a/ffi/vmlib/build.rs b/ffi/vmlib/build.rs deleted file mode 100644 index 6eb41249..00000000 --- a/ffi/vmlib/build.rs +++ /dev/null @@ -1,10 +0,0 @@ -fn main() { - // Platform-specific flags - #[cfg(target_os = "macos")] - { - // Workaround for linker issue - // See https://github.com/athenavm/athena/pull/161 - println!("cargo:rustc-link-arg=-undefined"); - println!("cargo:rustc-link-arg=dynamic_lookup"); - } -} diff --git a/vm/entrypoint/src/syscalls/memory.rs b/vm/entrypoint/src/syscalls/memory.rs index d42b2b93..69b62382 100644 --- a/vm/entrypoint/src/syscalls/memory.rs +++ b/vm/entrypoint/src/syscalls/memory.rs @@ -16,23 +16,18 @@ // Note: We inherit this constraint from SP1, and I don't see a reason to remove it. const MAX_MEMORY: usize = 0x78000000; +// Platform-agnostic heap allocation starting at 1MB mark +static mut HEAP_START: usize = 1024 * 1024; +static mut HEAP_POS: usize = 0; + #[allow(clippy::missing_safety_doc)] #[no_mangle] pub unsafe extern "C" fn sys_alloc_aligned(bytes: usize, align: usize) -> *mut u8 { - extern "C" { - // https://lld.llvm.org/ELF/linker_script.html#sections-command - static _end: u8; - } - - // Pointer to next heap address to use, or 0 if the heap has not yet been - // initialized. - static mut HEAP_POS: usize = 0; - // SAFETY: Single threaded, so nothing else can touch this while we're working. let mut heap_pos = unsafe { HEAP_POS }; if heap_pos == 0 { - heap_pos = unsafe { (&_end) as *const u8 as usize }; + heap_pos = HEAP_START; } let offset = heap_pos & (align - 1);