[CMAKE]
authorAmine Khaldi <amine.khaldi@reactos.org>
Tue, 19 Apr 2011 18:13:10 +0000 (18:13 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Tue, 19 Apr 2011 18:13:10 +0000 (18:13 +0000)
* The cmake branch is so awesome you don't even need to manually translate addresses. Automagic usermode address translation brought to you by the Arty.

svn path=/branches/cmake-bringup/; revision=51404

include/reactos/rossym.h
lib/rossym/CMakeLists.txt
lib/rossym/initkm.c
lib/rossym/iofile.c [new file with mode: 0644]
lib/rossym/rossympriv.h
ntoskrnl/CMakeLists.txt
ntoskrnl/cache/section/io.c
ntoskrnl/cache/section/newmm.h
ntoskrnl/kdbg/kdb_symbols.c

index 6236cc1..d65f969 100644 (file)
@@ -24,6 +24,11 @@ typedef struct _ROSSYM_CALLBACKS {
   BOOLEAN (*SeekFileProc)(PVOID FileContext, ULONG_PTR Position);
 } ROSSYM_CALLBACKS, *PROSSYM_CALLBACKS;
 
+typedef struct _ROSSYM_OWN_FILECONTEXT {
+  BOOLEAN (*ReadFileProc)(PVOID FileContext, PVOID Buffer, ULONG Size);
+  BOOLEAN (*SeekFileProc)(PVOID FileContext, ULONG_PTR Position);
+} ROSSYM_OWN_FILECONTEXT, *PROSSYM_OWN_FILECONTEXT;
+
 struct Dwarf;
 typedef struct Dwarf *PROSSYM_INFO;
 
index 98e9ee4..2b05860 100644 (file)
@@ -16,6 +16,7 @@ list(APPEND SOURCE
     dwarfpubnames.c
     find.c
     fromfile.c
+    iofile.c
     init.c
     initkm.c
     initum.c
index a50680e..4f1c071 100644 (file)
@@ -38,8 +38,8 @@ RosSymInitKernelMode(VOID)
     {
       RosSymAllocMemKM,
       RosSymFreeMemKM,
-      RosSymZwReadFile,
-      RosSymZwSeekFile
+      RosSymIoReadFile,
+      RosSymIoSeekFile
     };
 
   RosSymInit(&KmCallbacks);
diff --git a/lib/rossym/iofile.c b/lib/rossym/iofile.c
new file mode 100644 (file)
index 0000000..97069c5
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS kernel
+ * FILE:            lib/rossym/zwfile.c
+ * PURPOSE:         File I/O using native functions
+ *
+ * PROGRAMMERS:     Ge van Geldorp (gvg@reactos.com)
+ */
+
+#define NTOSAPI
+#include <ntddk.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+NTSTATUS RosSymStatus;
+
+BOOLEAN
+RosSymIoReadFile(PVOID FileContext, PVOID Buffer, ULONG Size)
+{
+    PROSSYM_OWN_FILECONTEXT OwnContext = (PROSSYM_OWN_FILECONTEXT)FileContext;
+    return OwnContext->ReadFileProc(FileContext, Buffer, Size);
+}
+
+BOOLEAN
+RosSymIoSeekFile(PVOID FileContext, ULONG_PTR Position)
+{
+    PROSSYM_OWN_FILECONTEXT OwnContext = (PROSSYM_OWN_FILECONTEXT)FileContext;
+    return OwnContext->SeekFileProc(FileContext, Position);
+}
+
+/* EOF */
index fb97019..ffeb2ce 100644 (file)
@@ -19,6 +19,9 @@ extern ROSSYM_CALLBACKS RosSymCallbacks;
 extern BOOLEAN RosSymZwReadFile(PVOID FileContext, PVOID Buffer, ULONG Size);
 extern BOOLEAN RosSymZwSeekFile(PVOID FileContext, ULONG_PTR Position);
 
+extern BOOLEAN RosSymIoReadFile(PVOID FileContext, PVOID Buffer, ULONG Size);
+extern BOOLEAN RosSymIoSeekFile(PVOID FileContext, ULONG_PTR Position);
+
 #define ROSSYM_IS_VALID_DOS_HEADER(DosHeader) (IMAGE_DOS_SIGNATURE == (DosHeader)->e_magic \
                                                && 0L != (DosHeader)->e_lfanew)
 #define ROSSYM_IS_VALID_NT_HEADERS(NtHeaders) (IMAGE_NT_SIGNATURE == (NtHeaders)->Signature \
index f10b62c..b2e740c 100644 (file)
@@ -32,7 +32,6 @@ if(NEWCC)
         cache/pinsup.c
         cache/section/data.c
         cache/section/fault.c
-        cache/section/io.c
         cache/section/reqtools.c
         cache/section/sptab.c
         cache/section/swapout.c)
@@ -47,6 +46,7 @@ else()
 endif()
 
 list(APPEND SOURCE
+    cache/section/io.c
     config/cmalloc.c
     config/cmapi.c
     config/cmboot.c
index 254c25c..4d59412 100644 (file)
@@ -99,6 +99,7 @@ MiSimpleRead
  PLARGE_INTEGER FileOffset,
  PVOID Buffer, 
  ULONG Length,
+ BOOLEAN Paging,
  PIO_STATUS_BLOCK ReadStatus)
 {
     NTSTATUS Status;
@@ -127,7 +128,7 @@ MiSimpleRead
                 Length);
 
     KeInitializeEvent(&ReadWait, NotificationEvent, FALSE);
-    
+
     Irp = IoBuildAsynchronousFsdRequest
                (IRP_MJ_READ,
                 DeviceObject,
@@ -141,7 +142,7 @@ MiSimpleRead
                return STATUS_NO_MEMORY;
     }
     
-    Irp->Flags |= IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO | IRP_NOCACHE | IRP_SYNCHRONOUS_API;
+    Irp->Flags |= (Paging ? IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO | IRP_NOCACHE : 0) | IRP_SYNCHRONOUS_API;
     
     Irp->UserEvent = &ReadWait;
     Irp->Tail.Overlay.OriginalFileObject = FileObject;
@@ -150,7 +151,8 @@ MiSimpleRead
        IrpSp->Control |= SL_INVOKE_ON_SUCCESS | SL_INVOKE_ON_ERROR;
     IrpSp->FileObject = FileObject;
     IrpSp->CompletionRoutine = MiSimpleReadComplete;
-    
+    ObReferenceObject(FileObject);
+
     Status = IoCallDriver(DeviceObject, Irp);
     if (Status == STATUS_PENDING)
     {
index 43fd3fe..e1b0511 100644 (file)
@@ -181,6 +181,7 @@ MiSimpleRead
  PLARGE_INTEGER FileOffset,
  PVOID Buffer, 
  ULONG Length,
+ BOOLEAN Paging,
  PIO_STATUS_BLOCK ReadStatus);
 
 NTSTATUS
@@ -404,40 +405,6 @@ MmCreateCacheSection
  ULONG AllocationAttributes,
  PFILE_OBJECT FileObject);
 
-NTSTATUS
-NTAPI
-MiSimpleRead
-(PFILE_OBJECT FileObject, 
- PLARGE_INTEGER FileOffset,
- PVOID Buffer, 
- ULONG Length,
- PIO_STATUS_BLOCK ReadStatus);
-
-NTSTATUS
-NTAPI
-_MiSimpleWrite
-(PFILE_OBJECT FileObject, 
- PLARGE_INTEGER FileOffset,
- PVOID Buffer, 
- ULONG Length,
- PIO_STATUS_BLOCK ReadStatus,
- const char *file,
- int line);
-
-#define MiSimpleWrite(F,O,B,L,R) _MiSimpleWrite(F,O,B,L,R,__FILE__,__LINE__)
-
-NTSTATUS
-NTAPI
-_MiWriteBackPage
-(PFILE_OBJECT FileObject,
- PLARGE_INTEGER Offset,
- ULONG Length,
- PFN_NUMBER Page,
- const char *File,
- int Line);
-
-#define MiWriteBackPage(F,O,L,P) _MiWriteBackPage(F,O,L,P,__FILE__,__LINE__)
-
 PVOID
 NTAPI
 MmGetSegmentRmap(PFN_NUMBER Page, PULONG RawOffset);
index f021649..bff9696 100644 (file)
@@ -12,7 +12,8 @@
 
 #include <ntoskrnl.h>
 
-#define NDEBUG
+//#define NDEBUG
+#include "../cache/section/newmm.h"
 #include <debug.h>
 
 /* GLOBALS ******************************************************************/
@@ -26,6 +27,12 @@ typedef struct _IMAGE_SYMBOL_INFO_CACHE
 }
 IMAGE_SYMBOL_INFO_CACHE, *PIMAGE_SYMBOL_INFO_CACHE;
 
+typedef struct _ROSSYM_KM_OWN_CONTEXT {
+    ROSSYM_OWN_FILECONTEXT Rossym;
+    LARGE_INTEGER FileOffset;
+    PFILE_OBJECT FileObject;
+} ROSSYM_KM_OWN_CONTEXT, *PROSSYM_KM_OWN_CONTEXT;
+
 static BOOLEAN LoadSymbols;
 static LIST_ENTRY SymbolFileListHead;
 static KSPIN_LOCK SymbolFileListLock;
@@ -35,6 +42,50 @@ BOOLEAN KdbpSymbolsInitialized = FALSE;
 
 /* FUNCTIONS ****************************************************************/
 
+static BOOLEAN
+KdbpSeekSymFile(PVOID FileContext, ULONG_PTR Target)
+{
+    PROSSYM_KM_OWN_CONTEXT Context = (PROSSYM_KM_OWN_CONTEXT)FileContext;
+    Context->FileOffset.QuadPart = Target;
+    return TRUE;
+}
+
+static BOOLEAN
+KdbpReadSymFile(PVOID FileContext, PVOID Buffer, ULONG Length)
+{
+    PROSSYM_KM_OWN_CONTEXT Context = (PROSSYM_KM_OWN_CONTEXT)FileContext;
+    IO_STATUS_BLOCK Iosb;
+    NTSTATUS Status = MiSimpleRead
+        (Context->FileObject, 
+         &Context->FileOffset,
+         Buffer,
+         Length,
+         FALSE,
+         &Iosb);
+    return NT_SUCCESS(Status);
+}
+
+static PROSSYM_OWN_FILECONTEXT 
+KdbpCaptureFileForSymbols(PFILE_OBJECT FileObject)
+{
+    PROSSYM_KM_OWN_CONTEXT Context = ExAllocatePool(NonPagedPool, sizeof(*Context));
+    if (!Context) return NULL;
+    ObReferenceObject(FileObject);
+    Context->FileOffset.QuadPart = 0;
+    Context->FileObject = FileObject;
+    Context->Rossym.ReadFileProc = KdbpReadSymFile;
+    Context->Rossym.SeekFileProc = KdbpSeekSymFile;
+    return &Context->Rossym;
+}
+
+static VOID
+KdbpReleaseFileForSymbols(PROSSYM_OWN_FILECONTEXT FileContext)
+{
+    PROSSYM_KM_OWN_CONTEXT Context = (PROSSYM_KM_OWN_CONTEXT)FileContext;
+    ObDereferenceObject(Context->FileObject);
+    ExFreePool(Context);
+}
+
 static BOOLEAN
 KdbpSymSearchModuleList(
     IN PLIST_ENTRY current_entry,
@@ -127,12 +178,9 @@ KdbSymPrintAddress(
     IN PVOID Address)
 {
        PMEMORY_AREA MemoryArea = NULL;
-       HANDLE FileHandle = NULL;
        PROS_SECTION_OBJECT SectionObject;
     PLDR_DATA_TABLE_ENTRY LdrEntry;
-       OBJECT_ATTRIBUTES ObjectAttributes;
-       IO_STATUS_BLOCK IoStatusBlock;
-       UNICODE_STRING ModuleFileName;
+    PROSSYM_OWN_FILECONTEXT FileContext;
     ULONG_PTR RelativeAddress;
     NTSTATUS Status;
     ULONG LineNumber;
@@ -163,44 +211,22 @@ KdbSymPrintAddress(
                }
                SectionObject = MemoryArea->Data.SectionData.Section;
                if (!(SectionObject->AllocationAttributes & SEC_IMAGE)) goto end;
-               if (SectionObject->ImageSection->ImageBase != KdbpImageBase)
+               if (MemoryArea->StartingAddress != KdbpImageBase)
                {
                        if (KdbpRosSymInfo)
                        {
                                RosSymDelete(KdbpRosSymInfo);
                                KdbpRosSymInfo = NULL;
+                KdbpImageBase = 0;
                        }
 
-                       Status = MmGetFileNameForAddress(Address, &ModuleFileName);
-                       if (!NT_SUCCESS(Status))
-                               goto end;
-
-                       InitializeObjectAttributes
-                               (&ObjectAttributes,
-                                &ModuleFileName,
-                                OBJ_CASE_INSENSITIVE,
-                                NULL,
-                                NULL);
-
-                       if (!NT_SUCCESS
-                               (ZwOpenFile
-                                (&FileHandle,
-                                 FILE_READ_ACCESS,
-                                 &ObjectAttributes,
-                                 &IoStatusBlock,
-                                 FILE_SHARE_READ,
-                                 FILE_SYNCHRONOUS_IO_NONALERT)))
+            if ((FileContext = KdbpCaptureFileForSymbols(SectionObject->FileObject)))
                        {
-                               goto end;
-                       }
+                if (RosSymCreateFromFile(FileContext, &KdbpRosSymInfo))
+                    KdbpImageBase = MemoryArea->StartingAddress;
 
-                       if (!RosSymCreateFromFile(&FileHandle, &KdbpRosSymInfo))
-                       {
-                               KdbpRosSymInfo = NULL;
+                KdbpReleaseFileForSymbols(FileContext);
                        }
-
-                       ZwClose(FileHandle);
-                       KdbpImageBase = SectionObject->ImageSection->ImageBase;
                }
 
                if (KdbpRosSymInfo)
@@ -402,6 +428,8 @@ KdbpSymLoadModuleSymbols(
     HANDLE FileHandle;
     NTSTATUS Status;
     IO_STATUS_BLOCK IoStatusBlock;
+    PFILE_OBJECT FileObject;
+    PROSSYM_OWN_FILECONTEXT FileContext;
 
     /* Allow KDB to break on module load */
     KdbModuleLoaded(FileName);
@@ -423,7 +451,7 @@ KdbpSymLoadModuleSymbols(
     /*  Open the file  */
     InitializeObjectAttributes(&ObjectAttributes,
                                FileName,
-                               0,
+                               OBJ_CASE_INSENSITIVE,
                                NULL,
                                NULL);
 
@@ -443,20 +471,34 @@ KdbpSymLoadModuleSymbols(
 
     DPRINT("Loading symbols from %wZ...\n", FileName);
 
-    if (!RosSymCreateFromFile(&FileHandle, RosSymInfo))
+    Status = ObReferenceObjectByHandle
+        (FileHandle,
+         FILE_READ_DATA|SYNCHRONIZE,
+         NULL,
+         KernelMode,
+         (PVOID*)&FileObject,
+         NULL);
+
+    if (!NT_SUCCESS(Status))
     {
-        DPRINT("Failed to load symbols from %wZ\n", FileName);
+        DPRINT("Could not get the file object\n");
+        ZwClose(FileHandle);
         return;
     }
 
-    ZwClose(FileHandle);
-
-    DPRINT("Symbols loaded.\n");
-
-    /* add file to cache */
-    KdbpSymAddCachedFile(FileName, *RosSymInfo);
+    if ((FileContext = KdbpCaptureFileForSymbols(FileObject)))
+    {
+        if (RosSymCreateFromFile(FileContext, RosSymInfo))
+        {
+            /* add file to cache */
+            KdbpSymAddCachedFile(FileName, *RosSymInfo);
+            DPRINT("Installed symbols: %wZ %p\n", FileName, *RosSymInfo);
+        }
+        KdbpReleaseFileForSymbols(FileContext);
+    }
 
-    DPRINT("Installed symbols: %wZ %p\n", FileName, *RosSymInfo);
+    ObDereferenceObject(FileObject);
+    ZwClose(FileHandle);
 }
 
 VOID