From b4f6a29a959c3fc2b74ff71e3357cb7eb6f71b2f Mon Sep 17 00:00:00 2001 From: Weiteng Chen Date: Thu, 10 Sep 2026 18:07:55 -0700 Subject: [PATCH 1/3] Use the default allocator on Windows userland Remove the platform's global SafeZoneAllocator declaration so Rust heap allocations use the default allocator. Leave guest page management and the MemoryProvider implementation unchanged. Avoid the slab spinlock involved in the observed ExitProcess TLS-cleanup deadlock. The rebuilt run_multithreaded_pe test and 50 sequential no-retry stress repetitions passed. Detached-worker shutdown remains a separate lifecycle concern. --- litebox_platform_windows_userland/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) 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( From 2b05396b95451ab54919b4be63fc62eb958f950b Mon Sep 17 00:00:00 2001 From: Weiteng Chen Date: Thu, 10 Sep 2026 18:14:32 -0700 Subject: [PATCH 2/3] update ratchet --- dev_tests/src/ratchet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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), From 7fff3b4f2231628ead7a78d7b8371836a1d670f5 Mon Sep 17 00:00:00 2001 From: Weiteng Chen Date: Thu, 10 Sep 2026 23:09:43 -0700 Subject: [PATCH 3/3] Fix allocator collision test with aligned platform pages --- litebox_shim_linux/src/syscalls/mm.rs | 72 +++++++++++++++++---------- 1 file changed, 45 insertions(+), 27 deletions(-) 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]