Skip to content

Commit

Permalink
Little fixes that enables compilation for FPC x86_64-linux target, Ge…
Browse files Browse the repository at this point in the history
…tMem/FreeMem tested and works
  • Loading branch information
Mario Ray Mahardhika committed Jun 3, 2017
1 parent 4447db1 commit 47dbaca
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions FastMM4.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,9 @@ interface
PNativeUInt = ^Cardinal;
IntPtr = Integer;
UIntPtr = Cardinal;
{$else}
NativeUInt = PtrUInt;
PNativeUInt = ^PtrUInt;
{$endif}
{$endif}

Expand Down Expand Up @@ -1570,6 +1573,9 @@ implementation
FastMM4Messages;

{$ifdef fpc}
const
clib = 'c';

function valloc(__size:size_t):pointer;cdecl;external clib name 'valloc';
procedure free(__ptr:pointer);cdecl;external clib name 'free';
function usleep(__useconds:dword):longint;cdecl;external clib name 'usleep';
Expand Down Expand Up @@ -2303,7 +2309,7 @@ function MMX_Supported: Boolean;
{Compare [AAddress], CompareVal:
If Equal: [AAddress] := NewVal and result = CompareVal
If Unequal: Result := [AAddress]}
function LockCmpxchg(CompareVal, NewVal: Byte; AAddress: PByte): Byte; {$ifdef fpc64bit}nostackframe;{$endif}
function LockCmpxchg(CompareVal, NewVal: Byte; AAddress: PByte): Byte; {$ifdef fpc64bit}assembler; nostackframe;{$endif}
asm
{$ifdef 32Bit}
{On entry:
Expand Down Expand Up @@ -2334,7 +2340,7 @@ function LockCmpxchg(CompareVal, NewVal: Byte; AAddress: PByte): Byte; {$ifdef f

{$ifndef ASMVersion}
{Gets the first set bit in the 32-bit number, returning the bit index}
function FindFirstSetBit(ACardinal: Cardinal): Cardinal; {$ifdef fpc64bit} nostackframe; {$endif}
function FindFirstSetBit(ACardinal: Cardinal): Cardinal; {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 64Bit}
{$ifndef unix}
Expand Down Expand Up @@ -2492,7 +2498,7 @@ function AppendStringToModuleName(AString, ABuffer: PAnsiChar): PAnsiChar;
{Fixed size move operations ignore the size parameter. All moves are assumed to
be non-overlapping.}

procedure Move4(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move4(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
mov eax, [eax]
Expand All @@ -2510,7 +2516,7 @@ procedure Move4(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
end;

{$ifdef 64Bit}
procedure Move8(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move8(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifndef unix}
.noframe
Expand All @@ -2523,7 +2529,7 @@ procedure Move8(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
end;
{$endif}

procedure Move12(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move12(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
mov ecx, [eax]
Expand All @@ -2548,7 +2554,7 @@ procedure Move12(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
{$endif}
end;

procedure Move20(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move20(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
mov ecx, [eax]
Expand Down Expand Up @@ -2578,7 +2584,7 @@ procedure Move20(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
end;

{$ifdef 64Bit}
procedure Move24(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move24(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifndef unix}
.noframe
Expand All @@ -2595,7 +2601,7 @@ procedure Move24(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
end;
{$endif}

procedure Move28(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move28(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
mov ecx, [eax]
Expand Down Expand Up @@ -2632,7 +2638,7 @@ procedure Move28(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
{$endif}
end;

procedure Move36(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move36(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
fild qword ptr [eax]
Expand Down Expand Up @@ -2666,7 +2672,7 @@ procedure Move36(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
end;

{$ifdef 64Bit}
procedure Move40(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move40(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifndef unix}
.noframe
Expand All @@ -2687,7 +2693,7 @@ procedure Move40(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
end;
{$endif}

procedure Move44(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move44(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
fild qword ptr [eax]
Expand Down Expand Up @@ -2726,7 +2732,7 @@ procedure Move44(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
{$endif}
end;

procedure Move52(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move52(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
fild qword ptr [eax]
Expand Down Expand Up @@ -2768,7 +2774,7 @@ procedure Move52(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
end;

{$ifdef 64Bit}
procedure Move56(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move56(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifndef unix}
.noframe
Expand All @@ -2793,7 +2799,7 @@ procedure Move56(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
end;
{$endif}

procedure Move60(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move60(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
fild qword ptr [eax]
Expand Down Expand Up @@ -2840,7 +2846,7 @@ procedure Move60(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
{$endif}
end;

procedure Move68(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure Move68(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
fild qword ptr [eax]
Expand Down Expand Up @@ -2893,7 +2899,7 @@ procedure Move68(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit}
SizeOf(Pointer). Important note: Always moves at least 16 - SizeOf(Pointer)
bytes (the minimum small block size with 16 byte alignment), irrespective of
ACount.}
procedure MoveX16LP(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure MoveX16LP(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
{Make the counter negative based: The last 12 bytes are moved separately}
Expand Down Expand Up @@ -3019,7 +3025,7 @@ procedure MoveX16LP(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64b
SizeOf(Pointer). Important note: Always moves at least 8 - SizeOf(Pointer)
bytes (the minimum small block size with 8 byte alignment), irrespective of
ACount.}
procedure MoveX8LP(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure MoveX8LP(const ASource; var ADest; ACount: NativeInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
{Make the counter negative based: The last 4 bytes are moved separately}
Expand Down Expand Up @@ -3193,7 +3199,7 @@ function GetThreadID: Cardinal;

{Fills a block of memory with the given dword (32-bit) or qword (64-bit).
Always fills a multiple of SizeOf(Pointer) bytes}
procedure DebugFillMem(var AAddress; AByteCount: NativeInt; AFillValue: NativeUInt); {$ifdef fpc64bit} nostackframe; {$endif}
procedure DebugFillMem(var AAddress; AByteCount: NativeInt; AFillValue: NativeUInt); {$ifdef fpc64bit} assembler; nostackframe; {$endif}
asm
{$ifdef 32Bit}
{On Entry:
Expand Down Expand Up @@ -5128,7 +5134,7 @@ function FastGetMem(ASize: {$ifdef XE2AndUp}NativeInt{$else}{$ifdef fpc}NativeUI
else
begin
{Allocate a Large block}
if ASize > 0 then
if ASize > 0 then
begin
Result := AllocateLargeBlock(ASize {$ifdef LogLockContention}, LDidSleep{$endif});
{$ifdef LogLockContention}
Expand All @@ -5142,7 +5148,7 @@ function FastGetMem(ASize: {$ifdef XE2AndUp}NativeInt{$else}{$ifdef fpc}NativeUI
end;
{$ifdef LogLockContention}
{$ifndef FullDebugMode}
if Assigned(ACollector) then
if Assigned(ACollector) then
begin
GetStackTrace(@LStackTrace, StackTraceDepth, 1);
ACollector.Add(@LStackTrace[0], StackTraceDepth);
Expand Down Expand Up @@ -9638,7 +9644,7 @@ function DebugGetMem(ASize: {$ifdef XE2AndUp}NativeInt{$else}Integer{$endif}): P
else
begin
{$ifdef LogLockContention}
if assigned(LCollector) then
if assigned(LCollector) then
begin
GetStackTrace(@LStackTrace, StackTraceDepth, 1);
LCollector.Add(@LStackTrace[0], StackTraceDepth);
Expand Down Expand Up @@ -12045,13 +12051,13 @@ procedure ReportLockContention;
LargeBlockCollector.GetData(mergedData, mergedCount);
MediumBlockCollector.GetData(data, count);
LargeBlockCollector.Merge(mergedData, mergedCount, data, count);
for i := 0 to High(SmallBlockTypes) do
for i := 0 to High(SmallBlockTypes) do
begin
SmallBlockTypes[i].BlockCollector.GetData(data, count);
LargeBlockCollector.Merge(mergedData, mergedCount, data, count);
end;

if mergedCount > 0 then
if mergedCount > 0 then
begin
FillChar(LErrorMessage, SizeOf(LErrorMessage), 0);
FillChar(LMessageTitleBuffer, SizeOf(LMessageTitleBuffer), 0);
Expand All @@ -12076,7 +12082,7 @@ procedure ReportLockContention;
end;
AppendStringToModuleName(LockingReportTitle, LMessageTitleBuffer);
ShowMessageBox(LErrorMessage, LMessageTitleBuffer);
for i := 4 to 10 do
for i := 4 to 10 do
begin
if i > mergedCount then
break; //for i
Expand Down Expand Up @@ -12948,11 +12954,13 @@ procedure FinalizeMemoryManager;
and DelphiIsRunning
{$endif}
{$ifdef RequireDebuggerPresenceForLeakReporting}
{$ifndef fpc}
and ((DebugHook <> 0)
{$ifdef PatchBCBTerminate}
or (Assigned(pCppDebugHook) and (pCppDebugHook^ <> 0))
{$endif PatchBCBTerminate}
)
{$endif}
{$endif}
{$ifdef ManualLeakReportingControl}
and ReportMemoryLeaksOnShutdown
Expand Down

0 comments on commit 47dbaca

Please sign in to comment.