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

memory experiments #1296

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion zkvm/entrypoint/src/heap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::alloc::{GlobalAlloc, Layout};

use crate::syscalls::sys_alloc_aligned;
use crate::syscalls::{sys_alloc_aligned, HEAP_POS};

/// A simple heap allocator.
///
Expand All @@ -14,3 +14,13 @@ unsafe impl GlobalAlloc for SimpleAlloc {

unsafe fn dealloc(&self, _: *mut u8, _: Layout) {}
}

impl SimpleAlloc {
pub fn get_heap_pointer() -> *mut u8 {
unsafe { HEAP_POS as *mut u8 }
}

pub fn set_heap_pointer(ptr: *mut u8) {
unsafe { HEAP_POS = ptr as usize };
}
}
8 changes: 4 additions & 4 deletions zkvm/entrypoint/src/syscalls/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
// Memory addresses must be lower than BabyBear prime.
const MAX_MEMORY: usize = 0x78000000;

// Pointer to next heap address to use, or 0 if the heap has not yet been
// initialized.
pub 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 {
Expand All @@ -23,10 +27,6 @@ pub unsafe extern "C" fn sys_alloc_aligned(bytes: usize, align: usize) -> *mut u
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 };

Expand Down
Loading