Store symbolic information in a .rossym section in the
executable/library/driver/whatever
Modified: trunk/reactos/Makefile
Modified: trunk/reactos/boot/freeldr/freeldr/Makefile
Modified: trunk/reactos/boot/freeldr/freeldr/include/freeldr.h
Modified: trunk/reactos/boot/freeldr/freeldr/multiboot.c
Modified: trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
Modified: trunk/reactos/include/ntdll/ldr.h
Deleted: trunk/reactos/include/ntos/kdbgsyms.h
Modified: trunk/reactos/include/ntos.h
Added: trunk/reactos/include/reactos/rossym.h
Added: trunk/reactos/lib/rossym/
Added: trunk/reactos/lib/rossym/Makefile
Added: trunk/reactos/lib/rossym/delete.c
Added: trunk/reactos/lib/rossym/find.c
Added: trunk/reactos/lib/rossym/fromfile.c
Added: trunk/reactos/lib/rossym/frommem.c
Added: trunk/reactos/lib/rossym/fromraw.c
Added: trunk/reactos/lib/rossym/getraw.c
Added: trunk/reactos/lib/rossym/init.c
Added: trunk/reactos/lib/rossym/initkm.c
Added: trunk/reactos/lib/rossym/initum.c
Added: trunk/reactos/lib/rossym/rossympriv.h
Added: trunk/reactos/lib/rossym/zwfile.c
Modified: trunk/reactos/ntoskrnl/Makefile
Modified: trunk/reactos/ntoskrnl/dbg/kdb.h
Deleted: trunk/reactos/ntoskrnl/dbg/kdb_stabs.c
Deleted: trunk/reactos/ntoskrnl/dbg/kdb_stabs.h
Modified: trunk/reactos/ntoskrnl/dbg/kdb_symbols.c
Modified: trunk/reactos/ntoskrnl/dbg/profile.c
Modified: trunk/reactos/ntoskrnl/include/internal/module.h
Modified: trunk/reactos/ntoskrnl/io/driver.c
Modified: trunk/reactos/tools/helper.mk
Modified: trunk/reactos/tools/rsym.c
_____
Modified: trunk/reactos/Makefile
--- trunk/reactos/Makefile 2005-02-02 22:51:23 UTC (rev 13391)
+++ trunk/reactos/Makefile 2005-02-02 23:07:33 UTC (rev 13392)
@@ -42,7 +42,7 @@
LIB_FSLIB = vfatlib
# Static libraries
-LIB_STATIC = string rosrtl epsapi uuid libwine zlib rtl tgetopt pseh
adns dxguid strmiids crt
+LIB_STATIC = string rosrtl epsapi uuid libwine zlib rtl tgetopt pseh
adns dxguid strmiids crt rossym
# Keyboard layout libraries
DLLS_KBD = kbdda kbddv kbdes kbdfr kbdgr kbdse kbduk kbdus
_____
Modified: trunk/reactos/boot/freeldr/freeldr/Makefile
--- trunk/reactos/boot/freeldr/freeldr/Makefile 2005-02-02 22:51:23 UTC
(rev 13391)
+++ trunk/reactos/boot/freeldr/freeldr/Makefile 2005-02-02 23:07:33 UTC
(rev 13392)
@@ -95,7 +95,7 @@
COMPILER_DEFINES = -D__$(TARGET)__ $(COMPILER_DEBUG_DEFINES)
-COMPILER_INCLUDES = -I$(SRCDIR)/include
+COMPILER_INCLUDES = -I$(SRCDIR)/include
-I$(PATH_TO_TOP)/include
CFLAGS = $(COMPILER_OPTIONS) \
$(COMPILER_DEFINES) \
@@ -262,9 +262,9 @@
@echo Make ALL done.
-freeldr.sys : $(ALL_OBJS)
+freeldr.sys : $(ALL_OBJS) $(PATH_TO_TOP)/dk/w32/lib/librossym.a
@echo =====================================================
LINKING $@
- @$(LD) $(LFLAGS) -o freeldr.exe $(F_OBJS)
+ @$(LD) $(LFLAGS) -o freeldr.exe $(F_OBJS)
$(PATH_TO_TOP)/dk/w32/lib/librossym.a
ifeq ($(FULL_MAP),yes)
@$(OBJDUMP) -d -S freeldr.exe > freeldr.map
else
_____
Modified: trunk/reactos/boot/freeldr/freeldr/include/freeldr.h
--- trunk/reactos/boot/freeldr/freeldr/include/freeldr.h
2005-02-02 22:51:23 UTC (rev 13391)
+++ trunk/reactos/boot/freeldr/freeldr/include/freeldr.h
2005-02-02 23:07:33 UTC (rev 13392)
@@ -28,12 +28,18 @@
#define BOOLEAN int
typedef BOOLEAN *PBOOLEAN;
-#define CHAR char
-#define PCHAR char *
-#define UCHAR unsigned char
-#define PUCHAR unsigned char *
-#define WCHAR unsigned short
-#define PWCHAR unsigned short *
+#define CHAR char
+#define PCHAR char *
+#define UCHAR unsigned char
+#define PUCHAR unsigned char *
+#define WCHAR unsigned short
+#define PWCHAR unsigned short *
+#define ULONG unsigned long
+#if defined(_WIN64)
+#define ULONG_PTR __int64
+#else
+#define ULONG_PTR unsigned long
+#endif
#define VOID void
#define PVOID VOID*
_____
Modified: trunk/reactos/boot/freeldr/freeldr/multiboot.c
--- trunk/reactos/boot/freeldr/freeldr/multiboot.c 2005-02-02
22:51:23 UTC (rev 13391)
+++ trunk/reactos/boot/freeldr/freeldr/multiboot.c 2005-02-02
23:07:33 UTC (rev 13392)
@@ -130,44 +130,6 @@
return TRUE;
}
-#if 0
-BOOL MultiBootLoadModule(FILE *ModuleImage, char *ModuleName)
-{
- U32 dwModuleSize;
- module_t* pModule;
- char* ModuleNameString;
- char * TempName;
-
- /*
- * Get current module data structure and module name string
array
- */
- pModule = &multiboot_modules[mb_info.mods_count];
- do {
- TempName = strchr( ModuleName, '\\' );
- if( TempName )
- ModuleName = TempName + 1;
- } while( TempName );
-
- ModuleNameString = multiboot_module_strings[mb_info.mods_count];
-
- dwModuleSize = FsGetFileSize(ModuleImage);
- pModule->mod_start = next_module_load_base;
- pModule->mod_end = next_module_load_base + dwModuleSize;
- strcpy(ModuleNameString, ModuleName);
- pModule->string = (unsigned long)ModuleNameString;
-
- /*
- * Load the file image
- */
- FsReadFile(ModuleImage, dwModuleSize, NULL,
(void*)next_module_load_base);
-
- next_module_load_base = ROUND_UP(pModule->mod_end,
/*PAGE_SIZE*/4096);
- mb_info.mods_count++;
-
- return TRUE;
-}
-#endif
-
PVOID MultiBootLoadModule(FILE *ModuleImage, char *ModuleName, U32*
ModuleSize)
{
U32 dwModuleSize;
_____
Modified: trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
--- trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
2005-02-02 22:51:23 UTC (rev 13391)
+++ trunk/reactos/boot/freeldr/freeldr/reactos/reactos.c
2005-02-02 23:07:33 UTC (rev 13392)
@@ -31,6 +31,8 @@
#include <machine.h>
#include <inifile.h>
+#include <reactos/rossym.h>
+
#include "registry.h"
@@ -85,71 +87,73 @@
return(TRUE);
}
-static BOOL
-LoadSymbolFile(PCHAR szSystemRoot,
- PCHAR ModuleName,
- int nPos)
+static PVOID
+FreeldrAllocMem(ULONG_PTR Size)
{
- CHAR SymbolFileName[1024];
- PFILE FilePointer;
- U32 Length;
- PCHAR Start;
- PCHAR Ext;
- char value[256];
- char *p;
+ return MmAllocateMemory((U32) Size);
+}
- /* Get the path to the symbol store */
- strcpy(SymbolFileName, szSystemRoot);
- strcat(SymbolFileName, "symbols\\");
+static VOID
+FreeldrFreeMem(PVOID Area)
+{
+ MmFreeMemory(Area);
+}
- /* Get the symbol filename from the module name */
- Start = strrchr(ModuleName, '\\');
- if (Start == NULL)
- Start = ModuleName;
- else
- Start++;
+static BOOLEAN
+FreeldrReadFile(PVOID FileContext, PVOID Buffer, ULONG Size)
+{
+ U32 BytesRead;
- Ext = strrchr(ModuleName, '.');
- if (Ext != NULL)
- Length = Ext - Start;
- else
- Length = strlen(Start);
+ return FsReadFile((PFILE) FileContext, (U32) Size, &BytesRead,
Buffer)
+ && Size == BytesRead;
+}
- strncat(SymbolFileName, Start, Length);
- strcat(SymbolFileName, ".sym");
+static BOOLEAN
+FreeldrSeekFile(PVOID FileContext, ULONG_PTR Position)
+{
+ FsSetFilePointer((PFILE) FileContext, (U32) Position);
- FilePointer = FsOpenFile((PCHAR)&SymbolFileName[0]);
+ return TRUE;
+}
+
+static BOOL
+LoadKernelSymbols(PCHAR szKernelName, int nPos)
+{
+ static ROSSYM_CALLBACKS FreeldrCallbacks =
+ {
+ FreeldrAllocMem,
+ FreeldrFreeMem,
+ FreeldrReadFile,
+ FreeldrSeekFile
+ };
+ PFILE FilePointer;
+ PROSSYM_INFO RosSymInfo;
+ U32 Size;
+ PVOID Base;
+
+ RosSymInit(&FreeldrCallbacks);
+
+ FilePointer = FsOpenFile(szKernelName);
if (FilePointer == NULL)
{
- DbgPrint((DPRINT_REACTOS, "Symbol file %s not loaded.\n",
SymbolFileName));
- /* This is not critical */
return FALSE;
}
- DbgPrint((DPRINT_REACTOS, "Symbol file %s is loaded.\n",
SymbolFileName));
+ if (! RosSymCreateFromFile(FilePointer, &RosSymInfo))
+ {
+ return FALSE;
+ }
- /*
- * Update the status bar with the current file
- */
- strcpy(value, "Reading ");
- p = strrchr(SymbolFileName, '\\');
- if (p == NULL)
- strcat(value, SymbolFileName);
- else
- strcat(value, p + 1);
- UiDrawStatusText(value);
+ Base = MultiBootCreateModule("NTOSKRNL.SYM");
+ Size = RosSymGetRawDataLength(RosSymInfo);
+ RosSymGetRawData(RosSymInfo, Base);
+ MultiBootCloseModule(Base, Size);
- /*
- * Load the symbol file
- */
- MultiBootLoadModule(FilePointer, SymbolFileName, NULL);
+ RosSymDelete(RosSymInfo);
- UiDrawProgressBarCenter(nPos, 100, "Loading ReactOS...");
-
- return (TRUE);
+ return TRUE;
}
-
static BOOL
LoadDriver(PCHAR szFileName, int nPos)
{
@@ -366,7 +370,6 @@
nPos += 5;
LoadDriver(ImagePath, nPos);
- LoadSymbolFile(szSystemRoot, ImagePath, nPos);
}
else
{
@@ -446,7 +449,6 @@
nPos += 5;
LoadDriver(ImagePath, nPos);
- LoadSymbolFile(szSystemRoot, ImagePath, nPos);
}
else
{
@@ -880,22 +882,19 @@
UiMessageBox(MsgBuffer);
return;
}
- UiDrawProgressBarCenter(25, 100, "Loading ReactOS...");
+ UiDrawProgressBarCenter(30, 100, "Loading ReactOS...");
/*
- * Load symbol files
+ * Load kernel symbols
*/
- LoadSymbolFile(szBootPath, szKernelName, 30);
- LoadSymbolFile(szBootPath, szHalName, 30);
+ LoadKernelSymbols(szKernelName, 30);
+ UiDrawProgressBarCenter(40, 100, "Loading ReactOS...");
- UiDrawProgressBarCenter(30, 100, "Loading ReactOS...");
-
/*
* Load boot drivers
*/
- LoadBootDrivers(szBootPath, 30);
+ LoadBootDrivers(szBootPath, 40);
-
#if 0
/*
* Clear the screen and redraw the backdrop and status bar
@@ -921,4 +920,12 @@
boot_reactos();
}
+#undef DbgPrint
+ULONG
+DbgPrint(char *Fmt, ...)
+{
+ UiMessageBox(Fmt);
+ return 0;
+}
+
/* EOF */
_____
Modified: trunk/reactos/include/ntdll/ldr.h
--- trunk/reactos/include/ntdll/ldr.h 2005-02-02 22:51:23 UTC (rev
13391)
+++ trunk/reactos/include/ntdll/ldr.h 2005-02-02 23:07:33 UTC (rev
13392)
@@ -1,9 +1,9 @@
#ifndef __NTOSKRNL_INCLUDE_INTERNAL_LDR_H
#define __NTOSKRNL_INCLUDE_INTERNAL_LDR_H
-#include <ntos/kdbgsyms.h>
#include <roscfg.h>
#include <napi/teb.h>
+#include <reactos/rossym.h>
typedef NTSTATUS STDCALL_FUNC (*PEPFUNC)(PPEB);
@@ -69,7 +69,7 @@
ULONG CheckSum;
ULONG TimeDateStamp;
#if defined(DBG) || defined(KDBG)
- IMAGE_SYMBOL_INFO SymbolInfo;
+ PROSSYM_INFO RosSymInfo;
#endif /* KDBG */
} LDR_MODULE, *PLDR_MODULE;
_____
Deleted: trunk/reactos/include/ntos/kdbgsyms.h
--- trunk/reactos/include/ntos/kdbgsyms.h 2005-02-02 22:51:23 UTC
(rev 13391)
+++ trunk/reactos/include/ntos/kdbgsyms.h 2005-02-02 23:07:33 UTC
(rev 13392)
@@ -1,22 +0,0 @@
-#ifndef __KDBGSYMS_H
-#define __KDBGSYMS_H
-
-#include <ddk/ntddk.h>
-
-typedef struct _IMAGE_SYMBOL_INFO
-{
- ULONG_PTR ImageBase;
- ULONG_PTR ImageSize;
- PVOID FileBuffer;
- PVOID StabsBase;
- ULONG StabsLength;
- PVOID StabStringsBase;
- ULONG StabStringsLength;
- PVOID SymbolsBase;
- ULONG SymbolsLength;
- PVOID SymbolStringsBase;
- ULONG SymbolStringsLength;
-} IMAGE_SYMBOL_INFO, *PIMAGE_SYMBOL_INFO;
-
-#endif /* __KDBGSYMS_H */
-
_____
Modified: trunk/reactos/include/ntos.h
--- trunk/reactos/include/ntos.h 2005-02-02 22:51:23 UTC (rev
13391)
+++ trunk/reactos/include/ntos.h 2005-02-02 23:07:33 UTC (rev
13392)
@@ -20,7 +20,6 @@
#include "ntos/gditypes.h"
#include "ntos/fstypes.h" /* AG */
#include "ntos/heap.h"
-#include "ntos/kdbgsyms.h"
#include "ntos/keyboard.h"
#include "ntos/minmax.h"
#include "ntos/mm.h"
@@ -61,7 +60,6 @@
#include "ntos/file.h"
#include "ntos/gditypes.h"
#include "ntos/heap.h"
-#include "ntos/kdbgsyms.h"
#include "ntos/keyboard.h"
#include "ntos/minmax.h"
#include "ntos/mm.h"
_____
Added: trunk/reactos/include/reactos/rossym.h
--- trunk/reactos/include/reactos/rossym.h 2005-02-02 22:51:23 UTC
(rev 13391)
+++ trunk/reactos/include/reactos/rossym.h 2005-02-02 23:07:33 UTC
(rev 13392)
@@ -0,0 +1,59 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: include/reactos/rossym.h
+ * PURPOSE: Handling of rossym symbol info
+ *
+ * PROGRAMMERS: Ge van Geldorp (gvg(a)reactos.com)
+ */
+
+#ifndef REACTOS_ROSSYM_H_INCLUDED
+#define REACTOS_ROSSYM_H_INCLUDED
+
+#define ROSSYM_SECTION_NAME ".rossym"
+
+typedef struct _ROSSYM_HEADER {
+ unsigned long SymbolsOffset;
+ unsigned long SymbolsLength;
+ unsigned long StringsOffset;
+ unsigned long StringsLength;
+} ROSSYM_HEADER, *PROSSYM_HEADER;
+
+typedef struct _ROSSYM_ENTRY {
+ ULONG_PTR Address;
+ ULONG FunctionOffset;
+ ULONG FileOffset;
+ ULONG SourceLine;
+} ROSSYM_ENTRY, *PROSSYM_ENTRY;
+
+typedef struct _ROSSYM_CALLBACKS {
+ PVOID (*AllocMemProc)(ULONG_PTR Size);
+ VOID (*FreeMemProc)(PVOID Area);
+ BOOLEAN (*ReadFileProc)(PVOID FileContext, PVOID Buffer, ULONG Size);
+ BOOLEAN (*SeekFileProc)(PVOID FileContext, ULONG_PTR Position);
+} ROSSYM_CALLBACKS, *PROSSYM_CALLBACKS;
+
+typedef struct _ROSSYM_INFO *PROSSYM_INFO;
+
+VOID RosSymInit(PROSSYM_CALLBACKS Callbacks);
+VOID RosSymInitKernelMode(VOID);
+VOID RosSymInitUserMode(VOID);
+
+BOOLEAN RosSymCreateFromRaw(PVOID RawData, ULONG_PTR DataSize,
+ PROSSYM_INFO *RosSymInfo);
+BOOLEAN RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize,
+ PROSSYM_INFO *RosSymInfo);
+BOOLEAN RosSymCreateFromFile(PVOID FileContext, PROSSYM_INFO
*RosSymInfo);
+ULONG RosSymGetRawDataLength(PROSSYM_INFO RosSymInfo);
+VOID RosSymGetRawData(PROSSYM_INFO RosSymInfo, PVOID RawData);
+BOOLEAN RosSymGetAddressInformation(PROSSYM_INFO RosSymInfo,
+ ULONG_PTR RelativeAddress,
+ ULONG *LineNumber,
+ char *FileName,
+ char *FunctionName);
+VOID RosSymDelete(PROSSYM_INFO RosSymInfo);
+
+#endif /* REACTOS_ROSSYM_H_INCLUDED */
+
+/* EOF */
+
Property changes on: trunk/reactos/include/reactos/rossym.h
___________________________________________________________________
Name: svn:eol-style
+ native
Property changes on: trunk/reactos/lib/rossym
___________________________________________________________________
Name: svn:ignore
+ *.d
*.o
_____
Added: trunk/reactos/lib/rossym/Makefile
--- trunk/reactos/lib/rossym/Makefile 2005-02-02 22:51:23 UTC (rev
13391)
+++ trunk/reactos/lib/rossym/Makefile 2005-02-02 23:07:33 UTC (rev
13392)
@@ -0,0 +1,33 @@
+PATH_TO_TOP = ../..
+
+TARGET_TYPE = library
+
+TARGET_NAME = rossym
+
+include $(PATH_TO_TOP)/config
+
+TARGET_CFLAGS = -Wall -Werror -ffreestanding -D__USE_W32API
+
+TARGET_OBJECTS = \
+ delete.o \
+ find.o \
+ fromfile.o \
+ frommem.o \
+ fromraw.o \
+ getraw.o \
+ init.o \
+ initkm.o \
+ initum.o \
+ zwfile.o
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+DEP_OBJECTS := $(TARGET_OBJECTS)
+
+TARGET_CLEAN = $(DEP_FILES)
+
+include $(PATH_TO_TOP)/tools/depend.mk
+
+# EOF
Property changes on: trunk/reactos/lib/rossym/Makefile
___________________________________________________________________
Name: svn:eol-style
+ native
_____
Added: trunk/reactos/lib/rossym/delete.c
--- trunk/reactos/lib/rossym/delete.c 2005-02-02 22:51:23 UTC (rev
13391)
+++ trunk/reactos/lib/rossym/delete.c 2005-02-02 23:07:33 UTC (rev
13392)
@@ -0,0 +1,24 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: lib/rossym/delete.c
+ * PURPOSE: Free rossym info
+ *
+ * PROGRAMMERS: Ge van Geldorp (gvg(a)reactos.com)
+ */
+
+#define NTOSAPI
+#include <ddk/ntddk.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+VOID
+RosSymDelete(PROSSYM_INFO RosSymInfo)
+{
+ RosSymFreeMem(RosSymInfo);
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/delete.c
___________________________________________________________________
Name: svn:eol-style
+ native
_____
Added: trunk/reactos/lib/rossym/find.c
--- trunk/reactos/lib/rossym/find.c 2005-02-02 22:51:23 UTC (rev
13391)
+++ trunk/reactos/lib/rossym/find.c 2005-02-02 23:07:33 UTC (rev
13392)
@@ -0,0 +1,150 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: lib/rossym/find.c
+ * PURPOSE: Find symbol info for an address
+ *
+ * PROGRAMMERS: Ge van Geldorp (gvg(a)reactos.com)
+ */
+/*
+ * Parts of this file based on work Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights
reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
the
+ * documentation and/or other materials provided with the
distribution.
+ * 4. Neither the name of the University nor the names of its
contributors
+ * may be used to endorse or promote products derived from this
software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF
+ * SUCH DAMAGE.
+ */
+
+#define NTOSAPI
+#include <ddk/ntddk.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+static PROSSYM_ENTRY
+FindEntry(IN PROSSYM_INFO RosSymInfo, IN ULONG_PTR RelativeAddress)
+{
+ /*
+ * Perform a binary search.
+ *
+ * The code below is a bit sneaky. After a comparison fails, we
+ * divide the work in half by moving either left or right. If lim
+ * is odd, moving left simply involves halving lim: e.g., when lim
+ * is 5 we look at item 2, so we change lim to 2 so that we will
+ * look at items 0 & 1. If lim is even, the same applies. If lim
+ * is odd, moving right again involes halving lim, this time moving
+ * the base up one item past p: e.g., when lim is 5 we change base
+ * to item 3 and make lim 2 so that we will look at items 3 and 4.
+ * If lim is even, however, we have to shrink it by one before
+ * halving: e.g., when lim is 4, we still looked at item 2, so we
+ * have to make lim 3, then halve, obtaining 1, so that we will only
+ * look at item 3.
+ */
+ PROSSYM_ENTRY Base = RosSymInfo->Symbols;
+ ULONG Lim;
+ PROSSYM_ENTRY Mid, Low;
+
+ if (RelativeAddress < Base->Address)
+ {
+ return NULL;
+ }
+
+ Low = Base;
+ for (Lim = RosSymInfo->SymbolsCount; Lim != 0; Lim >>= 1)
+ {
+ Mid = Base + (Lim >> 1);
+ if (RelativeAddress == Mid->Address)
+ {
+ return Mid;
+ }
+ if (Mid->Address < RelativeAddress) /* key > mid: move right */
+ {
+ Low = Mid;
+ Base = Mid + 1;
+ Lim--;
+ } /* else move left */
+ }
+
+ return Low;
+}
+
+
+BOOLEAN
+RosSymGetAddressInformation(PROSSYM_INFO RosSymInfo,
+ ULONG_PTR RelativeAddress,
+ ULONG *LineNumber,
+ char *FileName,
+ char *FunctionName)
+{
+ PROSSYM_ENTRY RosSymEntry;
+
+ DPRINT("RelativeAddress = 0x%08x\n", RelativeAddress);
+
+ if (RosSymInfo->Symbols == NULL || RosSymInfo->SymbolsCount == 0 ||
+ RosSymInfo->Strings == NULL || RosSymInfo->StringsLength == 0)
+ {
+__asm__("int $3\n");
+ DPRINT1("Uninitialized RosSymInfo\n");
+ return FALSE;
+ }
+
+ ASSERT(LineNumber || FileName || FunctionName);
+
+ /* find symbol entry for function */
+ RosSymEntry = FindEntry(RosSymInfo, RelativeAddress);
+
+ if (NULL == RosSymEntry)
+ {
+ DPRINT("None of the requested information was found!\n");
+ return FALSE;
+ }
+
+ if (LineNumber != NULL)
+ {
+ *LineNumber = RosSymEntry->SourceLine;
+ }
+ if (FileName != NULL)
+ {
+ PCHAR Name = "";
+ if (RosSymEntry->FileOffset != 0)
+ {
+ Name = (PCHAR) RosSymInfo->Strings + RosSymEntry->FileOffset;
+ }
+ strcpy(FileName, Name);
+ }
+ if (FunctionName != NULL)
+ {
+ PCHAR Name = "";
+ if (RosSymEntry->FunctionOffset != 0)
+ {
+ Name = (PCHAR) RosSymInfo->Strings +
RosSymEntry->FunctionOffset;
+ }
+ strcpy(FunctionName, Name);
+ }
+
+ return TRUE;
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/find.c
___________________________________________________________________
Name: svn:eol-style
+ native
_____
Added: trunk/reactos/lib/rossym/fromfile.c
--- trunk/reactos/lib/rossym/fromfile.c 2005-02-02 22:51:23 UTC (rev
13391)
+++ trunk/reactos/lib/rossym/fromfile.c 2005-02-02 23:07:33 UTC (rev
13392)
@@ -0,0 +1,146 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: lib/rossym/fromfile.c
+ * PURPOSE: Creating rossym info from a file
+ *
+ * PROGRAMMERS: Ge van Geldorp (gvg(a)reactos.com)
+ */
+
+#define NTOSAPI
+#include <ddk/ntddk.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+BOOLEAN
+RosSymCreateFromFile(PVOID FileContext, PROSSYM_INFO *RosSymInfo)
+{
+ IMAGE_DOS_HEADER DosHeader;
+ IMAGE_NT_HEADERS NtHeaders;
+ PIMAGE_SECTION_HEADER SectionHeaders, SectionHeader;
+ unsigned SectionIndex;
+ char SectionName[IMAGE_SIZEOF_SHORT_NAME];
+ ROSSYM_HEADER RosSymHeader;
+
+ /* Load DOS header */
+ if (! RosSymReadFile(FileContext, &DosHeader,
sizeof(IMAGE_DOS_HEADER)))
+ {
+ DPRINT1("Failed to read DOS header\n");
+ return FALSE;
+ }
+ if (! ROSSYM_IS_VALID_DOS_HEADER(&DosHeader))
+ {
+ DPRINT1("Image doesn't have a valid DOS header\n");
+ return FALSE;
+ }
+
+ /* Load NT headers */
+ if (! RosSymSeekFile(FileContext, DosHeader.e_lfanew))
+ {
+ DPRINT1("Failed seeking to NT headers\n");
+ return FALSE;
+ }
+ if (! RosSymReadFile(FileContext, &NtHeaders,
sizeof(IMAGE_NT_HEADERS)))
+ {
+ DPRINT1("Failed to read NT headers\n");
+ return FALSE;
+ }
+ if (! ROSSYM_IS_VALID_NT_HEADERS(&NtHeaders))
+ {
+ DPRINT1("Image doesn't have a valid PE header\n");
+ return FALSE;
+ }
+
+ /* Load section headers */
+ if (! RosSymSeekFile(FileContext, (char *)
IMAGE_FIRST_SECTION(&NtHeaders) -
+ (char *) &NtHeaders +
DosHeader.e_lfanew))
+ {
+ DPRINT1("Failed seeking to section headers\n");
+ return FALSE;
+ }
+ SectionHeaders = RosSymAllocMem(NtHeaders.FileHeader.NumberOfSections
+ * sizeof(IMAGE_SECTION_HEADER));
+ if (NULL == SectionHeaders)
+ {
+ DPRINT1("Failed to allocate memory for %u section headers\n",
+ NtHeaders.FileHeader.NumberOfSections);
+ return FALSE;
+ }
+ if (! RosSymReadFile(FileContext, SectionHeaders,
+ NtHeaders.FileHeader.NumberOfSections
+ * sizeof(IMAGE_SECTION_HEADER)))
+ {
+ RosSymFreeMem(SectionHeaders);
+ DPRINT1("Failed to read section headers\n");
+ return FALSE;
+ }
+
+ /* Search for the section header */
+ strncpy(SectionName, ROSSYM_SECTION_NAME, IMAGE_SIZEOF_SHORT_NAME);
+ SectionHeader = SectionHeaders;
+ for (SectionIndex = 0; SectionIndex <
NtHeaders.FileHeader.NumberOfSections; SectionIndex++)
+ {
+ if (0 == memcmp(SectionName, SectionHeader->Name,
IMAGE_SIZEOF_SHORT_NAME))
+ {
+ break;
+ }
+ SectionHeader++;
+ }
+ if (NtHeaders.FileHeader.NumberOfSections <= SectionIndex)
+ {
+ RosSymFreeMem(SectionHeaders);
+ DPRINT("No %s section found\n", ROSSYM_SECTION_NAME);
+ return FALSE;
+ }
+
+ /* Load rossym header */
+ if (! RosSymSeekFile(FileContext, SectionHeader->PointerToRawData))
+ {
+ RosSymFreeMem(SectionHeaders);
+ DPRINT1("Failed seeking to section data\n");
+ return FALSE;
+ }
+ RosSymFreeMem(SectionHeaders);
+ if (! RosSymReadFile(FileContext, &RosSymHeader,
sizeof(ROSSYM_HEADER)))
+ {
+ DPRINT1("Failed to read rossym header\n");
+ return FALSE;
+ }
+ if (RosSymHeader.SymbolsOffset < sizeof(ROSSYM_HEADER)
+ || RosSymHeader.StringsOffset < RosSymHeader.SymbolsOffset +
RosSymHeader.SymbolsLength
+ || 0 != (RosSymHeader.SymbolsLength % sizeof(ROSSYM_ENTRY)))
+ {
+ DPRINT1("Invalid ROSSYM_HEADER\n");
+ return FALSE;
+ }
+
+ *RosSymInfo = RosSymAllocMem(sizeof(ROSSYM_INFO) -
sizeof(ROSSYM_HEADER)
+ + RosSymHeader.StringsOffset +
RosSymHeader.StringsLength + 1);
+ if (NULL == *RosSymInfo)
+ {
+ DPRINT1("Failed to allocate memory for rossym\n");
+ return FALSE;
+ }
+ (*RosSymInfo)->Symbols = (PROSSYM_ENTRY)((char *) *RosSymInfo +
sizeof(ROSSYM_INFO)
+ - sizeof(ROSSYM_HEADER) +
RosSymHeader.SymbolsOffset);
+ (*RosSymInfo)->SymbolsCount = RosSymHeader.SymbolsLength /
sizeof(ROSSYM_ENTRY);
+ (*RosSymInfo)->Strings = (PCHAR) *RosSymInfo + sizeof(ROSSYM_INFO) -
sizeof(ROSSYM_HEADER)
+ + RosSymHeader.StringsOffset;
+ (*RosSymInfo)->StringsLength = RosSymHeader.StringsLength;
+ if (! RosSymReadFile(FileContext, *RosSymInfo + 1,
+ RosSymHeader.StringsOffset +
RosSymHeader.StringsLength
+ - sizeof(ROSSYM_HEADER)))
+ {
+ DPRINT1("Failed to read rossym headers\n");
+ return FALSE;
+ }
+ /* Make sure the last string is null terminated, we allocated an
extra byte for that */
+ (*RosSymInfo)->Strings[(*RosSymInfo)->StringsLength] = '\0';
+
+ return TRUE;
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/fromfile.c
___________________________________________________________________
Name: svn:eol-style
+ native
_____
Added: trunk/reactos/lib/rossym/frommem.c
--- trunk/reactos/lib/rossym/frommem.c 2005-02-02 22:51:23 UTC (rev
13391)
+++ trunk/reactos/lib/rossym/frommem.c 2005-02-02 23:07:33 UTC (rev
13392)
@@ -0,0 +1,81 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: lib/rossym/frommem.c
+ * PURPOSE: Creating rossym info from an in-memory image
+ *
+ * PROGRAMMERS: Ge van Geldorp (gvg(a)reactos.com)
+ */
+
+#define NTOSAPI
+#include <ddk/ntddk.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+BOOLEAN
+RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO
*RosSymInfo)
+{
+ PIMAGE_DOS_HEADER DosHeader;
+ PIMAGE_NT_HEADERS NtHeaders;
+ PIMAGE_SECTION_HEADER SectionHeader;
+ unsigned SectionIndex;
+ char SectionName[IMAGE_SIZEOF_SHORT_NAME];
+
+ /* Check if MZ header is valid */
+ DosHeader = (PIMAGE_DOS_HEADER) ImageStart;
+ if (ImageSize < sizeof(IMAGE_DOS_HEADER)
+ || ! ROSSYM_IS_VALID_DOS_HEADER(DosHeader))
+ {
+ DPRINT1("Image doesn't have a valid DOS header\n");
+ return FALSE;
+ }
+
+ /* Locate NT header */
+ NtHeaders = (PIMAGE_NT_HEADERS)((char *) ImageStart +
DosHeader->e_lfanew);
+ if (ImageSize < DosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS)
+ || ! ROSSYM_IS_VALID_NT_HEADERS(NtHeaders))
+ {
+ DPRINT1("Image doesn't have a valid PE header\n");
+ return FALSE;
+ }
+
+ /* Search for the section header */
+ SectionHeader = IMAGE_FIRST_SECTION(NtHeaders);
+ if (ImageSize < (char *) (SectionHeader +
NtHeaders->FileHeader.NumberOfSections)
+ - (char *) ImageStart)
+ {
+ DPRINT1("Image doesn't have valid section headers\n");
+ return FALSE;
+ }
+ strncpy(SectionName, ROSSYM_SECTION_NAME, IMAGE_SIZEOF_SHORT_NAME);
+ for (SectionIndex = 0; SectionIndex <
NtHeaders->FileHeader.NumberOfSections; SectionIndex++)
+ {
+ if (0 == memcmp(SectionName, SectionHeader->Name,
IMAGE_SIZEOF_SHORT_NAME))
+ {
+ break;
+ }
+ SectionHeader++;
+ }
+ if (NtHeaders->FileHeader.NumberOfSections <= SectionIndex)
+ {
+ DPRINT("No %s section found\n", ROSSYM_SECTION_NAME);
+ return FALSE;
+ }
+
+ /* Locate the section itself */
+ if (ImageSize < SectionHeader->PointerToRawData +
SectionHeader->SizeOfRawData
+ || SectionHeader->SizeOfRawData < sizeof(ROSSYM_HEADER))
+ {
+ DPRINT1("Invalid %s section\n", ROSSYM_SECTION_NAME);
+ return FALSE;
+ }
+
+ /* Load it */
+ return RosSymCreateFromRaw((char *) ImageStart +
SectionHeader->PointerToRawData,
+ SectionHeader->SizeOfRawData, RosSymInfo);
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/frommem.c
___________________________________________________________________
Name: svn:eol-style
+ native
_____
Added: trunk/reactos/lib/rossym/fromraw.c
--- trunk/reactos/lib/rossym/fromraw.c 2005-02-02 22:51:23 UTC (rev
13391)
+++ trunk/reactos/lib/rossym/fromraw.c 2005-02-02 23:07:33 UTC (rev
13392)
@@ -0,0 +1,55 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: lib/rossym/frommem.c
+ * PURPOSE: Creating rossym info from an in-memory image
+ *
+ * PROGRAMMERS: Ge van Geldorp (gvg(a)reactos.com)
+ */
+
+#define NTOSAPI
+#include <ddk/ntddk.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+BOOLEAN
+RosSymCreateFromRaw(PVOID RawData, ULONG_PTR DataSize, PROSSYM_INFO
*RosSymInfo)
+{
+ PROSSYM_HEADER RosSymHeader;
+
+ RosSymHeader = (PROSSYM_HEADER) RawData;
+ if (RosSymHeader->SymbolsOffset < sizeof(ROSSYM_HEADER)
+ || RosSymHeader->StringsOffset < RosSymHeader->SymbolsOffset +
RosSymHeader->SymbolsLength
+ || DataSize < RosSymHeader->StringsOffset +
RosSymHeader->StringsLength
+ || 0 != (RosSymHeader->SymbolsLength % sizeof(ROSSYM_ENTRY)))
+ {
+ DPRINT1("Invalid ROSSYM_HEADER\n");
+ return FALSE;
+ }
+
+ /* Copy */
+ *RosSymInfo = RosSymAllocMem(sizeof(ROSSYM_INFO) +
RosSymHeader->SymbolsLength
+ + RosSymHeader->StringsLength + 1);
+ if (NULL == *RosSymInfo)
+ {
+ DPRINT1("Failed to allocate memory for rossym\n");
+ return FALSE;
+ }
+ (*RosSymInfo)->Symbols = (PROSSYM_ENTRY)((char *) *RosSymInfo +
sizeof(ROSSYM_INFO));
+ (*RosSymInfo)->SymbolsCount = RosSymHeader->SymbolsLength /
sizeof(ROSSYM_ENTRY);
+ (*RosSymInfo)->Strings = (PCHAR) *RosSymInfo + sizeof(ROSSYM_INFO) +
RosSymHeader->SymbolsLength;
+ (*RosSymInfo)->StringsLength = RosSymHeader->StringsLength;
+ memcpy((*RosSymInfo)->Symbols, (char *) RosSymHeader +
RosSymHeader->SymbolsOffset,
+ RosSymHeader->SymbolsLength);
+ memcpy((*RosSymInfo)->Strings, (char *) RosSymHeader +
RosSymHeader->StringsOffset,
+ RosSymHeader->StringsLength);
+ /* Make sure the last string is null terminated, we allocated an
extra byte for that */
+ (*RosSymInfo)->Strings[(*RosSymInfo)->StringsLength] = '\0';
+
+ return TRUE;
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/fromraw.c
___________________________________________________________________
Name: svn:eol-style
+ native
_____
Added: trunk/reactos/lib/rossym/getraw.c
--- trunk/reactos/lib/rossym/getraw.c 2005-02-02 22:51:23 UTC (rev
13391)
+++ trunk/reactos/lib/rossym/getraw.c 2005-02-02 23:07:33 UTC (rev
13392)
[truncated at 1000 lines; 3233 more skipped]