From 609c5e6e3d2d2fea12f16438fab8baaa9927074e Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 1 Oct 2023 16:18:25 +0200 Subject: [PATCH] fix malloc mmap --- libuwuc/src/alloc.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libuwuc/src/alloc.rs b/libuwuc/src/alloc.rs index d84349c..2ad53f8 100644 --- a/libuwuc/src/alloc.rs +++ b/libuwuc/src/alloc.rs @@ -21,18 +21,22 @@ fn init() { match state { Ok(_) => unsafe { const HEAP_SIZE: usize = 0x100000; + let map_private = 0x0002; let map_anon = 0x20; let prot_read = 1; let prod_write = 2; - let start = mmap( + let start = mmap_sys( core::ptr::null(), HEAP_SIZE, prot_read | prod_write, - map_anon, + map_anon | map_private, 0, 0, ); + if (start as isize) < 0 { + todo!("mmap failed"); + } ALLOCATOR.lock().init(start, HEAP_SIZE); INIT_STATE.store(INIT, Ordering::Release); @@ -80,7 +84,8 @@ pub unsafe fn free(ptr: *mut u8) { ALLOCATOR.dealloc(start, layout); } -pub unsafe fn mmap( +#[cfg_attr(miri, allow(unused_variables, unreachable_code))] +pub unsafe fn mmap_sys( addr: *const u8, size: usize, prot: c_int, @@ -107,7 +112,11 @@ pub unsafe fn mmap( #[cfg(test)] mod tests { #[test] - #[ignore = "uh"] + fn init() { + super::init(); + } + + #[test] fn malloc_free() { unsafe { let x = super::malloc_zeroed(10, 8);