mirror of
https://github.com/reactos/reactos.git
synced 2025-05-31 06:58:10 +00:00
[FREELDR]
- Enable new heap code and cleanup the heap, releasing unused memory, before starting reactos - Gives our kernel about 4MB additional memory, which - at the current leak rate - means around 8 minutes longer before it runs out of memory :) - Using the temp heap for all temporary allocations should increase the amount of saved space svn path=/trunk/; revision=55518
This commit is contained in:
parent
9cde5acdc8
commit
e2efea8263
4 changed files with 5 additions and 1759 deletions
|
@ -54,7 +54,7 @@ list(APPEND FREELDR_COMMON_SOURCE
|
|||
inifile/parse.c
|
||||
mm/meminit.c
|
||||
mm/mm.c
|
||||
mm/heap.c
|
||||
mm/heap_new.c
|
||||
reactos/registry.c
|
||||
reactos/arcname.c
|
||||
reactos/archwsup.c
|
||||
|
@ -155,7 +155,6 @@ endif()
|
|||
list(APPEND FREELDR_BASE_SOURCE
|
||||
bootmgr.c # This file is compiled with custom definitions
|
||||
freeldr.c
|
||||
rtl/bget.c
|
||||
rtl/libsupp.c)
|
||||
|
||||
if (NOT MSVC)
|
||||
|
|
|
@ -1,157 +0,0 @@
|
|||
/*
|
||||
* FreeLoader
|
||||
* Copyright (C) 2006-2008 Aleksey Bragin <aleksey@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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <freeldr.h>
|
||||
#include <debug.h>
|
||||
|
||||
//#define MM_DBG 1 // needs #define BufStats 1 in bget.c
|
||||
|
||||
ULONG MmMaximumHeapAlloc;
|
||||
|
||||
DBG_DEFAULT_CHANNEL(MEMORY);
|
||||
|
||||
VOID MmInitializeHeap(PVOID PageLookupTable)
|
||||
{
|
||||
ULONG PagesNeeded = 0;
|
||||
ULONG HeapStart = 0;
|
||||
|
||||
// Find contigious memory block for HEAP:STACK
|
||||
PagesNeeded = HEAP_PAGES + STACK_PAGES;
|
||||
HeapStart = MmFindAvailablePages(PageLookupTable, TotalPagesInLookupTable, PagesNeeded, FALSE);
|
||||
|
||||
if (HeapStart == 0)
|
||||
{
|
||||
UiMessageBox("Critical error: Can't allocate heap!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize BGET
|
||||
bpool((PVOID)(HeapStart << MM_PAGE_SHIFT), PagesNeeded << MM_PAGE_SHIFT);
|
||||
|
||||
// Mark those pages as used
|
||||
MmMarkPagesInLookupTable(PageLookupTableAddress, HeapStart, PagesNeeded, LoaderOsloaderHeap);
|
||||
|
||||
TRACE("Heap initialized, base 0x%08x, pages %d\n", (HeapStart << MM_PAGE_SHIFT), PagesNeeded);
|
||||
}
|
||||
|
||||
PVOID MmHeapAlloc(ULONG MemorySize)
|
||||
{
|
||||
PVOID Result;
|
||||
|
||||
if (MemorySize > MM_PAGE_SIZE)
|
||||
{
|
||||
WARN("Consider using other functions to allocate %d bytes of memory!\n", MemorySize);
|
||||
}
|
||||
|
||||
// Get the buffer from BGET pool
|
||||
Result = bget(MemorySize);
|
||||
|
||||
if (Result == NULL)
|
||||
{
|
||||
ERR("Heap allocation for %d bytes failed\n", MemorySize);
|
||||
}
|
||||
#ifdef MM_DBG
|
||||
{
|
||||
LONG CurAlloc, TotalFree, MaxFree, NumberOfGets, NumberOfRels;
|
||||
|
||||
// Gather some stats
|
||||
bstats(&CurAlloc, &TotalFree, &MaxFree, &NumberOfGets, &NumberOfRels);
|
||||
if (CurAlloc > MmMaximumHeapAlloc) MmMaximumHeapAlloc = CurAlloc;
|
||||
|
||||
TRACE("Current alloc %d, free %d, max alloc %lx, allocs %d, frees %d\n",
|
||||
CurAlloc, TotalFree, MmMaximumHeapAlloc, NumberOfGets, NumberOfRels);
|
||||
}
|
||||
#endif
|
||||
return Result;
|
||||
}
|
||||
|
||||
VOID MmHeapFree(PVOID MemoryPointer)
|
||||
{
|
||||
// Release the buffer to the pool
|
||||
brel(MemoryPointer);
|
||||
}
|
||||
|
||||
|
||||
PVOID
|
||||
NTAPI
|
||||
ExAllocatePool(
|
||||
IN POOL_TYPE PoolType,
|
||||
IN SIZE_T NumberOfBytes)
|
||||
{
|
||||
return MmHeapAlloc(NumberOfBytes);
|
||||
}
|
||||
|
||||
#undef ExAllocatePoolWithTag
|
||||
PVOID
|
||||
NTAPI
|
||||
ExAllocatePoolWithTag(
|
||||
IN POOL_TYPE PoolType,
|
||||
IN SIZE_T NumberOfBytes,
|
||||
IN ULONG Tag)
|
||||
{
|
||||
return MmHeapAlloc(NumberOfBytes);
|
||||
}
|
||||
|
||||
#undef ExFreePool
|
||||
VOID
|
||||
NTAPI
|
||||
ExFreePool(
|
||||
IN PVOID P)
|
||||
{
|
||||
MmHeapFree(P);
|
||||
}
|
||||
|
||||
#undef ExFreePoolWithTag
|
||||
VOID
|
||||
NTAPI
|
||||
ExFreePoolWithTag(
|
||||
IN PVOID P,
|
||||
IN ULONG Tag)
|
||||
{
|
||||
ExFreePool(P);
|
||||
}
|
||||
|
||||
PVOID
|
||||
NTAPI
|
||||
RtlAllocateHeap(
|
||||
IN PVOID HeapHandle,
|
||||
IN ULONG Flags,
|
||||
IN SIZE_T Size)
|
||||
{
|
||||
PVOID ptr;
|
||||
|
||||
ptr = MmHeapAlloc(Size);
|
||||
if (ptr && (Flags & HEAP_ZERO_MEMORY))
|
||||
{
|
||||
RtlZeroMemory(ptr, Size);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
RtlFreeHeap(
|
||||
IN PVOID HeapHandle,
|
||||
IN ULONG Flags,
|
||||
IN PVOID HeapBase)
|
||||
{
|
||||
MmHeapFree(HeapBase);
|
||||
return TRUE;
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -202,8 +202,11 @@ WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
|
|||
//PKTSS Tss;
|
||||
//BOOLEAN Status;
|
||||
|
||||
/* Cleanup heap */
|
||||
HeapCleanupAll();
|
||||
|
||||
//
|
||||
// Creating a suitable memory map for the Windows can be tricky, so let's
|
||||
// Creating a suitable memory map for Windows can be tricky, so let's
|
||||
// give a few advices:
|
||||
// 1) One must not map the whole available memory pages to PDE!
|
||||
// Map only what's needed - 16Mb, 24Mb, 32Mb max I think,
|
||||
|
|
Loading…
Reference in a new issue