Skip to content

Commit e37f2b5

Browse files
test: enhance ScopedSetMemoryRWX tests for memory protection states
1 parent 9c24a0b commit e37f2b5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/tests/test_windows.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,31 @@ TEST(BlookMemoryTests, ScopedSetMemoryRWX) {
322322
using namespace blook;
323323
int val = 123;
324324
Pointer p = &val;
325+
326+
auto assert_protect = [](Pointer p, DWORD expected) {
327+
MEMORY_BASIC_INFORMATION mbi;
328+
VirtualQuery(p.data(), &mbi, sizeof(mbi));
329+
EXPECT_EQ(mbi.Protect, expected);
330+
};
331+
assert_protect(p, PAGE_READWRITE);
325332
{
326333
ScopedSetMemoryRWX scoped(p, sizeof(val));
334+
assert_protect(p, PAGE_EXECUTE_READWRITE);
327335
p.write_s32(456);
328336
}
337+
assert_protect(p, PAGE_READWRITE);
338+
339+
auto rx_page = VirtualAlloc(nullptr, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READ);
340+
ASSERT_NE(rx_page, nullptr);
341+
Pointer p_rx = rx_page;
342+
assert_protect(p_rx, PAGE_EXECUTE_READ);
343+
{
344+
ScopedSetMemoryRWX scoped(p_rx, 0x1000);
345+
assert_protect(p_rx, PAGE_EXECUTE_READWRITE);
346+
}
347+
assert_protect(p_rx, PAGE_EXECUTE_READ);
348+
VirtualFree(rx_page, 0, MEM_RELEASE);
349+
329350
EXPECT_EQ(val, 456);
330351
}
331352

0 commit comments

Comments
 (0)