2005-03-19 20:26:46 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2006-01-11 05:55:49 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* FILE: ntoskrnl/ke/i386/usercall_asm.S
|
2005-03-19 20:26:46 +00:00
|
|
|
* PURPOSE: User-Mode callbacks and return.
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
#include <asm.inc>
|
|
|
|
#include <ks386.inc>
|
2006-01-17 05:05:35 +00:00
|
|
|
#include <internal/i386/asmmacro.S>
|
2005-03-19 20:26:46 +00:00
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
EXTERN _MmGrowKernelStack@4:PROC
|
2011-07-03 09:56:59 +00:00
|
|
|
EXTERN _KeUserCallbackDispatcher:DWORD
|
2010-11-27 22:12:15 +00:00
|
|
|
EXTERN @KiServiceExit@8:PROC
|
2011-05-13 19:51:09 +00:00
|
|
|
EXTERN _KeGetCurrentIrql@0:PROC
|
|
|
|
EXTERN _KeBugCheckEx@20:PROC
|
2011-07-25 00:01:29 +00:00
|
|
|
EXTERN @KiUserModeCallout@4:PROC
|
2005-03-19 20:26:46 +00:00
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
.code
|
2010-02-10 23:24:59 +00:00
|
|
|
|
2005-03-19 20:26:46 +00:00
|
|
|
/*++
|
2011-05-13 19:51:09 +00:00
|
|
|
* @name KiCallUserMode
|
2005-03-19 20:26:46 +00:00
|
|
|
*
|
|
|
|
* The KiSwitchToUserMode routine sets up a Trap Frame and a Callback stack
|
|
|
|
* for the purpose of switching to user mode. The actual final jump is done
|
|
|
|
* by KiServiceExit which will treat this as a syscall return.
|
|
|
|
*
|
2006-01-11 05:55:49 +00:00
|
|
|
* @param OutputBuffer
|
|
|
|
* Pointer to a caller-allocated buffer where to receive the return data
|
|
|
|
* from the user-mode function
|
2005-03-19 20:26:46 +00:00
|
|
|
*
|
2006-01-11 05:55:49 +00:00
|
|
|
* @param OutputLength
|
|
|
|
* Size of the Output Buffer described above.
|
2005-03-19 20:26:46 +00:00
|
|
|
*
|
2006-01-11 05:55:49 +00:00
|
|
|
* @return None. Jumps into KiServiceExit.
|
2005-03-19 20:26:46 +00:00
|
|
|
*
|
2006-01-11 05:55:49 +00:00
|
|
|
* @remark If there is not enough Kernel Stack space, the routine will increase the
|
|
|
|
* Kernel Stack.
|
2005-03-19 20:26:46 +00:00
|
|
|
*
|
2006-01-11 05:55:49 +00:00
|
|
|
* User mode execution resumes at ntdll!KiUserCallbackDispatcher.
|
2005-03-19 20:26:46 +00:00
|
|
|
*
|
2006-01-11 05:55:49 +00:00
|
|
|
* This call MUST be paired by interrupt 0x2B or NtCallbackReturn.
|
2005-03-19 20:26:46 +00:00
|
|
|
*
|
|
|
|
*--*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC _KiCallUserMode@8
|
2006-01-11 05:55:49 +00:00
|
|
|
_KiCallUserMode@8:
|
|
|
|
|
2011-07-25 00:07:07 +00:00
|
|
|
/* Push non-volatile registers on the stack.
|
2011-07-25 00:01:29 +00:00
|
|
|
This is part of the KCALLOUT_FRAME */
|
2006-01-11 05:55:49 +00:00
|
|
|
push ebp
|
|
|
|
push ebx
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
2011-07-25 00:01:29 +00:00
|
|
|
/* load the address of the callout frame into ecx */
|
|
|
|
lea ecx, [esp - 12]
|
2006-01-11 05:55:49 +00:00
|
|
|
|
2013-04-04 20:11:17 +00:00
|
|
|
/* Allocate space for the initial stack */
|
2011-07-25 00:01:29 +00:00
|
|
|
sub esp, 12 + NPX_FRAME_LENGTH + KTRAP_FRAME_LENGTH + 16
|
2006-01-11 05:55:49 +00:00
|
|
|
|
2011-07-25 00:01:29 +00:00
|
|
|
call @KiUserModeCallout@4
|
2006-08-31 18:10:11 +00:00
|
|
|
|
2011-07-25 00:01:29 +00:00
|
|
|
add esp, 12 + NPX_FRAME_LENGTH + KTRAP_FRAME_LENGTH + 16
|
2006-08-31 18:10:11 +00:00
|
|
|
|
2006-01-11 05:55:49 +00:00
|
|
|
/* Restore registers */
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebx
|
|
|
|
pop ebp
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret 8
|
2005-03-19 20:26:46 +00:00
|
|
|
|
|
|
|
|
2006-08-31 18:10:11 +00:00
|
|
|
|
2013-10-19 18:04:15 +00:00
|
|
|
PUBLIC @KiCallbackReturn@8
|
|
|
|
@KiCallbackReturn@8:
|
2006-08-31 18:10:11 +00:00
|
|
|
|
2013-10-19 18:04:15 +00:00
|
|
|
/* Restore the stack */
|
|
|
|
mov esp, ecx
|
2006-01-11 05:55:49 +00:00
|
|
|
|
|
|
|
/* Set status and return */
|
2013-10-19 18:04:15 +00:00
|
|
|
mov eax, edx
|
2006-01-11 05:55:49 +00:00
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
pop ebx
|
|
|
|
pop ebp
|
|
|
|
|
2013-10-19 18:04:15 +00:00
|
|
|
/* Clean stack and return */
|
|
|
|
ret 8
|
2006-01-11 05:55:49 +00:00
|
|
|
|
2006-01-13 22:23:31 +00:00
|
|
|
/*++
|
2011-05-13 19:51:09 +00:00
|
|
|
* @name KeSwitchKernelStack
|
2006-01-13 22:23:31 +00:00
|
|
|
*
|
|
|
|
* The KeSwitchKernelStack routine switches from the current thread's stack
|
|
|
|
* to the new specified base and limit.
|
|
|
|
*
|
|
|
|
* @param StackBase
|
|
|
|
* Pointer to the new Stack Base of the thread.
|
|
|
|
*
|
|
|
|
* @param StackLimit
|
|
|
|
* Pointer to the new Stack Limit of the thread.
|
|
|
|
*
|
2008-09-12 11:13:15 +00:00
|
|
|
* @return The previous Stack Base of the thread.
|
2006-01-13 22:23:31 +00:00
|
|
|
*
|
2011-05-13 19:51:09 +00:00
|
|
|
* @remark This routine should typically only be used when converting from a
|
2006-01-13 22:23:31 +00:00
|
|
|
* non-GUI to a GUI Thread. The caller is responsible for freeing the
|
|
|
|
* previous stack. The new stack values MUST be valid before calling
|
|
|
|
* this routine.
|
|
|
|
*
|
|
|
|
*--*/
|
2010-11-27 22:12:15 +00:00
|
|
|
PUBLIC _KeSwitchKernelStack@8
|
2006-01-11 05:55:49 +00:00
|
|
|
_KeSwitchKernelStack@8:
|
|
|
|
|
|
|
|
/* Save volatiles */
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
/* Get current thread */
|
|
|
|
mov edx, fs:[KPCR_CURRENT_THREAD]
|
|
|
|
|
|
|
|
/* Get new and current base */
|
|
|
|
mov edi, [esp+12]
|
|
|
|
mov ecx, [edx+KTHREAD_STACK_BASE]
|
|
|
|
|
|
|
|
/* Fixup the frame pointer */
|
|
|
|
sub ebp, ecx
|
|
|
|
add ebp, edi
|
|
|
|
|
|
|
|
/* Fixup the trap frame */
|
|
|
|
mov eax, [edx+KTHREAD_TRAP_FRAME]
|
|
|
|
sub eax, ecx
|
|
|
|
add eax, edi
|
|
|
|
mov [edx+KTHREAD_TRAP_FRAME], eax
|
|
|
|
|
|
|
|
/* Calculate stack size */
|
|
|
|
sub ecx, esp
|
|
|
|
|
|
|
|
/* Get desination and origin */
|
|
|
|
sub edi, ecx
|
|
|
|
mov esi, esp
|
|
|
|
|
|
|
|
/* Save stack pointer */
|
|
|
|
push edi
|
|
|
|
|
|
|
|
/* Copy stack */
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
/* Restore stack pointer */
|
|
|
|
pop edi
|
|
|
|
|
|
|
|
/* Save old stack base and get new limit/base */
|
2008-09-12 11:13:15 +00:00
|
|
|
mov eax, [edx+KTHREAD_STACK_BASE]
|
2006-01-11 05:55:49 +00:00
|
|
|
mov ecx, [esp+12]
|
|
|
|
mov esi, [esp+16]
|
|
|
|
|
|
|
|
/* Disable interrupts for stack switch */
|
|
|
|
cli
|
|
|
|
|
|
|
|
/* Set new base/limit */
|
|
|
|
mov [edx+KTHREAD_STACK_BASE], ecx
|
|
|
|
mov [edx+KTHREAD_STACK_LIMIT], esi
|
|
|
|
|
|
|
|
/* Set LargeStack */
|
|
|
|
mov byte ptr [edx+KTHREAD_LARGE_STACK], 1
|
|
|
|
|
|
|
|
/* Set new initial stack */
|
|
|
|
mov [edx+KTHREAD_INITIAL_STACK], ecx
|
|
|
|
|
|
|
|
/* Get trap frame */
|
|
|
|
mov esi, [edx+KTHREAD_TRAP_FRAME]
|
|
|
|
|
|
|
|
/* Get TSS */
|
|
|
|
mov edx, fs:[KPCR_TSS]
|
|
|
|
|
|
|
|
/* Check if we came from V86 mode */
|
|
|
|
test dword ptr [esi+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
|
|
|
|
|
|
|
|
/* Bias for NPX Area */
|
|
|
|
lea ecx, [ecx-NPX_FRAME_LENGTH]
|
|
|
|
jnz V86Switch
|
|
|
|
sub ecx, 16
|
|
|
|
|
|
|
|
V86Switch:
|
|
|
|
|
|
|
|
/* Update ESP in TSS */
|
|
|
|
mov [edx+KTSS_ESP0], ecx
|
|
|
|
|
|
|
|
/* Update stack pointer */
|
|
|
|
mov esp, edi
|
|
|
|
|
|
|
|
/* Bring back interrupts and return */
|
|
|
|
sti
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
ret 8
|
2010-11-27 22:12:15 +00:00
|
|
|
|
|
|
|
END
|