Sync with trunk (48237)
[reactos.git] / ntoskrnl / rtl / libsupp.c
index ae87fc5..aba04f1 100644 (file)
@@ -28,6 +28,30 @@ SIZE_T RtlpAllocDeallocQueryBufferSize = 128;
 
 /* FUNCTIONS *****************************************************************/
 
+PVOID
+NTAPI
+RtlPcToFileHeader(
+    IN  PVOID PcValue,
+    OUT PVOID *BaseOfImage)
+{
+    PLDR_DATA_TABLE_ENTRY LdrEntry;
+    BOOLEAN InSystem;
+
+    /* Get the base for this file */
+    if ((ULONG_PTR)PcValue > (ULONG_PTR)MmHighestUserAddress)
+    {
+        /* We are in kernel */
+        *BaseOfImage = KiPcToFileHeader(PcValue, &LdrEntry, FALSE, &InSystem);
+    }
+    else
+    {
+        /* We are in user land */
+        *BaseOfImage = KiRosPcToUserFileHeader(PcValue, &LdrEntry);
+    }
+
+    return *BaseOfImage;
+}
+
 VOID
 NTAPI
 RtlInitializeRangeListPackage(VOID)
@@ -225,7 +249,7 @@ RtlpHandleDpcStackException(IN PEXCEPTION_REGISTRATION_RECORD RegistrationFrame,
     return FALSE;
 }
 
-#ifndef _ARM_
+#if !defined(_ARM_) && !defined(_AMD64_)
 
 BOOLEAN
 NTAPI
@@ -317,7 +341,7 @@ RtlWalkFrameChain(OUT PVOID *Callers,
                                         &StackBegin,
                                         &StackEnd);
         if (!Result) return 0;
-    }
+        }
 
     /* Use a SEH block for maximum protection */
     _SEH2_TRY
@@ -331,17 +355,16 @@ RtlWalkFrameChain(OUT PVOID *Callers,
 
             /* Make sure we can trust the TEB and trap frame */
             if (!(Teb) ||
-                !(Thread->SystemThread) ||
                 (KeIsAttachedProcess()) ||
                 (KeGetCurrentIrql() >= DISPATCH_LEVEL))
             {
                 /* Invalid or unsafe attempt to get the stack */
-                return 0;
+                _SEH2_YIELD(return 0;)
             }
 
             /* Get the stack limits */
-            StackBegin = (ULONG_PTR)Teb->Tib.StackLimit;
-            StackEnd = (ULONG_PTR)Teb->Tib.StackBase;
+            StackBegin = (ULONG_PTR)Teb->NtTib.StackLimit;
+            StackEnd = (ULONG_PTR)Teb->NtTib.StackBase;
 #ifdef _M_IX86
             Stack = TrapFrame->Ebp;
 #elif defined(_M_PPC)
@@ -418,6 +441,19 @@ RtlWalkFrameChain(OUT PVOID *Callers,
 
 #endif
 
+#ifdef _AMD64_
+VOID
+NTAPI
+RtlpGetStackLimits(
+    OUT PULONG_PTR LowLimit,
+    OUT PULONG_PTR HighLimit)
+{
+    PKTHREAD CurrentThread = KeGetCurrentThread();
+    *HighLimit = (ULONG_PTR)CurrentThread->InitialStack;
+    *LowLimit = (ULONG_PTR)CurrentThread->StackLimit;
+}
+#endif
+
 /* RTL Atom Tables ************************************************************/
 
 NTSTATUS