diff --git a/dev_tests/src/ratchet.rs b/dev_tests/src/ratchet.rs index acdd9cea2..ff8614bf8 100644 --- a/dev_tests/src/ratchet.rs +++ b/dev_tests/src/ratchet.rs @@ -38,7 +38,7 @@ fn ratchet_globals() -> Result<()> { ("litebox_platform_linux_kernel/", 6), ("litebox_platform_linux_userland/", 5), ("litebox_platform_lvbs/", 22), - ("litebox_platform_windows_userland/", 8), + ("litebox_platform_windows_userland/", 7), ("litebox_runner_lvbs/", 8), ("litebox_runner_snp/", 2), ("litebox_shim_linux/", 1), diff --git a/litebox_platform_windows_userland/src/lib.rs b/litebox_platform_windows_userland/src/lib.rs index 400290cda..2d1e9142d 100644 --- a/litebox_platform_windows_userland/src/lib.rs +++ b/litebox_platform_windows_userland/src/lib.rs @@ -1932,10 +1932,6 @@ impl litebox::platform::StdioProvider for WindowsUserland { } } -#[global_allocator] -static SLAB_ALLOC: litebox::mm::allocator::SafeZoneAllocator<'static, 28, WindowsUserland> = - litebox::mm::allocator::SafeZoneAllocator::new(); - impl litebox::mm::allocator::MemoryProvider for WindowsUserland { fn alloc(layout: &std::alloc::Layout) -> Option<(usize, usize)> { let size = core::cmp::max( diff --git a/litebox_shim_linux/src/syscalls/mm.rs b/litebox_shim_linux/src/syscalls/mm.rs index 7f2696c76..1877a75f0 100644 --- a/litebox_shim_linux/src/syscalls/mm.rs +++ b/litebox_shim_linux/src/syscalls/mm.rs @@ -1324,36 +1324,40 @@ mod tests { let task = init_platform(None); let platform = task.global.platform; let mut data = alloc::vec::Vec::new(); - // Find an address that is allocated to the global allocator but not in reserved regions. - // LiteBox's page manager is not aware of the global allocator's allocations. + let mut count = 0; + // Model an external allocator allocation that LiteBox's page manager does not track. let addr = loop { - #[allow( - unused_variables, - reason = "the following features are mutually exclusive" - )] - #[cfg(target_os = "windows")] - let addr = { - let buf = alloc::vec::Vec::::with_capacity(0x10_0000); - let addr = buf.as_ptr() as usize; - data.push(buf); - addr - }; - #[cfg(target_os = "linux")] + assert!( + count < 100, + "Failed to find a suitable address after 100 attempts" + ); + count += 1; let addr = { - let addr = unsafe { - libc::mmap( - core::ptr::null_mut(), - 0x10_000, - libc::PROT_READ | libc::PROT_WRITE, - libc::MAP_PRIVATE | libc::MAP_ANONYMOUS, - -1, - 0, + use litebox::platform::{ + RawConstPointer as _, + page_mgmt::{FixedAddressBehavior, MemoryRegionPermissions}, + }; + + let allocation = >::allocate_pages( + platform, + 0..0x2000, + MemoryRegionPermissions::READ | MemoryRegionPermissions::WRITE, + false, + false, + FixedAddressBehavior::Hint, + ) + .unwrap() + .as_usize(); + // SAFETY: The first page belongs to this test and has no outstanding references. + unsafe { + >::deallocate_pages( + platform, + allocation..allocation + 0x1000, ) - } as usize; - data.push(alloc::vec::Vec::::from(unsafe { - core::slice::from_raw_parts(addr as *const u8, 0x10_000) - })); - addr + .unwrap(); + } + data.push(allocation); + allocation + 0x1000 }; let mut included = false; @@ -1411,6 +1415,20 @@ mod tests { ) .unwrap_err(); assert_eq!(err, Errno::ENOMEM); + + task.sys_munmap(res, 0x1000).unwrap(); + task.sys_munmap(UserPtrMut::from_usize(addr - 0x1000), 0x1000) + .unwrap(); + for allocation in data { + // SAFETY: The remaining page belongs to this test and was never mapped by the shim. + unsafe { + >::deallocate_pages( + platform, + allocation + 0x1000..allocation + 0x2000, + ) + .unwrap(); + } + } } #[test]