mirror of
https://github.com/reactos/reactos.git
synced 2024-11-03 21:34:00 +00:00
3b0611bcc9
* Add tests for NtProtectVirtualMemory svn path=/trunk/; revision=58924
102 lines
No EOL
2.9 KiB
C
102 lines
No EOL
2.9 KiB
C
/*
|
|
* PROJECT: ReactOS API Tests
|
|
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
|
* PURPOSE: Test for the NtProtectVirtualMemory API
|
|
*/
|
|
|
|
#define WIN32_NO_STATUS
|
|
#include <wine/test.h>
|
|
#include <ndk/rtlfuncs.h>
|
|
#include <ndk/mmfuncs.h>
|
|
#include <pseh/pseh2.h>
|
|
|
|
#define StartSeh status = STATUS_SUCCESS; _SEH2_TRY
|
|
#define EndSeh(ExpectedStatus) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { status = _SEH2_GetExceptionCode(); } _SEH2_END; ok(status == ExpectedStatus, "Exception %lx, expected %lx\n", status, ExpectedStatus)
|
|
|
|
START_TEST(NtProtectVirtualMemory)
|
|
{
|
|
ULONG* allocationStart = NULL;
|
|
NTSTATUS status;
|
|
SIZE_T allocationSize;
|
|
ULONG oldProtection;
|
|
|
|
/* Reserve a page */
|
|
allocationSize = PAGE_SIZE;
|
|
status = NtAllocateVirtualMemory(NtCurrentProcess(),
|
|
(void**)&allocationStart,
|
|
0,
|
|
&allocationSize,
|
|
MEM_RESERVE,
|
|
PAGE_NOACCESS);
|
|
ok(NT_SUCCESS(status), "Reserving memory failed\n");
|
|
|
|
/* Commit the page (RW) */
|
|
status = NtAllocateVirtualMemory(NtCurrentProcess(),
|
|
(void**)&allocationStart,
|
|
0,
|
|
&allocationSize,
|
|
MEM_COMMIT,
|
|
PAGE_READWRITE);
|
|
ok(NT_SUCCESS(status), "Commiting memory failed\n");
|
|
|
|
/* Try writing it */
|
|
StartSeh
|
|
{
|
|
*allocationStart = 0xFF;
|
|
} EndSeh(STATUS_SUCCESS);
|
|
|
|
/* Try reading it */
|
|
StartSeh
|
|
{
|
|
ok(*allocationStart == 0xFF, "Memory was not written\n");
|
|
} EndSeh(STATUS_SUCCESS);
|
|
|
|
/* Set it as read only */
|
|
status = NtProtectVirtualMemory(NtCurrentProcess(),
|
|
(void**)&allocationStart,
|
|
&allocationSize,
|
|
PAGE_READONLY,
|
|
&oldProtection);
|
|
ok(NT_SUCCESS(status), "NtProtectVirtualMemory failed.\n");
|
|
ok(oldProtection == PAGE_READWRITE, "Expected PAGE_READWRITE, got %08x.\n", oldProtection);
|
|
|
|
/* Try writing it */
|
|
StartSeh
|
|
{
|
|
*allocationStart = 0xAA;
|
|
} EndSeh(STATUS_ACCESS_VIOLATION);
|
|
|
|
/* Try reading it */
|
|
StartSeh
|
|
{
|
|
ok(*allocationStart == 0xFF, "read-only memory were changed.\n");
|
|
} EndSeh(STATUS_SUCCESS);
|
|
|
|
/* Set it as no access */
|
|
status = NtProtectVirtualMemory(NtCurrentProcess(),
|
|
(void**)&allocationStart,
|
|
&allocationSize,
|
|
PAGE_NOACCESS,
|
|
&oldProtection);
|
|
ok(NT_SUCCESS(status), "NtProtectVirtualMemory failed.\n");
|
|
ok(oldProtection == PAGE_READONLY, "Expected PAGE_READONLY, got %08x.\n", oldProtection);
|
|
|
|
/* Try writing it */
|
|
StartSeh
|
|
{
|
|
*allocationStart = 0xAA;
|
|
} EndSeh(STATUS_ACCESS_VIOLATION);
|
|
|
|
/* Try reading it */
|
|
StartSeh
|
|
{
|
|
ok(*allocationStart == 0, "Test should not go as far as this.\n");
|
|
} EndSeh(STATUS_ACCESS_VIOLATION);
|
|
|
|
/* Free memory */
|
|
status = NtFreeVirtualMemory(NtCurrentProcess(),
|
|
(void**)&allocationStart,
|
|
&allocationSize,
|
|
MEM_RELEASE);
|
|
ok(NT_SUCCESS(status), "Failed freeing memory.\n");
|
|
} |