2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for the NtProtectVirtualMemory API
9 #define WIN32_NO_STATUS
10 #include <ndk/rtlfuncs.h>
11 #include <ndk/mmfuncs.h>
13 START_TEST(NtProtectVirtualMemory
)
15 ULONG
* allocationStart
= NULL
;
17 SIZE_T allocationSize
;
21 allocationSize
= PAGE_SIZE
;
22 status
= NtAllocateVirtualMemory(NtCurrentProcess(),
23 (void**)&allocationStart
,
28 ok(NT_SUCCESS(status
), "Reserving memory failed\n");
30 /* Commit the page (RW) */
31 status
= NtAllocateVirtualMemory(NtCurrentProcess(),
32 (void**)&allocationStart
,
37 ok(NT_SUCCESS(status
), "Commiting memory failed\n");
42 *allocationStart
= 0xFF;
43 } EndSeh(STATUS_SUCCESS
);
48 ok(*allocationStart
== 0xFF, "Memory was not written\n");
49 } EndSeh(STATUS_SUCCESS
);
51 /* Set it as read only */
52 status
= NtProtectVirtualMemory(NtCurrentProcess(),
53 (void**)&allocationStart
,
57 ok(NT_SUCCESS(status
), "NtProtectVirtualMemory failed.\n");
58 ok(oldProtection
== PAGE_READWRITE
, "Expected PAGE_READWRITE, got %08x.\n", oldProtection
);
63 *allocationStart
= 0xAA;
64 } EndSeh(STATUS_ACCESS_VIOLATION
);
69 ok(*allocationStart
== 0xFF, "read-only memory were changed.\n");
70 } EndSeh(STATUS_SUCCESS
);
72 /* Set it as no access */
73 status
= NtProtectVirtualMemory(NtCurrentProcess(),
74 (void**)&allocationStart
,
78 ok(NT_SUCCESS(status
), "NtProtectVirtualMemory failed.\n");
79 ok(oldProtection
== PAGE_READONLY
, "Expected PAGE_READONLY, got %08x.\n", oldProtection
);
84 *allocationStart
= 0xAA;
85 } EndSeh(STATUS_ACCESS_VIOLATION
);
90 ok(*allocationStart
== 0, "Test should not go as far as this.\n");
91 } EndSeh(STATUS_ACCESS_VIOLATION
);
94 status
= NtFreeVirtualMemory(NtCurrentProcess(),
95 (void**)&allocationStart
,
98 ok(NT_SUCCESS(status
), "Failed freeing memory.\n");