From c3d35eaa65fefef3667d27b1adfd3c8d7c504139 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Tue, 19 Apr 2011 18:13:10 +0000 Subject: [PATCH] [CMAKE] * 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 | 5 ++ lib/rossym/CMakeLists.txt | 1 + lib/rossym/initkm.c | 4 +- lib/rossym/iofile.c | 34 +++++++++ lib/rossym/rossympriv.h | 3 + ntoskrnl/CMakeLists.txt | 2 +- ntoskrnl/cache/section/io.c | 8 ++- ntoskrnl/cache/section/newmm.h | 35 +-------- ntoskrnl/kdbg/kdb_symbols.c | 128 ++++++++++++++++++++++----------- 9 files changed, 137 insertions(+), 83 deletions(-) create mode 100644 lib/rossym/iofile.c diff --git a/include/reactos/rossym.h b/include/reactos/rossym.h index 6236cc1f8dd..d65f9695a76 100644 --- a/include/reactos/rossym.h +++ b/include/reactos/rossym.h @@ -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; diff --git a/lib/rossym/CMakeLists.txt b/lib/rossym/CMakeLists.txt index 98e9ee4f881..2b05860e247 100644 --- a/lib/rossym/CMakeLists.txt +++ b/lib/rossym/CMakeLists.txt @@ -16,6 +16,7 @@ list(APPEND SOURCE dwarfpubnames.c find.c fromfile.c + iofile.c init.c initkm.c initum.c diff --git a/lib/rossym/initkm.c b/lib/rossym/initkm.c index a50680e11da..4f1c07111a3 100644 --- a/lib/rossym/initkm.c +++ b/lib/rossym/initkm.c @@ -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 index 00000000000..97069c50076 --- /dev/null +++ b/lib/rossym/iofile.c @@ -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 +#include +#include "rossympriv.h" + +#define NDEBUG +#include + +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 */ diff --git a/lib/rossym/rossympriv.h b/lib/rossym/rossympriv.h index fb97019710a..ffeb2ce6782 100644 --- a/lib/rossym/rossympriv.h +++ b/lib/rossym/rossympriv.h @@ -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 \ diff --git a/ntoskrnl/CMakeLists.txt b/ntoskrnl/CMakeLists.txt index f10b62c9f3f..b2e740c62c0 100644 --- a/ntoskrnl/CMakeLists.txt +++ b/ntoskrnl/CMakeLists.txt @@ -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 diff --git a/ntoskrnl/cache/section/io.c b/ntoskrnl/cache/section/io.c index 254c25c38a6..4d59412451a 100644 --- a/ntoskrnl/cache/section/io.c +++ b/ntoskrnl/cache/section/io.c @@ -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) { diff --git a/ntoskrnl/cache/section/newmm.h b/ntoskrnl/cache/section/newmm.h index 43fd3fe7cef..e1b0511cff9 100644 --- a/ntoskrnl/cache/section/newmm.h +++ b/ntoskrnl/cache/section/newmm.h @@ -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); diff --git a/ntoskrnl/kdbg/kdb_symbols.c b/ntoskrnl/kdbg/kdb_symbols.c index f021649f12f..bff96963604 100644 --- a/ntoskrnl/kdbg/kdb_symbols.c +++ b/ntoskrnl/kdbg/kdb_symbols.c @@ -12,7 +12,8 @@ #include -#define NDEBUG +//#define NDEBUG +#include "../cache/section/newmm.h" #include /* 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 -- 2.17.1