[ros-diffs] [tkreuzer] 43993: [RTL] Simplify RtlLookupFunctionTable

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Sat Nov 7 04:33:00 CET 2009


Author: tkreuzer
Date: Sat Nov  7 04:33:00 2009
New Revision: 43993

URL: http://svn.reactos.org/svn/reactos?rev=43993&view=rev
Log:
[RTL]
Simplify RtlLookupFunctionTable

Modified:
    branches/ros-amd64-bringup/reactos/lib/rtl/amd64/unwind.c

Modified: branches/ros-amd64-bringup/reactos/lib/rtl/amd64/unwind.c
URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/lib/rtl/amd64/unwind.c?rev=43993&r1=43992&r2=43993&view=diff
==============================================================================
--- branches/ros-amd64-bringup/reactos/lib/rtl/amd64/unwind.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/lib/rtl/amd64/unwind.c [iso-8859-1] Sat Nov  7 04:33:00 2009
@@ -60,6 +60,17 @@
 
 /* FUNCTIONS *****************************************************************/
 
+/*! RtlLookupFunctionTable
+ * \brief Locates the table of RUNTIME_FUNCTION entries for a code address.
+ * \param ControlPc
+ *            Address of the code, for which the table should be searched.
+ * \param ImageBase 
+ *            Pointer to a DWORD64 that receives the base address of the
+ *            corresponding executable image.
+ * \param Length
+ *            Pointer to an ULONG that receives the number of table entries
+ *            present in the table.
+ */
 PRUNTIME_FUNCTION
 NTAPI
 RtlLookupFunctionTable(
@@ -67,34 +78,27 @@
     OUT PDWORD64 ImageBase,
     OUT PULONG Length)
 {
-    PIMAGE_DOS_HEADER DosHeader;
-    PIMAGE_NT_HEADERS NtHeader;
-    PIMAGE_DATA_DIRECTORY Directory;
-
-    /* Find ModuleBase */
-    if (!RtlPcToFileHeader((PVOID)ControlPc, (PVOID*)&DosHeader))
-    {
+    PVOID Table;
+    ULONG Size;
+
+    /* Find corresponding file header from code address */
+    if (!RtlPcToFileHeader((PVOID)ControlPc, (PVOID*)ImageBase))
+    {
+        /* Nothing found */
         return NULL;
     }
 
-    /* Locate NT header and check number of directories */
-    NtHeader = (PVOID)((ULONG64)DosHeader + DosHeader->e_lfanew);
-    if (NtHeader->OptionalHeader.NumberOfRvaAndSizes 
-         < IMAGE_DIRECTORY_ENTRY_EXCEPTION)
-    {
-        return NULL;
-    }
-
     /* Locate the exception directory */
-    Directory = &NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXCEPTION];
-    *Length = Directory->Size / sizeof(RUNTIME_FUNCTION);
-    *ImageBase = (ULONG64)DosHeader;
-    if (!Directory->VirtualAddress)
-    {
-        return NULL;
-    }
-
-    return (PVOID)((ULONG64)DosHeader + Directory->VirtualAddress);
+    Table = RtlImageDirectoryEntryToData((PVOID)*ImageBase,
+                                         TRUE,
+                                         IMAGE_DIRECTORY_ENTRY_EXCEPTION,
+                                         &Size);
+
+    /* Return the number of entries */
+    *Length = Size / sizeof(RUNTIME_FUNCTION);
+
+    /* Return the address of the table */
+    return Table;
 }
 
 /*! RtlLookupFunctionEntry
@@ -119,7 +123,7 @@
     /* Fail, if no table is found */
     if (!FunctionTable)
     {
-        return (PVOID)1;
+        return NULL;
     }
 
     /* Use relative virtual address */




More information about the Ros-diffs mailing list