Author: ion
Date: Wed Oct 4 20:00:36 2006
New Revision: 24395
URL:
http://svn.reactos.org/svn/reactos?rev=24395&view=rev
Log:
- Implement XPSP2+ syscall stub that uses indirect pointer instead of executable code
inside KUSER_SHARED_DATA.
- Someone (FILIP!) please fix LdrGetProcedureAddress. It's broken and I had to rename
an ntdll export to make it work (see comments).
- Make sure you REBUILD CLEAN. This commit changes NCITool!!!
- Setup some NPX-related CPU features in SharedUserData during KiInitializeKernel.
- Remove some now-deprecated initialization functions.
Modified:
trunk/reactos/dll/ntdll/def/ntdll.def
trunk/reactos/dll/ntdll/main/i386/dispatch.S
trunk/reactos/ntoskrnl/KrnlFun.c
trunk/reactos/ntoskrnl/ex/init.c
trunk/reactos/ntoskrnl/ke/i386/cpu.c
trunk/reactos/ntoskrnl/ke/i386/kiinit.c
trunk/reactos/ntoskrnl/ke/i386/trap.s
trunk/reactos/ntoskrnl/ldr/rtl.c
trunk/reactos/ntoskrnl/ps/psmgr.c
trunk/reactos/tools/nci/ncitool.c
Modified: trunk/reactos/dll/ntdll/def/ntdll.def
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/def/ntdll.def?re…
==============================================================================
--- trunk/reactos/dll/ntdll/def/ntdll.def (original)
+++ trunk/reactos/dll/ntdll/def/ntdll.def Wed Oct 4 20:00:36 2006
@@ -37,6 +37,9 @@
KiUserApcDispatcher@16
KiUserCallbackDispatcher@12
KiUserExceptionDispatcher@8
+KiIntSystemCall@0
+KeFastSystemCallRet@0 ; big hack since LdrGetProcedureAddress is broken
+KiFastSystemCall@0
LdrAccessResource@16
LdrAddRefDll@8
LdrDisableThreadCalloutsForDll@4
Modified: trunk/reactos/dll/ntdll/main/i386/dispatch.S
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/main/i386/dispat…
==============================================================================
--- trunk/reactos/dll/ntdll/main/i386/dispatch.S (original)
+++ trunk/reactos/dll/ntdll/main/i386/dispatch.S Wed Oct 4 20:00:36 2006
@@ -236,6 +236,35 @@
ret 8
.endfunc
+.func KiIntSystemCall@0
+.globl _KiIntSystemCall@0
+_KiIntSystemCall@0:
+
+ /* Set stack in EDX and do the interrupt */
+ lea edx, [esp+8]
+ int 0x2E
+
+ /* Return to caller */
+ ret
+.endfunc
+
+.func KiFastSystemCall@0
+.globl _KiFastSystemCall@0
+_KiFastSystemCall@0:
+
+ /* Put ESP in EDX and do the SYSENTER */
+ mov edx, esp
+ sysenter
+.endfunc
+
+.func KeFastSystemCallRet@0
+.globl _KeFastSystemCallRet@0
+_KeFastSystemCallRet@0:
+
+ /* Just return to caller */
+ ret
+.endfunc
+
.func RtlpGetStackLimits@8
.globl _RtlpGetStackLimits@8
_RtlpGetStackLimits@8:
Modified: trunk/reactos/ntoskrnl/KrnlFun.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/KrnlFun.c?rev=243…
==============================================================================
--- trunk/reactos/ntoskrnl/KrnlFun.c (original)
+++ trunk/reactos/ntoskrnl/KrnlFun.c Wed Oct 4 20:00:36 2006
@@ -27,8 +27,10 @@
// Ke:
//
// - FIXES:
-// * Get rid of KiRosPrintAddress and use KiDumpParameterImages instead.
+// * Stop using CachedModules.
+// * Try to make MmInit1 NTLDR compatible.
// * Sanitize some context fields during conversions.
+// * Figure out why the DPC stack doesn't really work.
// * Add DR macro/save and VM macro/save.
// - FEATURES:
// * New optimized table-based tick-hashed timer implementation.
Modified: trunk/reactos/ntoskrnl/ex/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=243…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/init.c (original)
+++ trunk/reactos/ntoskrnl/ex/init.c Wed Oct 4 20:00:36 2006
@@ -67,18 +67,9 @@
ULONG i;
BOOLEAN BootDriveFound = FALSE;
- /*
- * NOTE:
- * The shared user page has been zeroed-out right after creation.
- * There is NO need to do this again.
- */
- Ki386SetProcessorFeatures();
-
- /* Set the Version Data */
+ /* Set the Product Type */
SharedUserData->NtProductType = NtProductWinNt;
SharedUserData->ProductTypeIsValid = TRUE;
- SharedUserData->NtMajorVersion = 5;
- SharedUserData->NtMinorVersion = 0;
/*
* Retrieve the current dos system path
Modified: trunk/reactos/ntoskrnl/ke/i386/cpu.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/cpu.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/cpu.c (original)
+++ trunk/reactos/ntoskrnl/ke/i386/cpu.c Wed Oct 4 20:00:36 2006
@@ -650,97 +650,6 @@
}
VOID
-INIT_FUNCTION
-Ki386SetProcessorFeatures(VOID)
-{
- OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING KeyName =
-
RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Session
Manager\\Kernel");
- UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"FastSystemCallDisable");
- HANDLE KeyHandle;
- ULONG ResultLength;
- struct
- {
- KEY_VALUE_PARTIAL_INFORMATION Info;
- UCHAR Buffer[20];
- } ValueData;
- NTSTATUS Status;
- ULONG FastSystemCallDisable = 0;
-
- SharedUserData->ProcessorFeatures[PF_FLOATING_POINT_PRECISION_ERRATA] = FALSE;
- SharedUserData->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = FALSE;
- SharedUserData->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] =
- (KeFeatureBits & KF_CMPXCHG8B) ? TRUE : FALSE;
- SharedUserData->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] =
- (KeFeatureBits & KF_MMX) ? TRUE : FALSE;
- SharedUserData->ProcessorFeatures[PF_PPC_MOVEMEM_64BIT_OK] = FALSE;
- SharedUserData->ProcessorFeatures[PF_ALPHA_BYTE_INSTRUCTIONS] = FALSE;
- SharedUserData->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] =
- (KeFeatureBits & KF_XMMI) ? TRUE : FALSE;
- SharedUserData->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] =
- (KeFeatureBits & KF_RDTSC) ? TRUE : FALSE;
-
- /* Does the CPU Support Fast System Call? */
- if (KeFeatureBits & KF_FAST_SYSCALL) {
-
- /* FIXME: Check for Family == 6, Model < 3 and Stepping < 3 and disable */
-
- /* Make sure it's not disabled in registry */
- InitializeObjectAttributes(&ObjectAttributes,
- &KeyName,
- OBJ_CASE_INSENSITIVE,
- NULL,
- NULL);
- Status = ZwOpenKey(&KeyHandle,
- KEY_QUERY_VALUE,
- &ObjectAttributes);
-
- if (NT_SUCCESS(Status)) {
-
- /* Read the Value then Close the Key */
- Status = ZwQueryValueKey(KeyHandle,
- &ValueName,
- KeyValuePartialInformation,
- &ValueData,
- sizeof(ValueData),
- &ResultLength);
- if (NT_SUCCESS(Status))
- {
- if (ResultLength == sizeof(ValueData) &&
- ValueData.Info.Type == REG_DWORD)
- {
- FastSystemCallDisable = *(PULONG)ValueData.Info.Data != 0;
- }
-
- ZwClose(KeyHandle);
- }
- }
-
- } else {
-
- /* Disable SYSENTER/SYSEXIT, because the CPU doesn't support it */
- FastSystemCallDisable = 1;
-
- }
-
- if (FastSystemCallDisable) {
- /* Use INT2E */
- const unsigned char Entry[7] = {0x8D, 0x54, 0x24, 0x08, /* lea
0x8(%esp),%edx */
- 0xCD, 0x2E, /* int 0x2e
*/
- 0xC3}; /* ret
*/
- memcpy(&SharedUserData->SystemCall, Entry, sizeof(Entry));
- } else {
- /* Use SYSENTER */
- const unsigned char Entry[5] = {0x8B, 0xD4, /* movl %esp,%edx
*/
- 0x0F, 0x34, /* sysenter
*/
- 0xC3}; /* ret
*/
- memcpy(&SharedUserData->SystemCall, Entry, sizeof(Entry));
- /* Enable SYSENTER/SYSEXIT */
- KiFastSystemCallDisable = 0;
- }
-}
-
-VOID
NTAPI
KeFlushCurrentTb(VOID)
{
Modified: trunk/reactos/ntoskrnl/ke/i386/kiinit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/kiinit.c?…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/kiinit.c (original)
+++ trunk/reactos/ntoskrnl/ke/i386/kiinit.c Wed Oct 4 20:00:36 2006
@@ -421,6 +421,20 @@
/* Set the NX Support policy */
SharedUserData->NXSupportPolicy = NXSupportPolicy;
+ /* Set basic CPU Features that user mode can read */
+ SharedUserData->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] =
+ (KeFeatureBits & KF_MMX);
+ SharedUserData->ProcessorFeatures[PF_COMPARE_EXCHANGE_DOUBLE] =
+ (KeFeatureBits & KF_CMPXCHG8B);
+ SharedUserData->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] =
+ ((KeFeatureBits & KF_FXSR) && (KeFeatureBits & KF_XMMI));
+ SharedUserData->ProcessorFeatures[PF_XMMI64_INSTRUCTIONS_AVAILABLE] =
+ ((KeFeatureBits & KF_FXSR) && (KeFeatureBits & KF_XMMI64));
+ SharedUserData->ProcessorFeatures[PF_3DNOW_INSTRUCTIONS_AVAILABLE] =
+ (KeFeatureBits & KF_3DNOW);
+ SharedUserData->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] =
+ (KeFeatureBits & KF_RDTSC);
+
/* Setup the Idle Thread */
KeInitializeThread(InitProcess,
InitThread,
Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?re…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/trap.s (original)
+++ trunk/reactos/ntoskrnl/ke/i386/trap.s Wed Oct 4 20:00:36 2006
@@ -134,7 +134,7 @@
popf /* Set our EFLAGS */
or dword ptr [esp], EFLAGS_INTERRUPT_MASK /* Re-enable IRQs in EFLAGS, to fake INT
*/
push KGDT_R3_CODE + RPL_MASK
- push KUSER_SHARED_SYSCALL_RET
+ push dword ptr ds:KUSER_SHARED_SYSCALL_RET
/* Setup the Trap Frame stack */
push 0
Modified: trunk/reactos/ntoskrnl/ldr/rtl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ldr/rtl.c?rev=243…
==============================================================================
--- trunk/reactos/ntoskrnl/ldr/rtl.c (original)
+++ trunk/reactos/ntoskrnl/ldr/rtl.c Wed Oct 4 20:00:36 2006
@@ -55,6 +55,12 @@
* -- Filip Navara, August 1st, 2005
*/
+ /*
+ * I don't know who wrote this code but it's not working.
+ * Test case: KiFastSystemCall and KiFastSystemCallRet in ntdll.
+ * Former can't be found even though it's exported.
+ */
+
OrdinalPtr = (PUSHORT)RVA(BaseAddress, ExportDir->AddressOfNameOrdinals);
NamePtr = (PULONG)RVA(BaseAddress, ExportDir->AddressOfNames);
Modified: trunk/reactos/ntoskrnl/ps/psmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/psmgr.c?rev=24…
==============================================================================
--- trunk/reactos/ntoskrnl/ps/psmgr.c (original)
+++ trunk/reactos/ntoskrnl/ps/psmgr.c Wed Oct 4 20:00:36 2006
@@ -41,6 +41,9 @@
ANSI_STRING ExceptName = RTL_CONSTANT_STRING("KiUserExceptionDispatcher");
ANSI_STRING CallbackName = RTL_CONSTANT_STRING("KiUserCallbackDispatcher");
ANSI_STRING RaiseName = RTL_CONSTANT_STRING("KiRaiseUserExceptionDispatcher");
+ANSI_STRING FastName = RTL_CONSTANT_STRING("KiFastSystemCall");
+ANSI_STRING FastReturnName = RTL_CONSTANT_STRING("KeFastSystemCallRet");
+ANSI_STRING InterruptName = RTL_CONSTANT_STRING("KiIntSystemCall");
PHANDLE_TABLE PspCidTable;
@@ -97,6 +100,34 @@
/* Get user-mode exception raise trampoline */
Status = PspLookupSystemDllEntryPoint(&RaiseName,
&KeRaiseUserExceptionDispatcher);
+ if (!NT_SUCCESS(Status)) return Status;
+
+ /* Check if this is a machine that supports SYSENTER */
+ if (KeFeatureBits & KF_FAST_SYSCALL)
+ {
+ /* Get user-mode sysenter stub */
+ Status = PspLookupSystemDllEntryPoint(&FastName,
+ (PVOID)&SharedUserData->
+ SystemCall);
+ if (!NT_SUCCESS(Status)) return Status;
+
+ /* Get user-mode sysenter return stub */
+ Status = PspLookupSystemDllEntryPoint(&FastReturnName,
+ (PVOID)&SharedUserData->
+ SystemCallReturn);
+ }
+ else
+ {
+ /* Get the user-mode interrupt stub */
+ Status = PspLookupSystemDllEntryPoint(&InterruptName,
+ (PVOID)&SharedUserData->
+ SystemCall);
+ }
+
+ /* Set the test instruction */
+ if (!NT_SUCCESS(Status)) SharedUserData->TestRetInstruction = 0xC3;
+
+ /* Return the status */
return Status;
}
Modified: trunk/reactos/tools/nci/ncitool.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/nci/ncitool.c?rev=24…
==============================================================================
--- trunk/reactos/tools/nci/ncitool.c (original)
+++ trunk/reactos/tools/nci/ncitool.c Wed Oct 4 20:00:36 2006
@@ -51,7 +51,7 @@
#if defined(__GNUC__)
#define UserModeStub_x86 " movl $0x%x, %%eax\n" \
" movl $KUSER_SHARED_SYSCALL, %%ecx\n" \
- " call *%%ecx\n" \
+ " call *(%%ecx)\n" \
" ret $0x%x\n\n"
#elif defined(_MSC_VER)
#define UserModeStub_x86 " asm { \n" \