2009-10-12 03:35:35 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS NT Library
|
|
|
|
* FILE: dl/ntdll/dispatch/i386/dispatch.S
|
|
|
|
* PURPOSE: User-Mode NT Dispatchers
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
#include <asm.inc>
|
|
|
|
#include <ks386.inc>
|
|
|
|
|
|
|
|
EXTERN _LdrpInit@12:PROC
|
|
|
|
EXTERN _NtTestAlert@0:PROC
|
|
|
|
EXTERN _RtlDispatchException@8:PROC
|
|
|
|
EXTERN _RtlRaiseException@4:PROC
|
|
|
|
EXTERN _RtlRaiseStatus@4:PROC
|
|
|
|
EXTERN _ZwCallbackReturn@12:PROC
|
|
|
|
EXTERN _ZwContinue@8:PROC
|
|
|
|
EXTERN _ZwRaiseException@12:PROC
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
2010-11-27 22:12:15 +00:00
|
|
|
.code
|
2009-10-12 03:35:35 +00:00
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC _LdrInitializeThunk@16
|
2009-10-12 03:35:35 +00:00
|
|
|
_LdrInitializeThunk@16:
|
|
|
|
|
|
|
|
/* Get the APC Context */
|
|
|
|
lea eax, [esp+16]
|
|
|
|
|
|
|
|
/* Send it as the first parameter */
|
|
|
|
mov [esp+4], eax
|
|
|
|
|
|
|
|
/* Terminate the frame list */
|
|
|
|
xor ebp, ebp
|
|
|
|
|
|
|
|
/* Jump into the C initialization routine */
|
|
|
|
jmp _LdrpInit@12
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
_KiUserApcExceptionHandler:
|
|
|
|
|
|
|
|
/* Put the exception record in ECX and check the Flags */
|
|
|
|
mov ecx, [esp+4]
|
|
|
|
test dword ptr [ecx+EXCEPTION_RECORD_EXCEPTION_FLAGS], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
|
|
|
|
jz .return
|
|
|
|
|
|
|
|
/* Test alert the thread */
|
|
|
|
call _NtTestAlert@0
|
|
|
|
|
|
|
|
.return:
|
|
|
|
/* We'll execute handler */
|
|
|
|
mov eax, EXCEPTION_EXECUTE_HANDLER
|
|
|
|
ret 16
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
PUBLIC _KiUserApcDispatcher@16
|
2009-10-12 03:35:35 +00:00
|
|
|
_KiUserApcDispatcher@16:
|
|
|
|
|
|
|
|
/* Setup SEH stack */
|
|
|
|
lea eax, [esp+CONTEXT_ALIGNED_SIZE+16]
|
|
|
|
mov ecx, fs:[TEB_EXCEPTION_LIST]
|
|
|
|
mov edx, offset _KiUserApcExceptionHandler
|
|
|
|
mov [eax], ecx
|
|
|
|
mov [eax+4], edx
|
|
|
|
|
|
|
|
/* Enable SEH */
|
|
|
|
mov fs:[TEB_EXCEPTION_LIST], eax
|
|
|
|
|
|
|
|
/* Put the Context in EDI */
|
|
|
|
pop eax
|
|
|
|
lea edi, [esp+12]
|
|
|
|
|
|
|
|
/* Call the APC Routine */
|
|
|
|
call eax
|
|
|
|
|
|
|
|
/* Restore exception list */
|
|
|
|
mov ecx, [edi+CONTEXT_ALIGNED_SIZE]
|
|
|
|
mov fs:[TEB_EXCEPTION_LIST], ecx
|
|
|
|
|
|
|
|
/* Switch back to the context */
|
|
|
|
push 1
|
|
|
|
push edi
|
|
|
|
call _ZwContinue@8
|
|
|
|
|
|
|
|
/* Save callback return value */
|
|
|
|
mov esi, eax
|
|
|
|
|
|
|
|
/* Raise status */
|
|
|
|
StatusRaiseApc:
|
|
|
|
push esi
|
|
|
|
call _RtlRaiseStatus@4
|
|
|
|
jmp StatusRaiseApc
|
|
|
|
ret 16
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
|
2009-10-12 03:35:35 +00:00
|
|
|
_KiUserCallbackExceptionHandler:
|
|
|
|
|
|
|
|
/* Put the exception record in ECX and check the Flags */
|
|
|
|
mov ecx, [esp+4]
|
|
|
|
test dword ptr [ecx+EXCEPTION_RECORD_EXCEPTION_FLAGS], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
|
|
|
|
jz return
|
|
|
|
|
|
|
|
/* Tell the kernel to invalidate the stack */
|
|
|
|
push STATUS_CALLBACK_POP_STACK
|
|
|
|
push 0
|
|
|
|
push 0
|
|
|
|
call _ZwCallbackReturn@12
|
|
|
|
|
|
|
|
return:
|
|
|
|
/* We'll execute the handler */
|
|
|
|
mov eax, EXCEPTION_EXECUTE_HANDLER
|
|
|
|
ret 16
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
PUBLIC _KiUserCallbackDispatcher@12
|
2009-10-12 03:35:35 +00:00
|
|
|
_KiUserCallbackDispatcher@12:
|
|
|
|
|
|
|
|
/* Setup SEH stack */
|
|
|
|
mov ecx, fs:[TEB_EXCEPTION_LIST]
|
|
|
|
mov edx, offset _KiUserCallbackExceptionHandler
|
|
|
|
lea eax, [esp+16]
|
|
|
|
mov [esp+16], ecx
|
|
|
|
mov [esp+20], edx
|
|
|
|
|
|
|
|
/* Enable SEH */
|
|
|
|
mov fs:[TEB_EXCEPTION_LIST], eax
|
|
|
|
|
|
|
|
/* Get the callback Index */
|
|
|
|
add esp, 4
|
|
|
|
pop edx
|
|
|
|
|
|
|
|
/* Get the callback table */
|
|
|
|
mov eax, [fs:TEB_PEB]
|
|
|
|
mov eax, [eax+PEB_KERNEL_CALLBACK_TABLE]
|
|
|
|
|
|
|
|
/* Call the routine */
|
2010-11-27 22:12:15 +00:00
|
|
|
call dword ptr [eax+edx*4]
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Return from callback */
|
|
|
|
push eax
|
|
|
|
push 0
|
|
|
|
push 0
|
|
|
|
call _ZwCallbackReturn@12
|
|
|
|
|
|
|
|
/* Save callback return value */
|
|
|
|
mov esi, eax
|
|
|
|
|
|
|
|
/* Raise status */
|
|
|
|
StatusRaise:
|
|
|
|
push esi
|
|
|
|
call _RtlRaiseStatus@4
|
|
|
|
jmp StatusRaise
|
|
|
|
ret 12
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
PUBLIC _KiRaiseUserExceptionDispatcher@0
|
2009-10-12 03:35:35 +00:00
|
|
|
_KiRaiseUserExceptionDispatcher@0:
|
|
|
|
|
|
|
|
/* Setup stack for EXCEPTION_RECORD */
|
|
|
|
push ebp
|
|
|
|
mov ebp, esp
|
|
|
|
sub esp, EXCEPTION_RECORD_LENGTH
|
|
|
|
|
|
|
|
/* Fill out the record */
|
|
|
|
mov [esp+EXCEPTION_RECORD_EXCEPTION_ADDRESS], eax
|
|
|
|
mov eax, [fs:KPCR_TEB]
|
|
|
|
mov eax, [eax+TEB_EXCEPTION_CODE]
|
|
|
|
mov [esp+EXCEPTION_RECORD_EXCEPTION_CODE], eax
|
|
|
|
mov dword ptr [esp+EXCEPTION_RECORD_EXCEPTION_FLAGS], 0
|
|
|
|
mov dword ptr [esp+EXCEPTION_RECORD_EXCEPTION_RECORD], 0
|
|
|
|
mov dword ptr [esp+EXCEPTION_RECORD_NUMBER_PARAMETERS], 0
|
|
|
|
|
|
|
|
/* Raise the exception */
|
|
|
|
push esp
|
|
|
|
call _RtlRaiseException@4
|
|
|
|
|
|
|
|
/* Return exception code */
|
|
|
|
mov eax, [esp+EXCEPTION_RECORD_EXCEPTION_CODE]
|
|
|
|
mov esp, ebp
|
|
|
|
pop ebp
|
|
|
|
ret
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
PUBLIC _KiUserExceptionDispatcher@8
|
2011-10-13 15:16:29 +00:00
|
|
|
.PROC _KiUserExceptionDispatcher@8
|
2011-07-17 00:38:46 +00:00
|
|
|
FPO 0, 0, 0, 0, 0, FRAME_FPO
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Clear direction flag */
|
|
|
|
cld
|
|
|
|
|
|
|
|
/* Save the Context and Exception Records */
|
|
|
|
mov ecx, [esp+4]
|
|
|
|
mov ebx, [esp]
|
|
|
|
|
|
|
|
/* Dispatch the exception */
|
|
|
|
push ecx
|
|
|
|
push ebx
|
|
|
|
call _RtlDispatchException@8
|
|
|
|
|
|
|
|
/* Check for success */
|
|
|
|
or al, al
|
|
|
|
jz RaiseException
|
|
|
|
|
|
|
|
/* Pop off the records */
|
|
|
|
pop ebx
|
|
|
|
pop ecx
|
|
|
|
|
|
|
|
/* We're fine, continue execution */
|
|
|
|
push 0
|
|
|
|
push ecx
|
|
|
|
call _ZwContinue@8
|
|
|
|
|
|
|
|
/* Exit */
|
|
|
|
jmp Exit
|
|
|
|
|
|
|
|
RaiseException:
|
|
|
|
/* Pop off the records */
|
|
|
|
pop ebx
|
|
|
|
pop ecx
|
|
|
|
|
|
|
|
/* Raise the exception */
|
|
|
|
push 0
|
|
|
|
push ecx
|
|
|
|
push ebx
|
|
|
|
call _ZwRaiseException@12
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
/* Allocate space for the nested exception record */
|
|
|
|
add esp, -SIZEOF_EXCEPTION_RECORD
|
|
|
|
|
|
|
|
/* Set it up */
|
|
|
|
mov [esp+EXCEPTION_RECORD_EXCEPTION_CODE], eax
|
|
|
|
mov dword ptr [esp+EXCEPTION_RECORD_EXCEPTION_FLAGS], EXCEPTION_NONCONTINUABLE
|
|
|
|
mov [esp+EXCEPTION_RECORD_EXCEPTION_RECORD], ebx
|
|
|
|
mov dword ptr [esp+EXCEPTION_RECORD_NUMBER_PARAMETERS], 0
|
|
|
|
|
|
|
|
/* Raise the exception */
|
|
|
|
push esp
|
|
|
|
call _RtlRaiseException@4
|
|
|
|
ret 8
|
|
|
|
|
2011-10-13 15:16:29 +00:00
|
|
|
.ENDP
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
PUBLIC _KiIntSystemCall@0
|
2011-10-13 15:16:29 +00:00
|
|
|
.PROC _KiIntSystemCall@0
|
2011-07-17 00:38:46 +00:00
|
|
|
FPO 0, 0, 0, 0, 0, FRAME_FPO
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Set stack in EDX and do the interrupt */
|
|
|
|
lea edx, [esp+8]
|
2010-11-27 22:12:15 +00:00
|
|
|
int HEX(2E)
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Return to caller */
|
|
|
|
ret
|
|
|
|
|
2011-10-13 15:16:29 +00:00
|
|
|
.ENDP
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
PUBLIC _KiFastSystemCall@0
|
2011-10-13 15:16:29 +00:00
|
|
|
.PROC _KiFastSystemCall@0
|
2011-07-17 00:38:46 +00:00
|
|
|
FPO 0, 0, 0, 0, 0, FRAME_FPO
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Put ESP in EDX and do the SYSENTER */
|
|
|
|
mov edx, esp
|
|
|
|
sysenter
|
|
|
|
|
2011-10-13 15:16:29 +00:00
|
|
|
.ENDP
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
PUBLIC _KiFastSystemCallRet@0
|
2011-10-13 15:16:29 +00:00
|
|
|
.PROC _KiFastSystemCallRet@0
|
2011-07-17 00:38:46 +00:00
|
|
|
FPO 0, 0, 0, 0, 0, FRAME_FPO
|
2009-10-12 03:35:35 +00:00
|
|
|
|
|
|
|
/* Just return to caller */
|
|
|
|
ret
|
|
|
|
|
2011-10-13 15:16:29 +00:00
|
|
|
.ENDP
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
END
|