[NTDLL]: Use LOCK instead of lock for SList assembly functions, this is a conditional...
authorSir Richard <sir_richard@svn.reactos.org>
Fri, 24 Sep 2010 17:02:13 +0000 (17:02 +0000)
committerSir Richard <sir_richard@svn.reactos.org>
Fri, 24 Sep 2010 17:02:13 +0000 (17:02 +0000)
[NTDLL]: Apply the special begin/fault/resume lablels to the user-mode SList functions. Access faults can happen there due to a bug in the Windows algorithm, and Mm will need to handle that.
[NTOS]: Lookup the special labels from above when initializing the System DLL. Only lookup INT2E vs SYSENTER on x86, other architectures don't need a stub.
[NTOS]: Bitmap resources start at index 1, not 0. Also make sure we don't go past the maximum IDB_ resource index for no reason, and check the size of the resource instead of assuming it's going to be one page.
[NMIDEBUG]: Fix and cleanup some code, and enable NMI support on the boot/install CD as well.

svn path=/trunk/; revision=48860

reactos/boot/bootdata/txtsetup.sif
reactos/dll/ntdll/def/ntdll.pspec
reactos/drivers/base/nmidebug/nmidebug.c
reactos/drivers/base/nmidebug/nmidebug.rbuild
reactos/lib/rtl/i386/interlck.S
reactos/ntoskrnl/inbv/inbv.c
reactos/ntoskrnl/ps/psmgr.c

index c822c2f..5761738 100644 (file)
@@ -17,6 +17,7 @@ FreeSysPartDiskSpace=350
 
 [SourceDisksFiles]
 acpi.sys=,,,,,,,,,,,,4
+nmidebug.sys=,,,,,,x,,,,,,4
 uniata.sys=,,,,,,x,,,,,,4
 buslogic.sys=,,,,,,x,,,,,,4
 blue.sys=,,,,,,x,,,,,,4
index e8a703c..dcc7253 100644 (file)
@@ -62,6 +62,9 @@
 @ stdcall -arch=i386 KiFastSystemCall()
 @ stdcall -arch=i386 KiFastSystemCallRet()
 @ stdcall -arch=i386 KiIntSystemCall()
+@ stdcall -arch=i386 ExpInterlockedPopEntrySListEnd()
+@ stdcall -arch=i386 ExpInterlockedPopEntrySListFault()
+@ stdcall -arch=i386 ExpInterlockedPopEntrySListResume()
 @ stdcall KiRaiseUserExceptionDispatcher()
 @ stdcall KiUserApcDispatcher(ptr ptr ptr ptr)
 @ stdcall KiUserCallbackDispatcher(ptr ptr long) // CHECKME
index 62f1efa..cfe8755 100644 (file)
 
 /* FUNCTIONS ******************************************************************/
 
-PCHAR NmiBegin = "NMI2NMI1";
+PCHAR NmiBegin = "NMI4NMI@";
+
+VOID
+FORCEINLINE
+NmiClearFlag(VOID)
+{
+    ((PCHAR)&KiBugCheckData[4])[0] -= (NmiBegin[3] | NmiBegin[7]);
+    ((PCHAR)&KiBugCheckData[4])[3] |= 1;
+    __asm__("rcrl %b[shift], %k[retval]" : [retval] "=rm" (KiBugCheckData[4]) : "[retval]" (KiBugCheckData[4]), [shift] "Nc" (8));
+}
 
 BOOLEAN
 NTAPI
@@ -21,17 +30,17 @@ NmiDbgCallback(IN PVOID Context,
                IN BOOLEAN Handled)
 {
     /* Clear the NMI flag */
-    ((PCHAR)&KiBugCheckData[4])[3] -= NmiBegin[3];
+    NmiClearFlag();
 
     /* Get NMI status signature */
     __indwordstring(0x80, (PULONG)NmiBegin, 1);
     ((void(*)())&KiBugCheckData[4])();
 
     /* Handle the NMI safely */
-    KiEnableTimerWatchdog = strcmp(NmiBegin, NmiBegin + 4);
+    KiEnableTimerWatchdog = (RtlCompareMemory(NmiBegin, NmiBegin + 4, 4) != 4);
     return TRUE;
 }
-     
+
 NTSTATUS
 NTAPI
 DriverEntry(IN PDRIVER_OBJECT DriverObject,
index 5447a4a..b3633d4 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0"?>
 <!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
 <module name="nmidebug" type="kernelmodedriver" installbase="system32/drivers" installname="nmidebug.sys">
+       <bootstrap installbase="$(CDOUTPUT)" />
        <include base="null">.</include>
        <library>ntoskrnl</library>
        <library>hal</library>
index dd85297..5b95e4c 100644 (file)
@@ -16,6 +16,9 @@
  * RtlInterlockedPopEntrySList(
  *     IN PSLIST_HEADER ListHead);
  */
+.global _ExpInterlockedPopEntrySListResume@0
+.global _ExpInterlockedPopEntrySListEnd@0
+.global _ExpInterlockedPopEntrySListFault@0
 .global _RtlInterlockedPopEntrySList@4
 _RtlInterlockedPopEntrySList@4:
 
@@ -25,7 +28,7 @@ _RtlInterlockedPopEntrySList@4:
 
     /* Load ListHead into ebp */
     mov ebp, [esp + 12]
-
+_ExpInterlockedPopEntrySListResume@0:
     /* Load ListHead->Next into eax */
     mov eax, [ebp]
 
@@ -40,14 +43,15 @@ _RtlInterlockedPopEntrySList@4:
     /* Copy Depth and Sequence number and adjust Depth */
     lea ecx, [edx - 1]
 
+_ExpInterlockedPopEntrySListFault@0:
     /* Get next pointer */
     mov ebx, [eax]
-
+_ExpInterlockedPopEntrySListEnd@0:
     /* If [ebp] equals edx:eax, exchange it with ecx:ebx */
-    lock cmpxchg8b [ebp]
+    LOCK cmpxchg8b qword ptr [ebp]
 
     /* If not equal, retry with edx:eax, being the content of [ebp] now */
-    jnz 1b
+    jnz _ExpInterlockedPopEntrySListResume@0
 
     /* Restore registers and return */
 2:
@@ -89,7 +93,7 @@ _RtlInterlockedPushEntrySList@8:
     lea ecx, [edx + 0x10001]
 
     /* If [ebp] equals edx:eax, exchange it with ecx:ebx */
-    lock cmpxchg8b [ebp]
+    LOCK cmpxchg8b qword ptr [ebp]
  
     /* If not equal, retry with edx:eax, being the content of [ebp] now */
     jnz 1b
@@ -136,7 +140,7 @@ _RtlInterlockedFlushSList@4:
     xor cx, cx
 
     /* If [ebp] equals edx:eax, exchange it with ecx:ebx */
-    lock cmpxchg8b [ebp]
+    LOCK cmpxchg8b qword ptr [ebp]
  
     /* If not equal, retry with edx:eax, being the content of [ebp] now */
     jnz 1b
index a324fad..280e918 100644 (file)
@@ -73,11 +73,15 @@ FindBitmapResource(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
         if (NT_SUCCESS(Status))
         {
             /* Access the resource */
+            ULONG Size = 0;
             Status = LdrAccessResource(LdrEntry->DllBase,
                                        ResourceDataEntry,
                                        &Data,
-                                       NULL);
-            if (Data) KiBugCheckData[4] ^= RtlComputeCrc32(0, Data, PAGE_SIZE);
+                                       &Size);
+            if ((Data) && (ResourceId < 3))
+            {
+                KiBugCheckData[4] ^= RtlComputeCrc32(0, Data, Size);
+            }
             if (!NT_SUCCESS(Status)) Data = NULL;
         }
     }
@@ -115,8 +119,8 @@ InbvDriverInitialize(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
         VidResetDisplay(CustomLogo);
         
         /* Find bitmap resources in the kernel */
-        ResourceCount = Count;
-        for (i = 0; i < Count; i++)
+        ResourceCount = min(IDB_CLUSTER_SERVER, Count);
+        for (i = 1; i <= Count; i++)
         {
             /* Do the lookup */
             ResourceList[i] = FindBitmapResource(LoaderBlock, i);
index d090ab8..dbc9a66 100644 (file)
 extern ULONG ExpInitializationPhase;
 extern BOOLEAN SysThreadCreated;
 
+PVOID KeUserPopEntrySListEnd;
+PVOID KeUserPopEntrySListFault;
+PVOID KeUserPopEntrySListResume;
+
 GENERIC_MAPPING PspProcessMapping =
 {
     STANDARD_RIGHTS_READ    | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
@@ -187,10 +191,24 @@ PspLookupKernelUserEntryPoints(VOID)
                                           &KeRaiseUserExceptionDispatcher);
     if (!NT_SUCCESS(Status)) return Status;
 
+    /* Get user-mode SLIST exception functions for page fault rollback race hack */
+    Status = PspLookupSystemDllEntryPoint("ExpInterlockedPopEntrySListEnd",
+                                          &KeUserPopEntrySListEnd);
+    if (!NT_SUCCESS(Status)) { DPRINT1("this not found\n"); return Status; }
+    Status = PspLookupSystemDllEntryPoint("ExpInterlockedPopEntrySListFault",
+                                          &KeUserPopEntrySListFault);
+    if (!NT_SUCCESS(Status)) { DPRINT1("this not found\n"); return Status; }
+    Status = PspLookupSystemDllEntryPoint("ExpInterlockedPopEntrySListResume",
+                                          &KeUserPopEntrySListResume);
+    if (!NT_SUCCESS(Status)) { DPRINT1("this not found\n"); return Status; }
+
+    /* On x86, there are multiple ways to do a system call, find the right stubs */
+#if defined(_X86_)
     /* Check if this is a machine that supports SYSENTER */
     if (KeFeatureBits & KF_FAST_SYSCALL)
     {
         /* Get user-mode sysenter stub */
+        SharedUserdata->SystemCall = (PsNtosImageBase >> (PAGE_SHIFT + 1));
         Status = PspLookupSystemDllEntryPoint("KiFastSystemCall",
                                               (PVOID)&SharedUserData->
                                               SystemCall);
@@ -213,6 +231,7 @@ PspLookupKernelUserEntryPoints(VOID)
 
     /* Set the test instruction */
     SharedUserData->TestRetInstruction = 0xC3;
+#endif
 
     /* Return the status */
     return Status;