Hi, This is a small patch I wrote to fix the exception tests on Mac OS X. Right now, if you look at the Mac results I submitted, you'll notice that there are two failures.
The first failure happens because Mach doesn't allow the 'global' flag to be set when setting the debug registers. Changing the test not to set the global flag causes the test to pass. I get the feeling, though, that there is a good reason the global flag was set, so I'm reluctant to send that change in. The other failure happens because 32-bit Mac OS only protects stacks from execution. If you clear PROT_EXEC on any other data, you can still execute code from it. (64-bit Mac OS, on the other hand, always respects the PROT_EXEC flag.) I changed ntdll on 32-bit Mac OS to report DEP as permanently disabled, but I wonder if this was the right change to make. I just want to know: am I doing the right thing here? If not, what should I do instead to fix the tests? Chip
>From 2dd72c20e9ff916d0e37c69622527aa9335e7c77 Mon Sep 17 00:00:00 2001 From: Charles Davis <cda...@mymail.mines.edu> Date: Tue, 16 Nov 2010 17:40:14 -0700 Subject: [PATCH] ntdll: Fix exception tests on Mac OS. Reply-To: wine-devel <wine-devel@winehq.org> --- dlls/ntdll/process.c | 10 ++++++++++ dlls/ntdll/tests/exception.c | 2 +- 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c index b9b81ca..d127e42 100644 --- a/dlls/ntdll/process.c +++ b/dlls/ntdll/process.c @@ -37,7 +37,17 @@ WINE_DEFAULT_DEBUG_CHANNEL(ntdll); +#if defined(__APPLE__) && defined(__i386__) +/* On 32-bit Mac OS when the processor supports no-execute protection, + * only stacks are protected for some reason. All other data is not + * protected. Even if you clear PROT_EXEC with mprotect, the kernel + * will let you execute any code/data in that memory. So, it's point- + * less to enable DEP here. + */ +static ULONG execute_flags = MEM_EXECUTE_OPTION_ENABLE | MEM_EXECUTE_OPTION_PERMANENT; +#else static ULONG execute_flags = MEM_EXECUTE_OPTION_DISABLE; +#endif /* * Process object diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c index 386c5a6..326cb77 100644 --- a/dlls/ntdll/tests/exception.c +++ b/dlls/ntdll/tests/exception.c @@ -678,7 +678,7 @@ static void test_exceptions(void) /* test single stepping over hardware breakpoint */ memset(&ctx, 0, sizeof(ctx)); ctx.Dr0 = (DWORD) code_mem; /* set hw bp on first nop */ - ctx.Dr7 = 3; + ctx.Dr7 = 1; ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS; res = pNtSetContextThread( GetCurrentThread(), &ctx); ok( res == STATUS_SUCCESS, "NtSetContextThread faild with %x\n", res); -- 1.7.4.rc3