From 53a31b512ebe01e25aba09fc7f2812872e3340f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Franch?= Date: Thu, 8 Oct 2026 08:24:12 +0200 Subject: [PATCH] test(guest_memory): pin mprotect on an unmapped and a wrapping range Both return -1/EINVAL: FreeBSD kern_mprotect (sys/vm/vm_mmap.c) maps only PROTECTION_FAILURE, RESOURCE_SHORTAGE and OUT_OF_BOUNDS to their own errno, so KERN_INVALID_ADDRESS falls to EINVAL. Co-Authored-By: Claude --- core/libs/tests/GuestMemory.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/libs/tests/GuestMemory.cpp b/core/libs/tests/GuestMemory.cpp index e400e7e0a..bde88f82e 100644 --- a/core/libs/tests/GuestMemory.cpp +++ b/core/libs/tests/GuestMemory.cpp @@ -1123,6 +1123,11 @@ int main() { Require(memory[page * 2] == 73); Require(munmap_nid_postfix(memory + page * 2, page) == 0); Require(munmap_nid_postfix(memory, page) == -1); + *__error_nid_postfix() = 0; + Require(mprotect_nid_postfix(memory, page, 1) == -1 && *__error_nid_postfix() == 22); + *__error_nid_postfix() = 0; + Require(mprotect_nid_postfix(memory, std::numeric_limits::max(), 1) == -1 && + *__error_nid_postfix() == 22); for (int protection : {0, 1, 3, 5}) { void* mapped = mmap_nid_postfix(memory, 1, protection, 0x1002, -1, 0); Require(mapped != failed);