From 0bc167ea876591056b8158ecee4ab4588b346bf8 Mon Sep 17 00:00:00 2001 From: DH Date: Thu, 16 Oct 2025 12:14:26 +0300 Subject: [PATCH] rx/map: simplify protection conversion for windows --- rx/src/Mappable.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/rx/src/Mappable.cpp b/rx/src/Mappable.cpp index 7b4d74cb2..8bce5954b 100644 --- a/rx/src/Mappable.cpp +++ b/rx/src/Mappable.cpp @@ -122,22 +122,20 @@ std::errc rx::Mappable::map(rx::AddressRange virtualRange, std::size_t offset, rx::EnumBitSet protection, [[maybe_unused]] std::size_t alignment) { #ifdef _WIN32 - DWORD prot = 0; - if (!protection) { - prot = PAGE_NOACCESS; - } else if (protection == Protection::R) { - prot = PAGE_READONLY; - } else if (protection & Protection::X) { - if (protection & Protection::W) { - prot = PAGE_EXECUTE_READWRITE; - } else if (protection & Protection::R) { - prot = PAGE_EXECUTE_READ; - } else { - prot = PAGE_EXECUTE; - } - } else { - prot = PAGE_READWRITE; - } + static const DWORD protTable[] = { + PAGE_NOACCESS, // 0 + PAGE_READONLY, // R + PAGE_EXECUTE_READWRITE, // W + PAGE_EXECUTE_READWRITE, // RW + PAGE_EXECUTE, // X + PAGE_EXECUTE_READWRITE, // XR + PAGE_EXECUTE_READWRITE, // XW + PAGE_EXECUTE_READWRITE, // XRW + }; + + auto prot = + protTable[(protection & (Protection::R | Protection::W | Protection::X)) + .toUnderlying()]; releaseVirtualSpace(virtualRange, alignment);