From bccdc08487e888811dcd9cfb30a07ad047e173df Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 30 Jul 2021 13:14:51 +0200 Subject: [PATCH] Kernel: Unmapping a non-mapped region with munmap() should be a no-op Not a regression per se from 0fcb9efd86da4c15a1aee87503348c5bee875c51 since we were crashing before that which is obviously worse. --- Kernel/VM/Space.cpp | 2 +- Tests/Kernel/TestMunMap.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Kernel/VM/Space.cpp b/Kernel/VM/Space.cpp index cf165ea348..fb89991906 100644 --- a/Kernel/VM/Space.cpp +++ b/Kernel/VM/Space.cpp @@ -92,7 +92,7 @@ KResult Space::unmap_mmap_range(VirtualAddress addr, size_t size) // Try again while checking multiple regions at a time. auto const& regions = find_regions_intersecting(range_to_unmap); if (regions.is_empty()) - return EINVAL; + return KSuccess; // Check if any of the regions is not mmap'ed, to not accidentally // error out with just half a region map left. diff --git a/Tests/Kernel/TestMunMap.cpp b/Tests/Kernel/TestMunMap.cpp index 206c7c3556..6d8af21d79 100644 --- a/Tests/Kernel/TestMunMap.cpp +++ b/Tests/Kernel/TestMunMap.cpp @@ -10,8 +10,7 @@ TEST_CASE(munmap_zero_page) { - // munmap of the unmapped zero page should always fail. + // munmap of the unmapped zero page should always "succeed". auto res = munmap(0x0, 0xF); - EXPECT_EQ(res, -1); - EXPECT_EQ(errno, EINVAL); + EXPECT_EQ(res, 0); }