From 986d5a9958ee767ee3c358fe676dde95dc0a3279 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Mon, 9 Jul 2018 11:12:56 +0100 Subject: [PATCH] ntdll/tests: Skip the map protect tests if we can't disable no-exec. Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/ntdll/tests/info.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c index 4a2d9e69330..7d60b94f15f 100644 --- a/dlls/ntdll/tests/info.c +++ b/dlls/ntdll/tests/info.c @@ -1776,20 +1776,30 @@ static void test_mapprotection(void) NTSTATUS status; SIZE_T retlen, count; void (*f)(void); + BOOL reset_flags = FALSE; - if (!pNtClose) { - skip("No NtClose ... Win98\n"); - return; - } /* Switch to being a noexec unaware process */ status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &oldflags, sizeof (oldflags), &flagsize); - if (status == STATUS_INVALID_PARAMETER) { - skip("Invalid Parameter on ProcessExecuteFlags query?\n"); + if (status == STATUS_INVALID_PARAMETER) + { + skip("Unable to query process execute flags on this platform\n"); return; } - ok( (status == STATUS_SUCCESS) || (status == STATUS_INVALID_INFO_CLASS), "Expected STATUS_SUCCESS, got %08x\n", status); - status = pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &flags, sizeof(flags) ); - ok( (status == STATUS_SUCCESS) || (status == STATUS_INVALID_INFO_CLASS), "Expected STATUS_SUCCESS, got %08x\n", status); + ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status ); + trace("Process execute flags %08x\n", oldflags); + + if (oldflags & MEM_EXECUTE_OPTION_DISABLE) + { + if (oldflags & MEM_EXECUTE_OPTION_PERMANENT) + { + skip("Unable to turn off noexec\n"); + return; + } + + status = pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &flags, sizeof(flags) ); + ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status ); + reset_flags = TRUE; + } size.u.LowPart = 0x2000; size.u.HighPart = 0; @@ -1832,8 +1842,8 @@ static void test_mapprotection(void) ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status); pNtClose (h); - /* Switch back */ - pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &oldflags, sizeof(oldflags) ); + if (reset_flags) + pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &oldflags, sizeof(oldflags) ); } static void test_queryvirtualmemory(void)