* Add more PSDK defintions to asm.h

* Use these new definitions instead of constants in syscall.S
* Document the macros using doxygen-compatible format, and convert SET_TF_DEBUG_HEADER to as macro instead of CPP macro.
* Use SET_TF_DEBUG_HEADER in system call handlers instead of duplicating the code.

svn path=/trunk/; revision=20930
This commit is contained in:
Alex Ionescu 2006-01-17 03:00:21 +00:00
parent 3ad6f05446
commit 5b6264cf13
3 changed files with 68 additions and 52 deletions

View file

@ -360,6 +360,20 @@ Author:
#define STATUS_INVALID_SYSTEM_SERVICE 0xC000001C #define STATUS_INVALID_SYSTEM_SERVICE 0xC000001C
#endif #endif
//
// System Call Table definitions
//
#define NUMBER_SERVICE_TABLES 0x0002
#define SERVICE_NUMBER_MASK 0x0FFF
#define SERVICE_TABLE_SHIFT 0x0008
#define SERVICE_TABLE_MASK 0x0010
#define SERVICE_TABLE_TEST 0x0010
#define SERVICE_DESCRIPTOR_BASE 0x0000
#define SERVICE_DESCRIPTOR_COUNT 0x0004
#define SERVICE_DESCRIPTOR_LIMIT 0x0008
#define SERVICE_DESCRIPTOR_NUMBER 0x000C
#define SERVICE_DESCRIPTOR_LENGTH 0x0010
// //
// Generic Definitions // Generic Definitions
// //

View file

@ -46,30 +46,40 @@
#endif #endif
// //
// SET_TF_DEBUG_HEADER // @name SET_TF_DEBUG_HEADER
// This macro sets up the debug header in the trap frame.
// Assumptions:
// ebp = PKTRAP_FRAME
// edi/ebx = Have been saved and can be used
// //
#define SET_TF_DEBUG_HEADER \ // This macro sets up the debug header in the trap frame.
/* Get the Debug Trap Frame EBP/EIP */ \ //
mov ebx, [ebp+KTRAP_FRAME_EBP]; \ // @param None.
mov edi, [ebp+KTRAP_FRAME_EIP]; \ //
\ // @remark ebp = PKTRAP_FRAME.
/* Write the debug data */ \ // edi/ebx = Have been saved and can be used.
mov [ebp+KTRAP_FRAME_DEBUGPOINTER], edx; \ //
mov dword ptr [ebp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00; \ .macro SET_TF_DEBUG_HEADER
mov [ebp+KTRAP_FRAME_DEBUGEBP], ebx; \ /* Get the Debug Trap Frame EBP/EIP */
mov [ebp+KTRAP_FRAME_DEBUGEIP], edi; mov ebx, [ebp+KTRAP_FRAME_EBP]
mov edi, [ebp+KTRAP_FRAME_EIP]
/* Write the debug data */
mov [ebp+KTRAP_FRAME_DEBUGPOINTER], edx
mov dword ptr [ebp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
mov [ebp+KTRAP_FRAME_DEBUGEBP], ebx
mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
.endm
// //
// These macros help with USer-Mode APC delivery after exiting a trap. // @name CHECK_FOR_APC_DELIVER
// //
// CHECK_FOR_APC_DELIVER
// This macro checks if the trapframe indicates a return to user-mode, // This macro checks if the trapframe indicates a return to user-mode,
// and, if so, checks if user-mode APCs should be delivered. // and, if so, checks if user-mode APCs should be delivered.
// //
// @param PreserveEax
// Determines if EAX should be preserved. Implies that the segment
// registers will also be saved.
//
// @remark ebp = PKTRAP_FRAME.
// ebx = Saved and will be used.
//
.macro CHECK_FOR_APC_DELIVER PreserveEax .macro CHECK_FOR_APC_DELIVER PreserveEax
/* Check for V86 mode */ /* Check for V86 mode */
test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
@ -129,16 +139,18 @@
2: 2:
.endm .endm
// //
// These macros control common execution paths for Traps and System Call Code // @name TRAP_PROLOG
// //
// TRAP_PROLOG
// This macro creates a standard trap entry prologue. // This macro creates a standard trap entry prologue.
// It should be used for entry into any kernel trap (KiTrapXx), but not for // It should be used for entry into any kernel trap (KiTrapXx), but not for
// system calls, which require special handling. // system calls, which require special handling.
// //
// Use as follows: // @param Label
// Identifying name of the caller function; will be used to append
// to the name V86 and DR helper functions, which must already exist.
//
// @remark Use as follows:
// _KiTrap00: // _KiTrap00:
// /* Push fake error code */ // /* Push fake error code */
// push 0 // push 0

View file

@ -238,24 +238,20 @@ _KiSystemService:
mov ebx, [esi+KTHREAD_TRAP_FRAME] mov ebx, [esi+KTHREAD_TRAP_FRAME]
mov [ebp+KTRAP_FRAME_EDX], ebx mov [ebp+KTRAP_FRAME_EDX], ebx
// ==================== COMMON DR SAVE CHECK.AND DEBUG FRAME SETUP ============//
/* Flush DR7 */ /* Flush DR7 */
and dword ptr [ebp+KTRAP_FRAME_DR7], 0 and dword ptr [ebp+KTRAP_FRAME_DR7], 0
/* Check if the thread was being debugged */ /* Check if the thread was being debugged */
test byte ptr [esi+KTHREAD_DEBUG_ACTIVE], 0xFF test byte ptr [esi+KTHREAD_DEBUG_ACTIVE], 0xFF
cld
//jnz Dr_kss_a //jnz Dr_kss_a
/* Save a pointer to the trap frame in the TCB */
SharedCode: SharedCode:
mov [esi+KTHREAD_TRAP_FRAME], ebp mov [esi+KTHREAD_TRAP_FRAME], ebp
/* Get the Debug Trap Frame EBP/EIP */ /* Set the trap frame debug header */
mov ebx, [ebp+KTRAP_FRAME_EBP] SET_TF_DEBUG_HEADER
mov edi, [ebp+KTRAP_FRAME_EIP]
#ifdef DBG #ifdef DBG // FIXME: Is this for GDB? Can it be moved in the stub?
/* /*
* We want to know the address from where the syscall stub was called. * We want to know the address from where the syscall stub was called.
* If PrevMode is KernelMode, that address is stored in our own (kernel) * If PrevMode is KernelMode, that address is stored in our own (kernel)
@ -269,15 +265,9 @@ SharedCode:
jz PrevWasKernelMode jz PrevWasKernelMode
mov edi, [edi+4] mov edi, [edi+4]
PrevWasKernelMode: PrevWasKernelMode:
mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
#endif #endif
/* Write the debug data */
mov [ebp+KTRAP_FRAME_DEBUGPOINTER], edx
mov dword ptr [ebp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
mov [ebp+KTRAP_FRAME_DEBUGEBP], ebx
mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
// ============= END OF COMMON DR SAVE CHECK.AND DEBUG FRAME SETUP ============//
/* Enable interrupts */ /* Enable interrupts */
sti sti
@ -288,8 +278,8 @@ CheckValidCall:
* The offset is related to the Table Index as such: Offset = TableIndex x 10 * The offset is related to the Table Index as such: Offset = TableIndex x 10
*/ */
mov edi, eax mov edi, eax
shr edi, 8 shr edi, SERVICE_TABLE_SHIFT
and edi, 0x10 and edi, SERVICE_TABLE_MASK
mov ecx, edi mov ecx, edi
/* Now add the thread's base system table to the offset */ /* Now add the thread's base system table to the offset */
@ -297,8 +287,8 @@ CheckValidCall:
/* Get the true syscall ID and check it */ /* Get the true syscall ID and check it */
mov ebx, eax mov ebx, eax
and eax, 0xFFF and eax, SERVICE_NUMBER_MASK
cmp eax, [edi+8] cmp eax, [edi+SERVICE_DESCRIPTOR_LIMIT]
/* Invalid ID, try to load Win32K Table */ /* Invalid ID, try to load Win32K Table */
jnb KiBBTUnexpectedRange jnb KiBBTUnexpectedRange
@ -307,7 +297,7 @@ CheckValidCall:
// <== We don't have a KeGdiFlushUserBatch callback yet (needs to be // <== We don't have a KeGdiFlushUserBatch callback yet (needs to be
// sent through the PsInitializeWin32Callouts structure) // sent through the PsInitializeWin32Callouts structure)
/* Check if this was Win32K */ /* Check if this was Win32K */
cmp ecx, 0x10 cmp ecx, SERVICE_TABLE_TEST
jnz NotWin32K jnz NotWin32K
/* Get the TEB */ /* Get the TEB */
@ -332,7 +322,7 @@ NotWin32K:
#ifdef DBG #ifdef DBG
/* Increase per-syscall count */ /* Increase per-syscall count */
mov ecx, [edi+4] mov ecx, [edi+SERVICE_DESCRIPTOR_COUNT]
jecxz NoCountTable jecxz NoCountTable
inc dword ptr [ecx+eax*4] inc dword ptr [ecx+eax*4]
#endif #endif
@ -342,12 +332,12 @@ NoCountTable:
mov esi, edx mov esi, edx
/* Allocate room for argument list from kernel stack */ /* Allocate room for argument list from kernel stack */
mov ebx, [edi+12] mov ebx, [edi+SERVICE_DESCRIPTOR_NUMBER]
xor ecx, ecx xor ecx, ecx
mov cl, [eax+ebx] mov cl, [eax+ebx]
/* Get pointer to function */ /* Get pointer to function */
mov edi, [edi] mov edi, [edi+SERVICE_DESCRIPTOR_BASE]
mov ebx, [edi+eax*4] mov ebx, [edi+eax*4]
/* Allocate space on our stack */ /* Allocate space on our stack */