Merge trunk head (r43756)
[reactos.git] / reactos / dll / ntdll / rtl / libsupp.c
index 3c4e01b..c10bb87 100644 (file)
 
 SIZE_T RtlpAllocDeallocQueryBufferSize = PAGE_SIZE;
 PTEB LdrpTopLevelDllBeingLoadedTeb = NULL;
 
 SIZE_T RtlpAllocDeallocQueryBufferSize = PAGE_SIZE;
 PTEB LdrpTopLevelDllBeingLoadedTeb = NULL;
+#define IMAGE_DOS_MAGIC 0x5a4d
+#define IMAGE_PE_MAGIC 0x00004550
 
 /* FUNCTIONS ***************************************************************/
 
 
 /* FUNCTIONS ***************************************************************/
 
+#ifndef _M_AMD64
+// FIXME: Why "Not implemented"???
 /*
  * @implemented
  */
 /*
  * @implemented
  */
@@ -30,6 +34,7 @@ RtlWalkFrameChain(OUT PVOID *Callers,
     /* Not implemented for user-mode */
     return 0;
 }
     /* Not implemented for user-mode */
     return 0;
 }
+#endif
 
 BOOLEAN
 NTAPI
 
 BOOLEAN
 NTAPI
@@ -205,6 +210,19 @@ RtlpCaptureStackLimits(IN ULONG_PTR Ebp,
     return TRUE;
 }
 
     return TRUE;
 }
 
+#ifdef _AMD64_
+VOID
+NTAPI
+RtlpGetStackLimits(
+    OUT PULONG_PTR LowLimit,
+    OUT PULONG_PTR HighLimit)
+{
+    *LowLimit = (ULONG_PTR)NtCurrentTeb()->Tib.StackLimit;
+    *HighLimit = (ULONG_PTR)NtCurrentTeb()->Tib.StackBase;
+    return;
+}
+#endif
+
 BOOLEAN
 NTAPI
 RtlIsThreadWithinLoaderCallout(VOID)
 BOOLEAN
 NTAPI
 RtlIsThreadWithinLoaderCallout(VOID)
@@ -367,6 +385,62 @@ RtlpGetAtomEntry(PRTL_ATOM_TABLE AtomTable, ULONG Index)
    return NULL;
 }
 
    return NULL;
 }
 
+PVOID
+NTAPI
+RtlpLookupModuleBase(
+    PVOID Address)
+{
+    NTSTATUS Status;
+    MEMORY_BASIC_INFORMATION MemoryInformation;
+    ULONG_PTR Base, Limit;
+    PIMAGE_DOS_HEADER DosHeader;
+    PIMAGE_NT_HEADERS NtHeader;
+
+    Status = NtQueryVirtualMemory(NtCurrentProcess(),
+                                  Address,
+                                  MemoryBasicInformation,
+                                  &MemoryInformation,
+                                  sizeof(MEMORY_BASIC_INFORMATION),
+                                  NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        return NULL;
+    }
+
+    /* FIXME: remove these checks? */
+    Base = (ULONG_PTR)MemoryInformation.BaseAddress;
+    Limit = Base + MemoryInformation.RegionSize;
+    if ( ((ULONG_PTR)Address < Base) ||
+         ((ULONG_PTR)Address >= Limit) )
+    {
+        /* WTF? */
+        return NULL;
+    }
+
+    /* Check if we got the right kind of memory */
+    if ( (MemoryInformation.State != MEM_COMMIT) ||
+         (MemoryInformation.Type != MEM_IMAGE) )
+    {
+        return NULL;
+    }
+
+    /* Check DOS magic */
+    DosHeader = MemoryInformation.AllocationBase;
+    if (DosHeader->e_magic != IMAGE_DOS_MAGIC)
+    {
+        return NULL;
+    }
+
+    /* Check NT header */
+    NtHeader = (PVOID)((ULONG_PTR)DosHeader + DosHeader->e_lfanew);
+    if (NtHeader->Signature != IMAGE_PE_MAGIC)
+    {
+        return NULL;
+    }
+
+    return MemoryInformation.AllocationBase;
+}
+
 
 /*
  * Ldr Resource support code
 
 /*
  * Ldr Resource support code