From 750187cc72a40ab035547998135d70b64d066cbe Mon Sep 17 00:00:00 2001 From: Marsman1996 Date: Thu, 29 Jan 2026 20:22:04 +0800 Subject: [PATCH] Add test for memory merge after split panic of mprotect --- test/initramfs/src/apps/mmap/mmap_and_mprotect.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/initramfs/src/apps/mmap/mmap_and_mprotect.c b/test/initramfs/src/apps/mmap/mmap_and_mprotect.c index 50021e99c..679095ccf 100644 --- a/test/initramfs/src/apps/mmap/mmap_and_mprotect.c +++ b/test/initramfs/src/apps/mmap/mmap_and_mprotect.c @@ -69,3 +69,17 @@ FN_TEST(mprotect_invalid_permission) TEST_SUCC(munmap(addr, PAGE_SIZE)); } END_TEST() + +FN_TEST(mprotect_merge_after_split_mapping) +{ + void *addr = TEST_SUCC(mmap(NULL, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); + + // Split the mapping into two. + TEST_SUCC(mprotect(addr, PAGE_SIZE, PROT_READ)); + // After the first mapping is protected, the two mappings will merge. + TEST_SUCC(mprotect(addr, 2 * PAGE_SIZE, PROT_READ | PROT_WRITE)); + + TEST_SUCC(munmap(addr, 2 * PAGE_SIZE)); +} +END_TEST() \ No newline at end of file