Commit 78c2b7df authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Use a .seh handler for KiUserCallbackDispatcher exceptions.

parent 47aebf67
......@@ -185,6 +185,26 @@ LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
}
#if defined(__WINE_PE_BUILD) && !defined(__i386__)
/*******************************************************************
* user_callback_handler
*
* Exception handler for KiUserCallbackDispatcher.
*/
EXCEPTION_DISPOSITION WINAPI user_callback_handler( EXCEPTION_RECORD *record, void *frame,
CONTEXT *context, void *dispatch )
{
if (!(record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
{
ERR( "ignoring exception %lx\n", record->ExceptionCode );
RtlUnwind( frame, KiUserCallbackDispatcherReturn, record, ULongToPtr(record->ExceptionCode) );
}
return ExceptionContinueSearch;
}
#else
/*******************************************************************
* dispatch_user_callback
*
......@@ -208,6 +228,7 @@ NTSTATUS WINAPI dispatch_user_callback( void *args, ULONG len, ULONG id )
return status;
}
#endif
/*******************************************************************
* raise_status
......
......@@ -50,6 +50,8 @@ extern UINT_PTR page_size;
/* exceptions */
extern LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context );
extern NTSTATUS WINAPI dispatch_user_callback( void *args, ULONG len, ULONG id );
extern EXCEPTION_DISPOSITION WINAPI user_callback_handler( EXCEPTION_RECORD *record, void *frame,
CONTEXT *context, void *dispatch );
extern void DECLSPEC_NORETURN raise_status( NTSTATUS status, EXCEPTION_RECORD *rec );
extern LONG WINAPI call_unhandled_exception_filter( PEXCEPTION_POINTERS eptr );
......
......@@ -585,10 +585,19 @@ __ASM_GLOBAL_FUNC( KiUserCallbackDispatcher,
__ASM_EHABI(".save {sp, pc}\n\t")
__ASM_EHABI(".save {lr}\n\t")
__ASM_EHABI(".pad #0x0c\n\t")
"ldr r0, [sp]\n\t" /* args */
"ldr r1, [sp, #0x04]\n\t" /* len */
"ldr r2, [sp, #0x08]\n\t" /* id */
"ldr r0, [sp]\n\t" /* args */
"ldr r1, [sp, #0x04]\n\t" /* len */
"ldr r2, [sp, #0x08]\n\t" /* id */
#ifdef __WINE_PE_BUILD
"mrc p15, 0, r3, c13, c0, 2\n\t" /* NtCurrentTeb() */
"ldr r3, [r3, 0x30]\n\t" /* peb */
"ldr r3, [r3, 0x2c]\n\t" /* peb->KernelCallbackTable */
"ldr ip, [r3, r2, lsl #3]\n\t"
"blx ip\n\t"
".seh_handler " __ASM_NAME("user_callback_handler") ", %except\n\t"
#else
"bl " __ASM_NAME("dispatch_user_callback") "\n\t"
#endif
".globl " __ASM_NAME("KiUserCallbackDispatcherReturn") "\n"
__ASM_NAME("KiUserCallbackDispatcherReturn") ":\n\t"
"mov r2, r0\n\t" /* status */
......
......@@ -606,15 +606,19 @@ __ASM_GLOBAL_FUNC( KiUserApcDispatcher,
* KiUserCallbackDispatcher (NTDLL.@)
*/
__ASM_GLOBAL_FUNC( KiUserCallbackDispatcher,
__ASM_SEH(".seh_pushframe\n\t")
".seh_pushframe\n\t"
"nop\n\t"
__ASM_SEH(".seh_stackalloc 0x20\n\t")
".seh_stackalloc 0x20\n\t"
"nop\n\t"
__ASM_SEH(".seh_save_reg lr, 0x18\n\t")
__ASM_SEH(".seh_endprologue\n\t")
".seh_save_reg lr, 0x18\n\t"
".seh_endprologue\n\t"
".seh_handler " __ASM_NAME("user_callback_handler") ", @except\n\t"
"ldr x0, [sp]\n\t" /* args */
"ldp w1, w2, [sp, #0x08]\n\t" /* len, id */
"bl " __ASM_NAME("dispatch_user_callback") "\n\t"
"ldr x3, [x18, 0x60]\n\t" /* peb */
"ldr x3, [x3, 0x58]\n\t" /* peb->KernelCallbackTable */
"ldr x15, [x3, x2, lsl #3]\n\t"
"blr x15\n\t"
".globl " __ASM_NAME("KiUserCallbackDispatcherReturn") "\n"
__ASM_NAME("KiUserCallbackDispatcherReturn") ":\n\t"
"mov x2, x0\n\t" /* status */
......
......@@ -1717,15 +1717,19 @@ __ASM_GLOBAL_FUNC( "#KiUserApcDispatcher",
* KiUserCallbackDispatcher (NTDLL.@)
*/
__ASM_GLOBAL_FUNC( "#KiUserCallbackDispatcher",
__ASM_SEH(".seh_pushframe\n\t")
".seh_pushframe\n\t"
"nop\n\t"
__ASM_SEH(".seh_stackalloc 0x20\n\t")
".seh_stackalloc 0x20\n\t"
"nop\n\t"
__ASM_SEH(".seh_save_reg lr, 0x18\n\t")
__ASM_SEH(".seh_endprologue\n\t")
".seh_save_reg lr, 0x18\n\t"
".seh_endprologue\n\t"
".seh_handler " __ASM_NAME("user_callback_handler") ", @except\n\t"
"ldr x0, [sp]\n\t" /* args */
"ldp w1, w2, [sp, #0x08]\n\t" /* len, id */
"bl " __ASM_NAME("dispatch_user_callback") "\n\t"
"ldr x3, [x18, 0x60]\n\t" /* peb */
"ldr x3, [x3, 0x58]\n\t" /* peb->KernelCallbackTable */
"ldr x15, [x3, x2, lsl #3]\n\t"
"blr x15\n\t"
".globl \"#KiUserCallbackDispatcherReturn\"\n"
"\"#KiUserCallbackDispatcherReturn\":\n\t"
"mov x2, x0\n\t" /* status */
......
......@@ -702,7 +702,17 @@ __ASM_GLOBAL_FUNC( KiUserCallbackDispatcher,
"movq 0x20(%rsp),%rcx\n\t" /* args */
"movl 0x28(%rsp),%edx\n\t" /* len */
"movl 0x2c(%rsp),%r8d\n\t" /* id */
#ifdef __WINE_PE_BUILD
"movq %gs:0x30,%rax\n\t" /* NtCurrentTeb() */
"movq 0x60(%rax),%rax\n\t" /* peb */
"movq 0x58(%rax),%rax\n\t" /* peb->KernelCallbackTable */
"call *(%rax,%r8,8)\n\t" /* KernelCallbackTable[id] */
".seh_handler " __ASM_NAME("user_callback_handler") ", @except\n\t"
".globl " __ASM_NAME("KiUserCallbackDispatcherReturn") "\n"
__ASM_NAME("KiUserCallbackDispatcherReturn") ":\n\t"
#else
"call " __ASM_NAME("dispatch_user_callback") "\n\t"
#endif
"xorq %rcx,%rcx\n\t" /* ret_ptr */
"xorl %edx,%edx\n\t" /* ret_len */
"movl %eax,%r8d\n\t" /* status */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment