rossym is ReactOS-specific
Modified: trunk/reactos/ReactOS.rbuild
Added: trunk/reactos/include/reactos/rossym.h
Added: trunk/reactos/lib/directory.rbuild
Added: trunk/reactos/lib/rossym/
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/rossym.rbuild
Added: trunk/reactos/lib/rossym/rossympriv.h
Added: trunk/reactos/lib/rossym/zwfile.c

Modified: trunk/reactos/ReactOS.rbuild
--- trunk/reactos/ReactOS.rbuild	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/ReactOS.rbuild	2006-01-30 20:01:34 UTC (rev 53)
@@ -42,7 +42,7 @@
 	<include>w32api/include/crt</include>
 	<include>w32api/include/ddk</include>
 
-<!--
+<!-- TODO
 	<directory name="apps">
 		<xi:include href="apps/directory.rbuild" />
 	</directory>
@@ -56,7 +56,7 @@
 	<directory name="base">
 		<xi:include href="base/base.rbuild" />
 	</directory>
-<!--
+<!-- TODO
 	<directory name="dll">
 		<xi:include href="dll/dll.rbuild" />
 	</directory>
@@ -69,9 +69,11 @@
 	<directory name="include">
 		<xi:include href="include/directory.rbuild" />
 	</directory>
+-->
 	<directory name="lib">
 		<xi:include href="lib/directory.rbuild" />
 	</directory>
+<!-- TODO
 	<directory name="media">
 		<xi:include href="media/directory.rbuild" />
 	</directory>

Added: trunk/reactos/include/reactos/rossym.h
--- trunk/reactos/include/reactos/rossym.h	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/include/reactos/rossym.h	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,58 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        include/reactos/rossym.h
+ * PURPOSE:     Handling of rossym symbol info
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#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:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/directory.rbuild
--- trunk/reactos/lib/directory.rbuild	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/directory.rbuild	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,5 @@
+<group>
+<directory name="rossym">
+        <xi:include href="rossym/rossym.rbuild" />
+</directory>
+</group>
Property changes on: trunk/reactos/lib/directory.rbuild
___________________________________________________________________
Name: svn:eol-style
   + native
Property changes on: trunk/reactos/lib/rossym
___________________________________________________________________
Name: ros:history
   + ------------------------------------------------------------------------
r19810 | sedwards | 2005-12-01 22:37:19 +0100 (Thu, 01 Dec 2005) | 1 line
stop the abuse of having the ddk directory in the path when including a ddk header
------------------------------------------------------------------------
r19144 | weiden | 2005-11-11 20:59:38 +0100 (Fri, 11 Nov 2005) | 1 line
fixed some more warnings when compiled with -Wwrite-strings
------------------------------------------------------------------------
r16720 | mf | 2005-07-24 23:42:00 +0200 (Sun, 24 Jul 2005) | 1 line
set eol-style for most xml files
------------------------------------------------------------------------
r16441 | weiden | 2005-07-06 00:35:29 +0200 (Wed, 06 Jul 2005) | 1 line
fixed some signed/unsigned comparison warnings with -Wsign-compare
------------------------------------------------------------------------
r16238 | ion | 2005-06-23 06:53:57 +0200 (Thu, 23 Jun 2005) | 1 line
use DDK for rossym
------------------------------------------------------------------------
r16079 | ion | 2005-06-19 09:15:07 +0200 (Sun, 19 Jun 2005) | 1 line
Fix rtl/rossym
------------------------------------------------------------------------
r15767 | mf | 2005-06-04 11:58:35 +0200 (Sat, 04 Jun 2005) | 1 line
svn:ignore generated files
------------------------------------------------------------------------
r15583 | chorns | 2005-05-28 17:18:30 +0200 (Sat, 28 May 2005) | 1 line
Merge 12735:15568 from xmlbuildsystem branch
------------------------------------------------------------------------
r13392 | gvg | 2005-02-03 00:07:33 +0100 (Thu, 03 Feb 2005) | 3 lines
Store symbolic information in a .rossym section in the
executable/library/driver/whatever
------------------------------------------------------------------------
Name: ros:doc
   + We store the symbolic information in a way completely different from Windows.
There is no equivalent to this lib in Windows.

Added: trunk/reactos/lib/rossym/delete.c
--- trunk/reactos/lib/rossym/delete.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/delete.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,23 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/delete.c
+ * PURPOSE:     Free rossym info
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#define NTOSAPI
+#include <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:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/find.c
--- trunk/reactos/lib/rossym/find.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/find.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,150 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/find.c
+ * PURPOSE:     Find symbol info for an address
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+/*
+ * 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 <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)
+    {
+      PCSTR Name = "";
+      if (RosSymEntry->FileOffset != 0)
+        {
+          Name = (PCHAR) RosSymInfo->Strings + RosSymEntry->FileOffset;
+        }
+      strcpy(FileName, Name);
+    }
+  if (FunctionName != NULL)
+    {
+      PCSTR 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:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/fromfile.c
--- trunk/reactos/lib/rossym/fromfile.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/fromfile.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,145 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/fromfile.c
+ * PURPOSE:     Creating rossym info from a file
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#define NTOSAPI
+#include <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:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/frommem.c
--- trunk/reactos/lib/rossym/frommem.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/frommem.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,80 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/frommem.c
+ * PURPOSE:     Creating rossym info from an in-memory image
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#define NTOSAPI
+#include <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 < (ULONG_PTR)((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:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/fromraw.c
--- trunk/reactos/lib/rossym/fromraw.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/fromraw.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,54 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/frommem.c
+ * PURPOSE:     Creating rossym info from an in-memory image
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#define NTOSAPI
+#include <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:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/getraw.c
--- trunk/reactos/lib/rossym/getraw.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/getraw.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,42 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/getraw.c
+ * PURPOSE:     Convert rossym info to raw external format
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#define NTOSAPI
+#include <ntddk.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+ULONG
+RosSymGetRawDataLength(PROSSYM_INFO RosSymInfo)
+{
+  return sizeof(ROSSYM_HEADER)
+         + RosSymInfo->SymbolsCount * sizeof(ROSSYM_ENTRY)
+         + RosSymInfo->StringsLength;
+}
+
+VOID
+RosSymGetRawData(PROSSYM_INFO RosSymInfo, PVOID RawData)
+{
+  PROSSYM_HEADER RosSymHeader;
+
+  RosSymHeader = (PROSSYM_HEADER) RawData;
+  RosSymHeader->SymbolsOffset = sizeof(ROSSYM_HEADER);
+  RosSymHeader->SymbolsLength = RosSymInfo->SymbolsCount * sizeof(ROSSYM_ENTRY);
+  RosSymHeader->StringsOffset = RosSymHeader->SymbolsOffset + RosSymHeader->SymbolsLength;
+  RosSymHeader->StringsLength = RosSymInfo->StringsLength;
+
+  memcpy((char *) RawData + RosSymHeader->SymbolsOffset, RosSymInfo->Symbols,
+         RosSymHeader->SymbolsLength);
+  memcpy((char *) RawData + RosSymHeader->StringsOffset, RosSymInfo->Strings,
+         RosSymHeader->StringsLength);
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/getraw.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/init.c
--- trunk/reactos/lib/rossym/init.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/init.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,21 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/data.c
+ * PURPOSE:     Definition of external variables
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#include <windows.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+ROSSYM_CALLBACKS RosSymCallbacks;
+
+VOID
+RosSymInit(PROSSYM_CALLBACKS Callbacks)
+{
+  RosSymCallbacks = *Callbacks;
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/init.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/initkm.c
--- trunk/reactos/lib/rossym/initkm.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/initkm.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,46 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/initkm.c
+ * PURPOSE:     Initialize library for use in kernel mode
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#define NTOSAPI
+#include <ntddk.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+#define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
+#define TAG_ROSSYM TAG('R', 'S', 'Y', 'M')
+
+static PVOID
+RosSymAllocMemKM(ULONG_PTR Size)
+{
+  return ExAllocatePoolWithTag(NonPagedPool, Size, TAG_ROSSYM);
+}
+
+static VOID
+RosSymFreeMemKM(PVOID Area)
+{
+  return ExFreePool(Area);
+}
+
+VOID
+RosSymInitKernelMode(VOID)
+{
+  static ROSSYM_CALLBACKS KmCallbacks =
+    {
+      RosSymAllocMemKM,
+      RosSymFreeMemKM,
+      RosSymZwReadFile,
+      RosSymZwSeekFile
+    };
+
+  RosSymInit(&KmCallbacks);
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/initkm.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/initum.c
--- trunk/reactos/lib/rossym/initum.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/initum.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,42 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/initum.c
+ * PURPOSE:     Initialize library for use in user mode
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#include <windows.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+static PVOID
+RosSymAllocMemUM(ULONG_PTR Size)
+{
+  return HeapAlloc(GetProcessHeap(), 0, Size);
+}
+
+static VOID
+RosSymFreeMemUM(PVOID Area)
+{
+  HeapFree(GetProcessHeap(), 0, Area);
+}
+
+VOID
+RosSymInitUserMode(VOID)
+{
+  static ROSSYM_CALLBACKS KmCallbacks =
+    {
+      RosSymAllocMemUM,
+      RosSymFreeMemUM,
+      RosSymZwReadFile,
+      RosSymZwSeekFile
+    };
+
+  RosSymInit(&KmCallbacks);
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/initum.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/rossym.rbuild
--- trunk/reactos/lib/rossym/rossym.rbuild	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/rossym.rbuild	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,14 @@
+<module name="rossym" type="staticlibrary">
+	<define name="__USE_W32API" />
+	<include base="ReactOS">include/ddk</include>
+	<file>delete.c</file>
+	<file>find.c</file>
+	<file>fromfile.c</file>
+	<file>frommem.c</file>
+	<file>fromraw.c</file>
+	<file>getraw.c</file>
+	<file>init.c</file>
+	<file>initkm.c</file>
+	<file>initum.c</file>
+	<file>zwfile.c</file>
+</module>
Property changes on: trunk/reactos/lib/rossym/rossym.rbuild
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/rossympriv.h
--- trunk/reactos/lib/rossym/rossympriv.h	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/rossympriv.h	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,38 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/rossympriv.h
+ * PURPOSE:     Private header for rossym
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#ifndef ROSSYMPRIV_H_INCLUDED
+#define ROSSYMPRIV_H_INCLUDED
+
+typedef struct _ROSSYM_INFO {
+  PROSSYM_ENTRY Symbols;
+  ULONG SymbolsCount;
+  PCHAR Strings;
+  ULONG StringsLength;
+} ROSSYM_INFO;
+
+extern ROSSYM_CALLBACKS RosSymCallbacks;
+
+#define RosSymAllocMem(Size) (*RosSymCallbacks.AllocMemProc)(Size)
+#define RosSymFreeMem(Area) (*RosSymCallbacks.FreeMemProc)(Area)
+#define RosSymReadFile(FileContext, Buffer, Size) (*RosSymCallbacks.ReadFileProc)((FileContext), (Buffer), (Size))
+#define RosSymSeekFile(FileContext, Position) (*RosSymCallbacks.SeekFileProc)((FileContext), (Position))
+
+extern BOOLEAN RosSymZwReadFile(PVOID FileContext, PVOID Buffer, ULONG Size);
+extern BOOLEAN RosSymZwSeekFile(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 \
+                                               && IMAGE_NT_OPTIONAL_HDR_MAGIC == (NtHeaders)->OptionalHeader.Magic)
+
+
+#endif /* ROSSYMPRIV_H_INCLUDED */
+
+/* EOF */
+
Property changes on: trunk/reactos/lib/rossym/rossympriv.h
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/reactos/lib/rossym/zwfile.c
--- trunk/reactos/lib/rossym/zwfile.c	2006-01-30 19:45:40 UTC (rev 52)
+++ trunk/reactos/lib/rossym/zwfile.c	2006-01-30 20:01:34 UTC (rev 53)
@@ -0,0 +1,51 @@
+/*
+ * PROJECT:     ReactOS Kernel
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        lib/rossym/zwfile.c
+ * PURPOSE:     File I/O using native functions
+ * COPYRIGHT:   Ge van Geldorp (gvg@reactos.org)
+ */
+
+#define NTOSAPI
+#include <ntddk.h>
+#include <reactos/rossym.h>
+#include "rossympriv.h"
+
+#define NDEBUG
+#include <debug.h>
+
+BOOLEAN
+RosSymZwReadFile(PVOID FileContext, PVOID Buffer, ULONG Size)
+{
+  NTSTATUS Status;
+  IO_STATUS_BLOCK IoStatusBlock;
+
+  Status = ZwReadFile(*((HANDLE *) FileContext),
+                      0, 0, 0,
+                      &IoStatusBlock,
+                      Buffer,
+                      Size,
+                      0, 0);
+
+  return NT_SUCCESS(Status) && IoStatusBlock.Information == Size;
+}
+
+BOOLEAN
+RosSymZwSeekFile(PVOID FileContext, ULONG_PTR Position)
+{
+  NTSTATUS Status;
+  IO_STATUS_BLOCK IoStatusBlock;
+  FILE_POSITION_INFORMATION NewPosition;
+
+  NewPosition.CurrentByteOffset.u.HighPart = 0;
+  NewPosition.CurrentByteOffset.u.LowPart = Position;
+  Status = ZwSetInformationFile(*((HANDLE *) FileContext),
+                                &IoStatusBlock,
+                                (PVOID) &NewPosition,
+                                sizeof(FILE_POSITION_INFORMATION),
+                                FilePositionInformation);
+
+  return NT_SUCCESS(Status);
+}
+
+/* EOF */
Property changes on: trunk/reactos/lib/rossym/zwfile.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native