diff --git a/reactos/boot/freeldr/freeldr/include/arch/pc/pcbios.h b/reactos/boot/freeldr/freeldr/include/arch/pc/pcbios.h index dcf89b3c641..3f10198c9cf 100644 --- a/reactos/boot/freeldr/freeldr/include/arch/pc/pcbios.h +++ b/reactos/boot/freeldr/freeldr/include/arch/pc/pcbios.h @@ -1,5 +1,29 @@ #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 typedef struct { diff --git a/reactos/boot/freeldr/freeldr/include/debug.h b/reactos/boot/freeldr/freeldr/include/debug.h index 6eccd3dae81..bd2b60978fb 100644 --- a/reactos/boot/freeldr/freeldr/include/debug.h +++ b/reactos/boot/freeldr/freeldr/include/debug.h @@ -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) diff --git a/reactos/boot/freeldr/freeldr/include/freeldr.h b/reactos/boot/freeldr/freeldr/include/freeldr.h index 234542b9d26..166f6bd3d11 100644 --- a/reactos/boot/freeldr/freeldr/include/freeldr.h +++ b/reactos/boot/freeldr/freeldr/include/freeldr.h @@ -96,9 +96,9 @@ /* arch specific includes */ #if defined(_M_IX86) || defined(_M_AMD64) #include +#include #include #include -#include #include #endif #if defined(_M_IX86) diff --git a/reactos/boot/freeldr/freeldr/include/mm.h b/reactos/boot/freeldr/freeldr/include/mm.h index 2c721b91f2f..c9068e1c6d7 100644 --- a/reactos/boot/freeldr/freeldr/include/mm.h +++ b/reactos/boot/freeldr/freeldr/include/mm.h @@ -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 @@ typedef struct _FREELDR_MEMORY_DESCRIPTOR PFN_NUMBER PageCount; } FREELDR_MEMORY_DESCRIPTOR, *PFREELDR_MEMORY_DESCRIPTOR; -#include -typedef struct -{ - ULONGLONG BaseAddress; - ULONGLONG Length; - ULONG Type; - ULONG Reserved; -} BIOS_MEMORY_MAP, *PBIOS_MEMORY_MAP; -#include #if defined(__i386__) || defined(_PPC_) || defined(_MIPS_) || defined(_ARM_) @@ -88,12 +71,10 @@ typedef struct // #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 MmAllocateHighestMemoryBelowAddress(ULONG MemorySize, PVOID DesiredAddress 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); + diff --git a/reactos/boot/freeldr/freeldr/include/winldr.h b/reactos/boot/freeldr/freeldr/include/winldr.h index afd6c94d640..84bfa377353 100644 --- a/reactos/boot/freeldr/freeldr/include/winldr.h +++ b/reactos/boot/freeldr/freeldr/include/winldr.h @@ -33,14 +33,6 @@ typedef VOID (NTAPI *KERNEL_ENTRY_POINT) (PLOADER_PARAMETER_BLOCK LoaderBlock); #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 typedef struct /* Root System Descriptor Pointer */ { diff --git a/reactos/boot/freeldr/freeldr/mm/heap.c b/reactos/boot/freeldr/freeldr/mm/heap.c index a24e88e73ac..13b0fe3a544 100644 --- a/reactos/boot/freeldr/freeldr/mm/heap.c +++ b/reactos/boot/freeldr/freeldr/mm/heap.c @@ -88,6 +88,14 @@ VOID MmHeapFree(PVOID MemoryPointer) } +PVOID +NTAPI +ExAllocatePool( + IN POOL_TYPE PoolType, + IN SIZE_T NumberOfBytes) +{ + return MmHeapAlloc(NumberOfBytes); +} #undef ExAllocatePoolWithTag PVOID diff --git a/reactos/boot/freeldr/freeldr/mm/heap_new.c b/reactos/boot/freeldr/freeldr/mm/heap_new.c index 9a37815c93a..b495f01b784 100644 --- a/reactos/boot/freeldr/freeldr/mm/heap_new.c +++ b/reactos/boot/freeldr/freeldr/mm/heap_new.c @@ -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 @@ HeapRelease( 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 @@ HeapFree( /* 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 default heap */ + FrLdrDefaultHeap = HeapCreate(DEFAULT_HEAP_SIZE, LoaderOsloaderHeap); + ASSERT(FrLdrDefaultHeap); - /* Create the process heap */ - FrLdrTempHeap = HeapCreate(HEAP_SIZE_PROCESS_HEAP, LoaderFirmwareTemporary); - - /* Create the pool heap */ - TRACE("MmInitializeHeap() done\n"); + /* 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 @@ ExAllocatePoolWithTag( 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