ntdll-ATL_Thunk: Add one additional test to confirm that ExceptionInformation[0] is set correctly.

This commit is contained in:
Sebastian Lackner 2014-10-11 19:05:40 +02:00
parent 90c872c5fe
commit 7336108ab8
7 changed files with 56 additions and 37 deletions

View File

@ -1,16 +1,16 @@
From 58524cf1b19cd820ee51e38e5ca6c002142f2047 Mon Sep 17 00:00:00 2001
From 74b84ed98a660e029a60ef7c6e20efa6a71c2361 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 8 Oct 2014 20:54:50 +0200
Subject: kernel32/tests: Add tests for DEP combined with guard pages and write
watches.
---
dlls/kernel32/tests/virtual.c | 438 ++++++++++++++++++++++++++++++++++++++++++
dlls/kernel32/tests/virtual.c | 449 ++++++++++++++++++++++++++++++++++++++++++
include/winternl.h | 1 +
2 files changed, 439 insertions(+)
2 files changed, 450 insertions(+)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index 0fa2b99..47feff1 100644
index 0fa2b99..501934d 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -28,6 +28,7 @@
@ -21,7 +21,7 @@ index 0fa2b99..47feff1 100644
#include "excpt.h"
#include "wine/test.h"
@@ -1797,6 +1798,438 @@ static void test_guard_page(void)
@@ -1797,6 +1798,449 @@ static void test_guard_page(void)
VirtualFree( base, 0, MEM_FREE );
}
@ -30,22 +30,33 @@ index 0fa2b99..47feff1 100644
+static DWORD execute_fault_seh_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
+ CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
+{
+ trace( "exception: %08x flags:%x addr:%p\n",
+ rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
+ ULONG flags = MEM_EXECUTE_OPTION_ENABLE;
+
+ trace( "exception: %08x flags:%x addr:%p info[0]:%ld info[1]:%p\n",
+ rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
+ rec->ExceptionInformation[0], (void *)rec->ExceptionInformation[1] );
+
+ ok( rec->NumberParameters == 2, "NumberParameters is %d instead of 2\n", rec->NumberParameters );
+ ok( rec->ExceptionCode == STATUS_ACCESS_VIOLATION || rec->ExceptionCode == STATUS_GUARD_PAGE_VIOLATION,
+ "ExceptionCode is %08x instead of STATUS_ACCESS_VIOLATION or STATUS_GUARD_PAGE_VIOLATION\n", rec->ExceptionCode );
+
+ NtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &flags, sizeof(flags), NULL );
+
+ if (rec->ExceptionCode == STATUS_GUARD_PAGE_VIOLATION)
+ {
+
+ todo_wine
+ ok( rec->ExceptionInformation[0] == EXCEPTION_EXECUTE_FAULT ||
+ broken(!(flags & MEM_EXECUTE_OPTION_DISABLE) && rec->ExceptionInformation[0] == EXCEPTION_READ_FAULT), /* Windows 2000 */
+ "ExceptionInformation[0] is %d instead of %d\n", (DWORD)rec->ExceptionInformation[0], EXCEPTION_EXECUTE_FAULT );
+
+ num_guard_page_calls++;
+ }
+ else if (rec->ExceptionCode == STATUS_ACCESS_VIOLATION)
+ {
+ DWORD err, old_prot;
+ BOOL success;
+ ULONG flags;
+
+ NtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &flags, sizeof(flags), NULL );
+ err = (flags & MEM_EXECUTE_OPTION_DISABLE) ? EXCEPTION_EXECUTE_FAULT : EXCEPTION_READ_FAULT;
+ ok( rec->ExceptionInformation[0] == err, "ExceptionInformation[0] is %d instead of %d\n",
+ (DWORD)rec->ExceptionInformation[0], err );
@ -460,7 +471,7 @@ index 0fa2b99..47feff1 100644
#endif /* __i386__ */
static void test_VirtualProtect(void)
@@ -2859,5 +3292,10 @@ START_TEST(virtual)
@@ -2859,5 +3303,10 @@ START_TEST(virtual)
test_write_watch();
#ifdef __i386__
test_guard_page();

View File

@ -1,4 +1,4 @@
From 0c2c4a58bd184a58e05ce2eb361c1dc565569a2c Mon Sep 17 00:00:00 2001
From f04b80a0472feb427cecabf6e05fb23515272a63 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 8 Oct 2014 21:11:55 +0200
Subject: ntdll: Avoid recursive exception handler calls when handling guard
@ -11,15 +11,23 @@ check is executed, and removes the guard page protection. Afterwards, when the A
check returns, the exception is _not_ catched by virtual_handle_fault, but instead
passed to the application.
---
dlls/kernel32/tests/virtual.c | 1 -
dlls/kernel32/tests/virtual.c | 2 --
dlls/ntdll/signal_i386.c | 10 ++++++----
2 files changed, 6 insertions(+), 5 deletions(-)
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index 47feff1..7905320 100644
index 501934d..4d8277d 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -1960,7 +1960,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -1818,7 +1818,6 @@ static DWORD execute_fault_seh_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTR
if (rec->ExceptionCode == STATUS_GUARD_PAGE_VIOLATION)
{
- todo_wine
ok( rec->ExceptionInformation[0] == EXCEPTION_EXECUTE_FAULT ||
broken(!(flags & MEM_EXECUTE_OPTION_DISABLE) && rec->ExceptionInformation[0] == EXCEPTION_READ_FAULT), /* Windows 2000 */
"ExceptionInformation[0] is %d instead of %d\n", (DWORD)rec->ExceptionInformation[0], EXCEPTION_EXECUTE_FAULT );
@@ -1971,7 +1970,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE)
ok( num_execute_fault_calls == 1, "expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
else

View File

@ -1,4 +1,4 @@
From bf053b74d743f38789ad01a0ad2610925c571e25 Mon Sep 17 00:00:00 2001
From 8f01f73ec7329ccff04899140d8d661d9db60719 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 8 Oct 2014 21:26:28 +0200
Subject: ntdll: Ensure force_exec_prot is also used for views with write watch
@ -10,10 +10,10 @@ Subject: ntdll: Ensure force_exec_prot is also used for views with write watch
2 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index 7905320..a58d085 100644
index 4d8277d..2d2554b 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -2092,7 +2092,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -2102,7 +2102,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE)
ok( num_execute_fault_calls == 1, "expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
else
@ -21,7 +21,7 @@ index 7905320..a58d085 100644
ok( num_execute_fault_calls == 0, "expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
count = 64;
@@ -2103,7 +2102,11 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -2113,7 +2112,11 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
ret = send_message_excpt( hWnd, WM_USER, 0, 0 );
ok( ret == 42, "call returned wrong result, expected 42, got %d\n", ret );
ok( num_guard_page_calls == 0, "expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
@ -34,7 +34,7 @@ index 7905320..a58d085 100644
/* Now a bit more complicated, the page containing the code is protected with
* PAGE_GUARD memory protection. */
@@ -2117,7 +2120,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -2127,7 +2130,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE)
ok( num_execute_fault_calls == 1, "expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
else

View File

@ -1,4 +1,4 @@
From 8385e203f822c454373a1fd21f99bd4a47f9ea0d Mon Sep 17 00:00:00 2001
From 2ef6876f6633398bbb8d59241ea321331a5d45ea Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 8 Oct 2014 21:28:25 +0200
Subject: ntdll: reset_write_watches shouldn't remove enforced exec
@ -10,10 +10,10 @@ Subject: ntdll: reset_write_watches shouldn't remove enforced exec
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index a58d085..8e3f43f 100644
index 2d2554b..4627c5a 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -2102,11 +2102,7 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -2112,11 +2112,7 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
ret = send_message_excpt( hWnd, WM_USER, 0, 0 );
ok( ret == 42, "call returned wrong result, expected 42, got %d\n", ret );
ok( num_guard_page_calls == 0, "expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );

View File

@ -1,4 +1,4 @@
From 1724b495cbaad5a806d74785bb8d8a53c9ff7062 Mon Sep 17 00:00:00 2001
From 36a090784f8fb7b4bb0e79ecfcd0fc5422474f22 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sat, 11 Oct 2014 00:08:41 +0200
Subject: ntdll: Only check for ATL thunk if allowed by execute option flags.
@ -9,10 +9,10 @@ Subject: ntdll: Only check for ATL thunk if allowed by execute option flags.
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index 8e3f43f..def2011 100644
index 4627c5a..434d880 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -1987,7 +1987,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -1997,7 +1997,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
ok( ret == 43, "call returned wrong result, expected 43, got %d\n", ret );
ok( num_guard_page_calls == 0, "expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
if ((dep_flags & MEM_EXECUTE_OPTION_DISABLE) && (dep_flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION))
@ -20,7 +20,7 @@ index 8e3f43f..def2011 100644
ok( num_execute_fault_calls == 1, "expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
else
ok( num_execute_fault_calls == 0, "expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
@@ -2003,7 +2002,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -2013,7 +2012,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
ok( ret == 43, "call returned wrong result, expected 43, got %d\n", ret );
ok( num_guard_page_calls == 1, "expected one STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
if ((dep_flags & MEM_EXECUTE_OPTION_DISABLE) && (dep_flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION))
@ -28,7 +28,7 @@ index 8e3f43f..def2011 100644
ok( num_execute_fault_calls == 1, "expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
else
ok( num_execute_fault_calls == 0, "expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
@@ -2154,7 +2152,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -2164,7 +2162,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
ok( ret == 43, "call returned wrong result, expected 43, got %d\n", ret );
ok( num_guard_page_calls == 0, "expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
if ((dep_flags & MEM_EXECUTE_OPTION_DISABLE) && (dep_flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION))
@ -36,7 +36,7 @@ index 8e3f43f..def2011 100644
ok( num_execute_fault_calls == 1, "expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
else
ok( num_execute_fault_calls == 0, "expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
@@ -2183,7 +2180,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -2193,7 +2190,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
ok( ret == 43, "call returned wrong result, expected 43, got %d\n", ret );
ok( num_guard_page_calls == 1, "expected one STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
if ((dep_flags & MEM_EXECUTE_OPTION_DISABLE) && (dep_flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION))

View File

@ -1,4 +1,4 @@
From 4298254e506fae9d2f3d119286309ac1598a0d4e Mon Sep 17 00:00:00 2001
From 0055b9ee3688aaec1bdfccb89c867c2f62d61146 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sat, 11 Oct 2014 00:35:02 +0200
Subject: kernel32/tests: Add test to show incorrect behaviour in ATL thunk
@ -9,7 +9,7 @@ Subject: kernel32/tests: Add test to show incorrect behaviour in ATL thunk
1 file changed, 65 insertions(+), 6 deletions(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index def2011..1bd04ee 100644
index 434d880..7ecd54d 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -35,7 +35,7 @@
@ -30,7 +30,7 @@ index def2011..1bd04ee 100644
/* ############################### */
@@ -1833,6 +1835,31 @@ static DWORD execute_fault_seh_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTR
@@ -1843,6 +1845,31 @@ static DWORD execute_fault_seh_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTR
return ExceptionContinueExecution;
}
@ -62,7 +62,7 @@ index def2011..1bd04ee 100644
static inline DWORD send_message_excpt( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
EXCEPTION_REGISTRATION_RECORD frame;
@@ -2011,6 +2038,35 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -2021,6 +2048,35 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
ok( num_guard_page_calls == 0, "expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
ok( num_execute_fault_calls == 0, "expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
@ -98,7 +98,7 @@ index def2011..1bd04ee 100644
/* Restore the JMP instruction, set to executable, and then destroy the Window */
memcpy( base, code_jmp, sizeof(code_jmp) );
@@ -3255,15 +3311,18 @@ START_TEST(virtual)
@@ -3265,15 +3321,18 @@ START_TEST(virtual)
}
hkernel32 = GetModuleHandleA("kernel32.dll");

View File

@ -1,4 +1,4 @@
From 1651ad24a94ffa9b75e498822c92ecfedc16d9c7 Mon Sep 17 00:00:00 2001
From 280ec71a219496224a2269c23480e6b1b0af3cb6 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sat, 11 Oct 2014 02:04:27 +0200
Subject: ntdll: Try to not raise exceptions when checking for ATL thunks.
@ -10,10 +10,10 @@ Original patch by Markus Amsler.
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index 1bd04ee..e6b1aee 100644
index 7ecd54d..6d05eef 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -2060,7 +2060,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
@@ -2070,7 +2070,6 @@ static void test_atl_thunk_emulation( ULONG dep_flags )
pRtlRemoveVectoredExceptionHandler(vectored_handler);
ok( ret == 43, "call returned wrong result, expected 43, got %d\n", ret );