Browse Source

* implement memory allocation functions for Unix platforms using mmap/mprotect/munmap

git-svn-id: trunk@42183 -
svenbarth 6 years ago
parent
commit
c008adb658
1 changed files with 12 additions and 0 deletions
  1. 12 0
      packages/rtl-objpas/src/inc/rtti.pp

+ 12 - 0
packages/rtl-objpas/src/inc/rtti.pp

@@ -576,6 +576,9 @@ implementation
 uses
 {$ifdef windows}
   Windows,
+{$endif}
+{$ifdef unix}
+  BaseUnix,
 {$endif}
   fgl;
 
@@ -749,6 +752,8 @@ function AllocateMemory(aSize: PtrUInt): Pointer;
 begin
 {$IF DEFINED(WINDOWS)}
   Result := VirtualAlloc(Nil, aSize, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
+{$ELSEIF DEFINED(UNIX)}
+  Result := fpmmap(Nil, aSize, PROT_READ or PROT_WRITE, MAP_PRIVATE or MAP_ANONYMOUS, 0, 0);
 {$ELSE}
   Result := GetMem(aSize);
 {$ENDIF}
@@ -765,6 +770,11 @@ begin
     Result := VirtualProtect(aPtr, aSize, PAGE_EXECUTE_READ, oldprot)
   else
     Result := VirtualProtect(aPtr, aSize, PAGE_READWRITE, oldprot);
+{$ELSEIF DEFINED(UNIX)}
+  if aExecutable then
+    Result := Fpmprotect(aPtr, aSize, PROT_EXEC or PROT_READ) = 0
+  else
+    Result := Fpmprotect(aPtr, aSize, PROT_READ or PROT_WRITE) = 0;
 {$ELSE}
   Result := True;
 {$ENDIF}
@@ -774,6 +784,8 @@ procedure FreeMemory(aPtr: Pointer; aSize: PtrUInt);
 begin
 {$IF DEFINED(WINDOWS)}
   VirtualFree(aPtr, 0, MEM_RELEASE);
+{$ELSEIF DEFINED(UNIX)}
+  fpmunmap(aPtr, aSize);
 {$ELSE}
   FreeMem(aPtr);
 {$ENDIF}