From 81b9ca5dbd08dad57cc009935be0d7a9a339d69c Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 25 Nov 2008 12:02:16 +0100 Subject: [PATCH] ntdll: Pass the error code to VIRTUAL_HandleFault, and allow it to ignore the exception. Also rename it to virtual_handle_fault for consistency. --- dlls/ntdll/ntdll_misc.h | 2 +- dlls/ntdll/signal_i386.c | 4 +++- dlls/ntdll/signal_powerpc.c | 7 ++----- dlls/ntdll/signal_sparc.c | 5 +++-- dlls/ntdll/signal_x86_64.c | 3 +++ dlls/ntdll/virtual.c | 4 ++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index a42fd116bbc..f3a60f6299c 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -141,7 +141,7 @@ extern SIZE_T virtual_free_system_view( PVOID *addr_ptr ); extern NTSTATUS virtual_alloc_thread_stack( void *base, SIZE_T stack_size ); extern void virtual_clear_thread_stack(void); extern BOOL virtual_handle_stack_fault( void *addr ); -extern NTSTATUS VIRTUAL_HandleFault(LPCVOID addr); +extern NTSTATUS virtual_handle_fault( LPCVOID addr, DWORD err ); extern void VIRTUAL_SetForceExec( BOOL enable ); extern void VIRTUAL_UseLargeAddressSpace(void); extern struct _KUSER_SHARED_DATA *user_shared_data; diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index a9482e97b68..6a3a8477703 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -1209,7 +1209,9 @@ static void WINAPI raise_segv_exception( EXCEPTION_RECORD *rec, CONTEXT *context { if (rec->ExceptionInformation[0] == EXCEPTION_EXECUTE_FAULT && check_atl_thunk( rec, context )) goto done; - rec->ExceptionCode = VIRTUAL_HandleFault( (void *)rec->ExceptionInformation[1] ); + if (!(rec->ExceptionCode = virtual_handle_fault( (void *)rec->ExceptionInformation[1], + rec->ExceptionInformation[0] ))) + goto done; } break; case EXCEPTION_DATATYPE_MISALIGNMENT: diff --git a/dlls/ntdll/signal_powerpc.c b/dlls/ntdll/signal_powerpc.c index e65591b8d63..ecb74e1d4d3 100644 --- a/dlls/ntdll/signal_powerpc.c +++ b/dlls/ntdll/signal_powerpc.c @@ -321,7 +321,6 @@ static inline DWORD get_fpu_code( const CONTEXT *context ) static void do_segv( CONTEXT *context, int trap, int err, int code, void * addr ) { EXCEPTION_RECORD rec; - DWORD page_fault_code = EXCEPTION_ACCESS_VIOLATION; rec.ExceptionRecord = NULL; rec.ExceptionFlags = EXCEPTION_CONTINUABLE; @@ -336,9 +335,8 @@ static void do_segv( CONTEXT *context, int trap, int err, int code, void * addr rec.NumberParameters = 2; rec.ExceptionInformation[0] = 0; /* FIXME ? */ rec.ExceptionInformation[1] = (ULONG_PTR)addr; - if (!(page_fault_code=VIRTUAL_HandleFault(addr))) + if (!(rec.ExceptionCode = virtual_handle_fault(addr, rec.ExceptionInformation[0]))) return; - rec.ExceptionCode = page_fault_code; break; default:FIXME("Unhandled SIGSEGV/%x\n",code); break; @@ -358,9 +356,8 @@ static void do_segv( CONTEXT *context, int trap, int err, int code, void * addr rec.NumberParameters = 2; rec.ExceptionInformation[0] = 0; /* FIXME ? */ rec.ExceptionInformation[1] = (ULONG_PTR)addr; - if (!(page_fault_code=VIRTUAL_HandleFault(addr))) + if (!(rec.ExceptionCode = virtual_handle_fault(addr, rec.ExceptionInformation[0]))) return; - rec.ExceptionCode = page_fault_code; break; #endif default:FIXME("Unhandled SIGBUS/%x\n",code); diff --git a/dlls/ntdll/signal_sparc.c b/dlls/ntdll/signal_sparc.c index d3896f36f47..657d167790c 100644 --- a/dlls/ntdll/signal_sparc.c +++ b/dlls/ntdll/signal_sparc.c @@ -180,12 +180,13 @@ static void segv_handler( int signal, siginfo_t *info, ucontext_t *ucontext ) EXCEPTION_RECORD rec; CONTEXT context; + rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION; + /* we want the page-fault case to be fast */ if ( info->si_code == SEGV_ACCERR ) - if (VIRTUAL_HandleFault( (LPVOID)info->si_addr )) return; + if (!(rec.ExceptionCode = virtual_handle_fault( info->si_addr, 0 ))) return; save_context( &context, ucontext ); - rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION; rec.ExceptionRecord = NULL; rec.ExceptionFlags = EXCEPTION_CONTINUABLE; rec.ExceptionAddress = (LPVOID)context.pc; diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c index a7a0d3b441b..47b2ff7f73b 100644 --- a/dlls/ntdll/signal_x86_64.c +++ b/dlls/ntdll/signal_x86_64.c @@ -263,6 +263,8 @@ static HANDLER_DEF(segv_handler) rec.NumberParameters = 2; rec.ExceptionInformation[0] = (ERROR_sig(HANDLER_CONTEXT) & 2) != 0; rec.ExceptionInformation[1] = (ULONG_PTR)FAULT_ADDRESS; + if (!(rec.ExceptionCode = virtual_handle_fault( FAULT_ADDRESS, rec.ExceptionInformation[0] ))) + goto done; #endif break; case TRAP_x86_ALIGNFLT: /* Alignment check exception */ @@ -282,6 +284,7 @@ static HANDLER_DEF(segv_handler) } __regs_RtlRaiseException( &rec, &context ); +done: restore_context( &context, HANDLER_CONTEXT ); } diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c index 34c6369cb51..3efd43d7dd2 100644 --- a/dlls/ntdll/virtual.c +++ b/dlls/ntdll/virtual.c @@ -1399,9 +1399,9 @@ void virtual_clear_thread_stack(void) /*********************************************************************** - * VIRTUAL_HandleFault + * virtual_handle_fault */ -NTSTATUS VIRTUAL_HandleFault( LPCVOID addr ) +NTSTATUS virtual_handle_fault( LPCVOID addr, DWORD err ) { FILE_VIEW *view; NTSTATUS ret = STATUS_ACCESS_VIOLATION; -- 2.11.4.GIT