From ee4ec6c84d1c1bfc66468b306b19fce4ff784364 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Tue, 16 Dec 2025 09:22:52 -0800 Subject: [PATCH] [vm] Maintain W^X when mapping snapshots on Windows. TEST=ci Bug: https://github.com/dart-lang/sdk/issues/62249 Change-Id: I4ee4e7420527907d20217916acbc4162d9a53800 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468441 Reviewed-by: Alexander Aprelev Commit-Queue: Ryan Macnak --- runtime/bin/file_win.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc index fcc90a545d7..009a0a53d11 100644 --- a/runtime/bin/file_win.cc +++ b/runtime/bin/file_win.cc @@ -86,26 +86,23 @@ MappedMemory* File::Map(File::MapType type, int64_t position, int64_t length, void* start) { - DWORD prot_alloc; - DWORD prot_final; + DWORD prot = PAGE_NOACCESS; switch (type) { case File::kReadOnly: - prot_alloc = PAGE_READWRITE; - prot_final = PAGE_READONLY; + prot = PAGE_READONLY; break; case File::kReadExecute: - prot_alloc = PAGE_EXECUTE_READWRITE; - prot_final = PAGE_EXECUTE_READ; + prot = PAGE_EXECUTE_READ; break; case File::kReadWrite: - prot_alloc = PAGE_READWRITE; - prot_final = PAGE_READWRITE; + prot = PAGE_READWRITE; break; } void* addr = start; if (addr == nullptr) { - addr = VirtualAlloc(nullptr, length, MEM_COMMIT | MEM_RESERVE, prot_alloc); + addr = + VirtualAlloc(nullptr, length, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); if (addr == nullptr) { int error = GetLastError(); char buffer[1024]; @@ -136,7 +133,7 @@ MappedMemory* File::Map(File::MapType type, } DWORD old_prot; - bool result = VirtualProtect(addr, length, prot_final, &old_prot); + bool result = VirtualProtect(addr, length, prot, &old_prot); if (!result) { int error = GetLastError(); char buffer[1024];