rt test: the import-time test ends its memfd mappings on Linux alone, so rt's device tests build for Windows

ff603a9212 gave import_time's Pages a Drop that calls libc::munmap for every mapping, outside the
Linux gate its mappings sit behind. rt takes libc only on unix targets, so rt's tests under
--cfg m2v_gpu stopped compiling for x86_64-pc-windows-gnullvm (E0433 at import_time.rs:122): the
Windows cross build of rt's device-test archive at development d6a8f8fc49 failed (m3-max-58057), and
with it the UHD 630 leg. The unmap now sits beside map_shared, gated as it is: Linux ends the
mapping, and elsewhere, where the test maps no memfd, it is unreachable.

Verified: see the compile jobs named in the landing.
This commit is contained in:
Anees Iqbal committed 2026-11-20 03:37:04 -08:00
1 parent 9e250379d3
commit b4058db961
1 file changed
+16 -6
@@ -116,16 +116,26 @@ mod on_device {
match self.layout {
// SAFETY: allocated with `layout`, and nothing uses it any more.
Some(layout) => unsafe { std::alloc::dealloc(self.pointer.as_ptr(), layout) },
None => {
// SAFETY: mapped by `map_shared` over `len` bytes, and nothing uses it any
// more.
let unmapped = unsafe { libc::munmap(self.pointer.as_ptr().cast(), self.len) };
assert_eq!(unmapped, 0, "the mappings' end");
}
None => unmap_shared(self.pointer, self.len),
}
}
}
/// The end of `len` bytes of mappings `map_shared` made at `pointer`, which nothing uses any
/// more.
#[cfg(target_os = "linux")]
fn unmap_shared(pointer: NonNull<u8>, len: usize) {
// SAFETY: mapped by `map_shared` over `len` bytes, and nothing uses it any more.
let unmapped = unsafe { libc::munmap(pointer.as_ptr().cast(), len) };
assert_eq!(unmapped, 0, "the mappings' end");
}
/// Off Linux the test maps no memfd, so it ends no mapping.
#[cfg(not(target_os = "linux"))]
fn unmap_shared(_: NonNull<u8>, _: usize) {
unreachable!("a memfd off Linux")
}
/// `len` bytes of shared mappings of a new memfd, by `kind` ([`Kind`]): one mapping of a memfd
/// of `len` bytes; or one mapping a page, the pages of a memfd of twice `len` taken at a stride
/// prime to its page count, so no two neighbouring mappings merge, over a shared mapping of