diff --git a/rtl/inc/heap.inc b/rtl/inc/heap.inc index d4f21efd9a..5386010ed9 100644 --- a/rtl/inc/heap.inc +++ b/rtl/inc/heap.inc @@ -70,7 +70,7 @@ const {$define SHOW_MEM_USAGE} {$endif} -{$ifndef HAS_MEMORYMANAGER} +{$ifndef FPC_NO_DEFAULT_MEMORYMANAGER} const {$ifdef CPU64} blocksize = 32; { at least size of freerecord } @@ -366,7 +366,8 @@ end; {$endif FPC_IN_HEAPMGR} {$if defined(FPC_HAS_FEATURE_HEAP) or defined(FPC_IN_HEAPMGR)} -{$ifndef FPC_NO_DEFAULT_HEAP} +{$ifndef HAS_MEMORYMANAGER} + {***************************************************************************** GetHeapStatus @@ -1636,8 +1637,8 @@ begin {$endif} end; -{$endif ndef FPC_NO_DEFAULT_HEAP} +{$endif ndef HAS_MEMORYMANAGER} -{$endif HAS_MEMORYMANAGER} +{$endif ndef FPC_NO_DEFAULT_MEMORYMANAGER} {$endif defined(FPC_HAS_FEATURE_HEAP) or defined(FPC_IN_HEAPMGR)} diff --git a/rtl/inc/heaptrc.pp b/rtl/inc/heaptrc.pp index 3b5fcbe854..3ebff858eb 100644 --- a/rtl/inc/heaptrc.pp +++ b/rtl/inc/heaptrc.pp @@ -29,18 +29,7 @@ interface {$define windows} {$endif} -{$ifdef msdos} - {$macro on} - { msdos target OS uses tinyheap code } - {$define SysGetMem:=SysTinyGetMem} - {$define SysAllocMem:=SysTinyGetMem} - {$define SysFreeMem:=SysTinyFreeMem} - {$define SysFreeMemSize:=SysTinyFreeMemSize} - {$define SysMemSize:=SysTinyMemSize} - {$define SysTryResizeMem:=SysTinyTryResizeMem} - {$define SysGetFPCHeapStatus:=SysTinyGetFPCHeapStatus} - {$define SysGetHeapStatus:=SysTinyGetHeapStatus} -{$endif} + Procedure DumpHeap; Procedure DumpHeap(SkipIfNoLeaks : Boolean); diff --git a/rtl/inc/tinyheap.inc b/rtl/inc/tinyheap.inc index 40cc577cae..f9dd134094 100644 --- a/rtl/inc/tinyheap.inc +++ b/rtl/inc/tinyheap.inc @@ -88,13 +88,13 @@ FindSize := PTinyHeapMemBlockSize(p)[-1]; end; - function SysTinyGetMem(Size: ptruint): pointer; + function SysGetMem(Size: ptruint): pointer; var p, prev, p2: PTinyHeapBlock; AllocSize, RestSize: ptruint; begin {$ifdef DEBUG_TINY_HEAP} - Write('SysTinyGetMem(', Size, ')='); + Write('SysGetMem(', Size, ')='); {$endif DEBUG_TINY_HEAP} AllocSize := align(size+sizeof(TTinyHeapMemBlockSize), TinyHeapAllocGranularity); @@ -157,7 +157,7 @@ begin RegisterTinyHeapBlock(p,AllocSize); { Recursive call } - SysTinyGetmem:=SysTinyGetmem(Size); + SysGetMem:=SysGetMem(Size); exit; end; end @@ -242,51 +242,51 @@ end; end; - function SysTinyFreeMem(Addr: Pointer): ptruint; + function SysFreeMem(p: Pointer): ptruint; var sz: ptruint; begin {$ifdef DEBUG_TINY_HEAP} - Writeln('SysTinyFreeMem(', HexStr(Addr), ')'); + Writeln('SysFreeMem(', HexStr(p), ')'); {$endif DEBUG_TINY_HEAP} - if addr=nil then + if p=nil then begin result:=0; exit; end; - if (TTinyHeapPointerArithmeticType(addr) < TTinyHeapPointerArithmeticType(HeapOrg)) or - (TTinyHeapPointerArithmeticType(addr) >= TTinyHeapPointerArithmeticType(HeapPtr)) then + if (TTinyHeapPointerArithmeticType(p) < TTinyHeapPointerArithmeticType(HeapOrg)) or + (TTinyHeapPointerArithmeticType(p) >= TTinyHeapPointerArithmeticType(HeapPtr)) then HandleError(204); - sz := Align(FindSize(addr)+SizeOf(TTinyHeapMemBlockSize), TinyHeapAllocGranularity); + sz := Align(FindSize(p)+SizeOf(TTinyHeapMemBlockSize), TinyHeapAllocGranularity); - InternalTinyFreeMem(@PTinyHeapMemBlockSize(addr)[-1], sz); + InternalTinyFreeMem(@PTinyHeapMemBlockSize(p)[-1], sz); result := sz; end; - function SysTinyFreeMemSize(Addr: Pointer; Size: Ptruint): ptruint; + function SysFreeMemSize(p: Pointer; Size: Ptruint): ptruint; begin - result := SysTinyFreeMem(addr); + result := SysFreeMem(p); end; - function SysTinyMemSize(p: pointer): ptruint; + function SysMemSize(p: pointer): ptruint; begin result := findsize(p); end; - function SysTinyTryResizeMem(var p: pointer; size: ptruint) : boolean; + function SysTryResizeMem(var p: pointer; size: ptruint) : boolean; begin result := false; end; - function SysTinyAllocMem(size: ptruint): pointer; + function SysAllocMem(size: ptruint): pointer; begin - result := SysTinyGetMem(size); + result := SysGetMem(size); if result<>nil then - FillChar(result^,SysTinyMemSize(result),0); + FillChar(result^,SysMemSize(result),0); end; - function SysTinyReAllocMem(var p: pointer; size: ptruint):pointer; + function SysReAllocMem(var p: pointer; size: ptruint):pointer; var oldsize, OldAllocSize, NewAllocSize: ptruint; after_block, before_block, before_before_block: PTinyHeapBlock; @@ -294,11 +294,11 @@ new_after_block: PTinyHeapBlock; begin {$ifdef DEBUG_TINY_HEAP} - Write('SysTinyReAllocMem(', HexStr(p), ',', size, ')='); + Write('SysReAllocMem(', HexStr(p), ',', size, ')='); {$endif DEBUG_TINY_HEAP} if size=0 then begin - SysTinyFreeMem(p); + SysFreeMem(p); result := nil; p := nil; end @@ -440,7 +440,7 @@ oldsize := size; move(pbyte(p)^, pbyte(result)^, oldsize); end; - SysTinyFreeMem(p); + SysFreeMem(p); p := result; end; end; @@ -588,7 +588,7 @@ end; - function SysTinyGetFPCHeapStatus : TFPCHeapStatus; + function SysGetFPCHeapStatus : TFPCHeapStatus; { TFPCHeapStatus = record @@ -600,48 +600,30 @@ end; } begin - SysTinyGetFPCHeapStatus.MaxHeapSize:=MaxAvail; + SysGetFPCHeapStatus.MaxHeapSize:=MaxAvail; { How can we compute this? } - SysTinyGetFPCHeapStatus.MaxHeapUsed:=0; - SysTinyGetFPCHeapStatus.CurrHeapFree:=MemAvail; - SysTinyGetFPCHeapStatus.CurrHeapUsed:=HeapSize-SysTinyGetFPCHeapStatus.CurrHeapFree; - SysTinyGetFPCHeapStatus.CurrHeapSize:=HeapSize; + SysGetFPCHeapStatus.MaxHeapUsed:=0; + SysGetFPCHeapStatus.CurrHeapFree:=MemAvail; + SysGetFPCHeapStatus.CurrHeapUsed:=HeapSize-SysGetFPCHeapStatus.CurrHeapFree; + SysGetFPCHeapStatus.CurrHeapSize:=HeapSize; end; - function SysTinyGetHeapStatus : THeapStatus; + function SysGetHeapStatus : THeapStatus; begin - SysTinyGetHeapStatus.TotalAddrSpace:= HeapSize; - SysTinyGetHeapStatus.TotalUncommitted:= 0; - SysTinyGetHeapStatus.TotalCommitted:= 0; - SysTinyGetHeapStatus.TotalAllocated:= HeapSize-MemAvail; - SysTinyGetHeapStatus.TotalFree:= MemAvail; - SysTinyGetHeapStatus.FreeSmall:= 0; - SysTinyGetHeapStatus.FreeBig:= 0; - SysTinyGetHeapStatus.Unused:= 0; - SysTinyGetHeapStatus.Overhead:= 0; - SysTinyGetHeapStatus.HeapErrorCode:= 0; + SysGetHeapStatus.TotalAddrSpace:= HeapSize; + SysGetHeapStatus.TotalUncommitted:= 0; + SysGetHeapStatus.TotalCommitted:= 0; + SysGetHeapStatus.TotalAllocated:= HeapSize-MemAvail; + SysGetHeapStatus.TotalFree:= MemAvail; + SysGetHeapStatus.FreeSmall:= 0; + SysGetHeapStatus.FreeBig:= 0; + SysGetHeapStatus.Unused:= 0; + SysGetHeapStatus.Overhead:= 0; + SysGetHeapStatus.HeapErrorCode:= 0; end; -{$ifdef FPC_NO_DEFAULT_MEMORYMANAGER} procedure FinalizeHeap; begin end; -{$endif FPC_NO_DEFAULT_MEMORYMANAGER} - - const - TinyHeapMemoryManager: TMemoryManager = ( - NeedLock: false; // Obsolete - GetMem: @SysTinyGetMem; - FreeMem: @SysTinyFreeMem; - FreeMemSize: @SysTinyFreeMemSize; - AllocMem: @SysTinyAllocMem; - ReAllocMem: @SysTinyReAllocMem; - MemSize: @SysTinyMemSize; - InitThread: nil; - DoneThread: nil; - RelocateHeap: nil; - GetHeapStatus: @SysTinyGetHeapStatus; - GetFPCHeapStatus: @SysTinyGetFPCHeapStatus; - ); diff --git a/rtl/inc/tnyheaph.inc b/rtl/inc/tnyheaph.inc index 72fab9d3df..2b771a67eb 100644 --- a/rtl/inc/tnyheaph.inc +++ b/rtl/inc/tnyheaph.inc @@ -31,6 +31,9 @@ function MaxAvail: {$ifdef FPC_TINYHEAP_HUGE}LongInt{$else}PtrUInt{$endif}; procedure Mark(var p: Pointer); procedure Release(var p: Pointer); +(* + Obsolete, renamed without the Tiny + to have the same names as in heap.inc function SysTinyGetMem(Size: ptruint): pointer; function SysTinyFreeMem(Addr: Pointer): ptruint; function SysTinyFreeMemSize(Addr: Pointer; Size: Ptruint): ptruint; @@ -38,3 +41,5 @@ function SysTinyGetFPCHeapStatus : TFPCHeapStatus; function SysTinyGetHeapStatus : THeapStatus; function SysTinyTryResizeMem(var p: pointer; size: ptruint) : boolean; + + *) diff --git a/rtl/msdos/system.pp b/rtl/msdos/system.pp index b56bd8eadc..82a3b286de 100644 --- a/rtl/msdos/system.pp +++ b/rtl/msdos/system.pp @@ -2,8 +2,11 @@ unit System; interface -{$DEFINE FPC_NO_DEFAULT_HEAP} -{$define FPC_NO_DEFAULT_MEMORYMANAGER} +{ The heap for MSDOS is implemented + in tinyheap.inc include file, + but it uses default SysGetMem names } + +{$define HAS_MEMORYMANAGER} {$DEFINE FPC_INCLUDE_SOFTWARE_MUL} {$DEFINE FPC_INCLUDE_SOFTWARE_MOD_DIV} @@ -74,6 +77,8 @@ var PrefixSeg:Word;public name '__fpc_PrefixSeg'; SaveInt00: FarPointer;public name '__SaveInt00'; + SaveInt10: FarPointer;public name '__SaveInt10'; + SaveInt75: FarPointer;public name '__SaveInt75'; AllFilesMask: string [3]; {$ifndef RTLLITE} @@ -489,7 +494,6 @@ type TPointerArithmeticType = Pointer; {$endif} begin - SetMemoryManager(TinyHeapMemoryManager); RegisterTinyHeapBlock_Simple_Prealigned(__nearheap_start, TPointerArithmeticType(__nearheap_end) - TPointerArithmeticType(__nearheap_start)); end; diff --git a/rtl/win16/system.pp b/rtl/win16/system.pp index a12f16a881..3f85f25510 100644 --- a/rtl/win16/system.pp +++ b/rtl/win16/system.pp @@ -3,7 +3,7 @@ unit system; interface {$DEFINE FPC_NO_DEFAULT_HEAP} -{$DEFINE FPC_NO_DEFAULT_MEMORYMANAGER} +{$DEFINE HAS_MEMORYMANAGER} {$DEFINE FPC_INCLUDE_SOFTWARE_MUL} {$DEFINE FPC_INCLUDE_SOFTWARE_MOD_DIV} @@ -90,6 +90,10 @@ var { SaveInt00: FarPointer;public name '__SaveInt00';} + { Required for i8086.inc Stack check code } + __stkbottom : pointer;public name '__stkbottom'; + + AllFilesMask: string [3]; {$ifndef RTLLITE} { System info } @@ -453,6 +457,7 @@ begin StackLength := pStackBot-pStackTop; end; {$endif} + __stkbottom := StackBottom; { To be set if this is a GUI or console application } IsConsole := FALSE; { To be set if this is a library and not a program }