Author: tkreuzer Date: Mon Oct 3 18:03:18 2011 New Revision: 53967
URL: http://svn.reactos.org/svn/reactos?rev=53967&view=rev Log: [FREELDR] - Clean up some headers - Add DPRINT_HEAP debug channel mask - Make ExAllocatePool a function instead of a macro - Add a cleanup function to the new heap code
Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/pc/pcbios.h trunk/reactos/boot/freeldr/freeldr/include/debug.h trunk/reactos/boot/freeldr/freeldr/include/freeldr.h trunk/reactos/boot/freeldr/freeldr/include/mm.h trunk/reactos/boot/freeldr/freeldr/include/winldr.h trunk/reactos/boot/freeldr/freeldr/mm/heap.c trunk/reactos/boot/freeldr/freeldr/mm/heap_new.c
Modified: trunk/reactos/boot/freeldr/freeldr/include/arch/pc/pcbios.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/arch/pc/pcbios.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/arch/pc/pcbios.h [iso-8859-1] Mon Oct 3 18:03:18 2011 @@ -1,4 +1,28 @@ #ifndef __ASM__ + +typedef enum +{ + BiosMemoryUsable=1, + BiosMemoryReserved, + BiosMemoryAcpiReclaim, + BiosMemoryAcpiNvs +} BIOS_MEMORY_TYPE; + +typedef struct +{ + ULONGLONG BaseAddress; + ULONGLONG Length; + ULONG Type; + ULONG Reserved; +} BIOS_MEMORY_MAP, *PBIOS_MEMORY_MAP; + +/* FIXME: Should be moved to NDK, and respective ACPI header files */ +typedef struct _ACPI_BIOS_DATA +{ + PHYSICAL_ADDRESS RSDTAddress; + ULONGLONG Count; + BIOS_MEMORY_MAP MemoryMap[1]; /* Count of BIOS memory map entries */ +} ACPI_BIOS_DATA, *PACPI_BIOS_DATA;
#include <pshpack1.h> typedef struct
Modified: trunk/reactos/boot/freeldr/freeldr/include/debug.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/debug.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/debug.h [iso-8859-1] Mon Oct 3 18:03:18 2011 @@ -20,21 +20,23 @@ #ifndef __DEBUG_H #define __DEBUG_H
+// OR this with DebugPrintMask to enable ... #define DPRINT_NONE 0x00000000 // No debug print -#define DPRINT_WARNING 0x00000001 // OR this with DebugPrintMask to enable debugger messages and other misc stuff -#define DPRINT_MEMORY 0x00000002 // OR this with DebugPrintMask to enable memory management messages -#define DPRINT_FILESYSTEM 0x00000004 // OR this with DebugPrintMask to enable file system messages -#define DPRINT_INIFILE 0x00000008 // OR this with DebugPrintMask to enable .ini file messages -#define DPRINT_UI 0x00000010 // OR this with DebugPrintMask to enable user interface messages -#define DPRINT_DISK 0x00000020 // OR this with DebugPrintMask to enable disk messages -#define DPRINT_CACHE 0x00000040 // OR this with DebugPrintMask to enable cache messages -#define DPRINT_REGISTRY 0x00000080 // OR this with DebugPrintMask to enable registry messages -#define DPRINT_REACTOS 0x00000100 // OR this with DebugPrintMask to enable ReactOS messages -#define DPRINT_LINUX 0x00000200 // OR this with DebugPrintMask to enable Linux messages -#define DPRINT_HWDETECT 0x00000400 // OR this with DebugPrintMask to enable hardware detection messages -#define DPRINT_WINDOWS 0x00000800 // OR this with DebugPrintMask to enable messages from Windows loader -#define DPRINT_PELOADER 0x00001000 // OR this with DebugPrintMask to enable messages from PE images loader -#define DPRINT_SCSIPORT 0x00002000 // OR this with DebugPrintMask to enable messages from SCSI miniport +#define DPRINT_WARNING 0x00000001 // debugger messages and other misc stuff +#define DPRINT_MEMORY 0x00000002 // memory management messages +#define DPRINT_FILESYSTEM 0x00000004 // file system messages +#define DPRINT_INIFILE 0x00000008 // .ini file messages +#define DPRINT_UI 0x00000010 // user interface messages +#define DPRINT_DISK 0x00000020 // disk messages +#define DPRINT_CACHE 0x00000040 // cache messages +#define DPRINT_REGISTRY 0x00000080 // registry messages +#define DPRINT_REACTOS 0x00000100 // ReactOS messages +#define DPRINT_LINUX 0x00000200 // Linux messages +#define DPRINT_HWDETECT 0x00000400 // hardware detection messages +#define DPRINT_WINDOWS 0x00000800 // messages from Windows loader +#define DPRINT_PELOADER 0x00001000 // messages from PE images loader +#define DPRINT_SCSIPORT 0x00002000 // messages from SCSI miniport +#define DPRINT_HEAP 0x00004000 // messages in a bottle
#if DBG && !defined(_M_ARM)
Modified: trunk/reactos/boot/freeldr/freeldr/include/freeldr.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/freeldr.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/freeldr.h [iso-8859-1] Mon Oct 3 18:03:18 2011 @@ -96,9 +96,9 @@ /* arch specific includes */ #if defined(_M_IX86) || defined(_M_AMD64) #include <arch/pc/hardware.h> +#include <arch/pc/pcbios.h> #include <arch/pc/machpc.h> #include <arch/pc/x86common.h> -#include <arch/pc/pcbios.h> #include <arch/pc/pxe.h> #endif #if defined(_M_IX86)
Modified: trunk/reactos/boot/freeldr/freeldr/include/mm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/mm.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/mm.h [iso-8859-1] Mon Oct 3 18:03:18 2011 @@ -19,14 +19,6 @@
#pragma once
-typedef enum -{ - BiosMemoryUsable=1, - BiosMemoryReserved, - BiosMemoryAcpiReclaim, - BiosMemoryAcpiNvs -} BIOS_MEMORY_TYPE; - typedef struct _FREELDR_MEMORY_DESCRIPTOR { TYPE_OF_MEMORY MemoryType; @@ -34,15 +26,6 @@ PFN_NUMBER PageCount; } FREELDR_MEMORY_DESCRIPTOR, *PFREELDR_MEMORY_DESCRIPTOR;
-#include <pshpack1.h> -typedef struct -{ - ULONGLONG BaseAddress; - ULONGLONG Length; - ULONG Type; - ULONG Reserved; -} BIOS_MEMORY_MAP, *PBIOS_MEMORY_MAP; -#include <poppack.h>
#if defined(__i386__) || defined(_PPC_) || defined(_MIPS_) || defined(_ARM_)
@@ -88,12 +71,10 @@ // #define DUMP_MEM_MAP_ON_VERIFY 0
- - -extern PVOID PageLookupTableAddress; -extern ULONG TotalPagesInLookupTable; -extern ULONG FreePagesInLookupTable; -extern ULONG LastFreePageHint; +extern PVOID PageLookupTableAddress; +extern ULONG TotalPagesInLookupTable; +extern ULONG FreePagesInLookupTable; +extern ULONG LastFreePageHint;
#if DBG PCSTR MmGetSystemMemoryMapTypeString(TYPE_OF_MEMORY Type); @@ -127,6 +108,35 @@ PVOID MmHeapAlloc(SIZE_T MemorySize); VOID MmHeapFree(PVOID MemoryPointer);
-#define ExAllocatePool(pool, size) MmHeapAlloc(size) -#define ExAllocatePoolWithTag(pool, size, tag) MmHeapAlloc(size) -#define ExFreePool(p) MmHeapFree(p) +/* Heap */ +extern PVOID FrLdrDefaultHeap; +extern PVOID FrLdrTempHeap; + +PVOID +HeapCreate( + ULONG MaximumSize, + TYPE_OF_MEMORY MemoryType); + +VOID +HeapDestroy( + PVOID HeapHandle); + +VOID +HeapRelease( + PVOID HeapHandle); + +VOID +HeapCleanupAll(VOID); + +PVOID +HeapAllocate( + PVOID HeapHandle, + SIZE_T ByteSize, + ULONG Tag); + +VOID +HeapFree( + PVOID HeapHandle, + PVOID Pointer, + ULONG Tag); +
Modified: trunk/reactos/boot/freeldr/freeldr/include/winldr.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/includ... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/include/winldr.h [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/include/winldr.h [iso-8859-1] Mon Oct 3 18:03:18 2011 @@ -32,14 +32,6 @@ // Descriptors #define NUM_GDT 128 // Must be 128 #define NUM_IDT 0x100 // only 16 are used though. Must be 0x100 - -/* FIXME: Should be moved to NDK, and respective ACPI header files */ -typedef struct _ACPI_BIOS_DATA -{ - PHYSICAL_ADDRESS RSDTAddress; - ULONGLONG Count; - BIOS_MEMORY_MAP MemoryMap[1]; /* Count of BIOS memory map entries */ -} ACPI_BIOS_DATA, *PACPI_BIOS_DATA;
#include <pshpack1.h> typedef struct /* Root System Descriptor Pointer */
Modified: trunk/reactos/boot/freeldr/freeldr/mm/heap.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/hea... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/mm/heap.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/mm/heap.c [iso-8859-1] Mon Oct 3 18:03:18 2011 @@ -88,6 +88,14 @@ }
+PVOID +NTAPI +ExAllocatePool( + IN POOL_TYPE PoolType, + IN SIZE_T NumberOfBytes) +{ + return MmHeapAlloc(NumberOfBytes); +}
#undef ExAllocatePoolWithTag PVOID
Modified: trunk/reactos/boot/freeldr/freeldr/mm/heap_new.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/hea... ============================================================================== --- trunk/reactos/boot/freeldr/freeldr/mm/heap_new.c [iso-8859-1] (original) +++ trunk/reactos/boot/freeldr/freeldr/mm/heap_new.c [iso-8859-1] Mon Oct 3 18:03:18 2011 @@ -1,6 +1,6 @@ /* * FreeLoader - * Copyright (C) 2011 Timo Kreuzer (timo.kreuzer@reactos.orh) + * Copyright (C) 2011 Timo Kreuzer (timo.kreuzer@reactos.org) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,6 +22,9 @@
DBG_DEFAULT_CHANNEL(HEAP);
+#define DEFAULT_HEAP_SIZE (1024 * 1024) +#define TEMP_HEAP_SIZE (1024 * 1024) + PVOID FrLdrDefaultHeap; PVOID FrLdrTempHeap;
@@ -173,6 +176,32 @@ TRACE("HeapRelease() done, freed %ld pages\n", AllFreePages); }
+VOID +HeapCleanupAll(VOID) +{ + PHEAP Heap; + + Heap = FrLdrDefaultHeap; + TRACE("Heap statistics for default heap:\n" + "CurrentAlloc=0x%lx, MaxAlloc=0x%lx, LargestAllocation=0x%lx\n" + "NumAllocs=%ld, NumFrees=%ld\n", + Heap->CurrentAllocBytes, Heap->MaxAllocBytes, Heap->LargestAllocation, + Heap->NumAllocs, Heap->NumFrees); + + /* Release fre pages */ + HeapRelease(FrLdrDefaultHeap); + + Heap = FrLdrTempHeap; + TRACE("Heap statistics for temp heap:\n" + "CurrentAlloc=0x%lx, MaxAlloc=0x%lx, LargestAllocation=0x%lx\n" + "NumAllocs=%ld, NumFrees=%ld\n", + Heap->CurrentAllocBytes, Heap->MaxAllocBytes, Heap->LargestAllocation, + Heap->NumAllocs, Heap->NumFrees); + + /* Destroy the heap */ + HeapDestroy(FrLdrTempHeap); +} + PVOID HeapAllocate( PVOID HeapHandle, @@ -328,22 +357,21 @@
/* Wrapper functions *********************************************************/
-#define HEAP_SIZE_PROCESS_HEAP (1024 * 1024) - VOID MmInitializeHeap(PVOID PageLookupTable) { TRACE("MmInitializeHeap()\n");
- /* Create the process heap */ - FrLdrDefaultHeap = HeapCreate(HEAP_SIZE_PROCESS_HEAP, LoaderOsloaderHeap); - - /* Create the process heap */ - FrLdrTempHeap = HeapCreate(HEAP_SIZE_PROCESS_HEAP, LoaderFirmwareTemporary); - - /* Create the pool heap */ - TRACE("MmInitializeHeap() done\n"); - + /* Create the default heap */ + FrLdrDefaultHeap = HeapCreate(DEFAULT_HEAP_SIZE, LoaderOsloaderHeap); + ASSERT(FrLdrDefaultHeap); + + /* Create a temporary heap */ + FrLdrTempHeap = HeapCreate(TEMP_HEAP_SIZE, LoaderFirmwareTemporary); + ASSERT(FrLdrTempHeap); + + TRACE("MmInitializeHeap() done, default heap %p, temp heap %p\n", + FrLdrDefaultHeap, FrLdrTempHeap); }
PVOID @@ -370,6 +398,15 @@ return HeapAllocate(FrLdrDefaultHeap, NumberOfBytes, Tag); }
+PVOID +NTAPI +ExAllocatePool( + IN POOL_TYPE PoolType, + IN SIZE_T NumberOfBytes) +{ + return HeapAllocate(FrLdrDefaultHeap, NumberOfBytes, 0); +} + #undef ExFreePool VOID NTAPI