From 3cd8a6719d3ab940028bb59b440fde6063898fbb Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 10 Dec 2024 22:34:16 -0500 Subject: [PATCH] kernel/vm: Make privately-mapped anonymous regions avoid committing memory too. This was already the case for non-anonymous regions (i.e. mmap'ed files), but wasn't the case for anonymous ones (fd < 0). Now it is. --- src/system/kernel/vm/vm.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 263f2a4641..f067a55b60 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -2271,6 +2271,12 @@ _vm_map_file(team_id team, const char* name, void** _address, uint32 mappingFlags = 0; if (unmapAddressRange) mappingFlags |= CREATE_AREA_UNMAP_ADDRESS_RANGE; + if (mapping == REGION_PRIVATE_MAP) { + // For privately mapped read-only regions, skip committing memory. + // (If protections are changed later on, memory will be committed then.) + if ((protection & (B_WRITE_AREA | B_KERNEL_WRITE_AREA)) == 0) + mappingFlags |= CREATE_AREA_DONT_COMMIT_MEMORY; + } if (fd < 0) { virtual_address_restrictions virtualRestrictions = {}; @@ -2304,11 +2310,6 @@ _vm_map_file(team_id team, const char* name, void** _address, protectionMax = protection | B_USER_PROTECTION; else protectionMax = protection | (B_USER_PROTECTION & ~B_WRITE_AREA); - } else if (mapping == REGION_PRIVATE_MAP) { - // For privately mapped read-only regions, skip committing memory. - // (If protections are changed later on, memory will be committed then.) - if ((protection & B_WRITE_AREA) == 0) - mappingFlags |= CREATE_AREA_DONT_COMMIT_MEMORY; } // get the vnode for the object, this also grabs a ref to it