Recent

Author Topic: How to use mprotect/make a code segment memory writable? [solved]  (Read 320 times)

pik33

  • Jr. Member
  • **
  • Posts: 63
I have an asm code (ARM, RPi) which I want to move from a bare metal environment to Lazarus/Linux on RPi. It writes values to the procedure area so the program causes the exception.

Is there any way to set a code area memory writable (while linking or runtime)?

I read the ld linker has -N option which does this but I don't know if Lazarus (2.0.0) uses LD and if yes, how to pass the parameter to the linker. I tried -k in option with no success (a lot of linker errors)

Edit: I found a mprotect system call. How to use it in Lazarus?
« Last Edit: July 09, 2019, 09:33:18 am by pik33 »

pik33

  • Jr. Member
  • **
  • Posts: 63
Re: How to use mprotect/make a code segment memory writable?
« Reply #1 on: July 09, 2019, 09:32:57 am »
Solved

Code: [Select]
function Do_SysCall(sysnr,param1,param2,param3:cardinal):integer; external name 'FPC_SYSCALL3';

function fpmprotect(addr,size,prot:cardinal):longint;

begin
 result:=Do_SysCall(125,addr,size,prot);
end;     


marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7430
Re: How to use mprotect/make a code segment memory writable? [solved]
« Reply #2 on: July 09, 2019, 11:22:40 am »
The do_syscalls are available via unit syscall, so you don't need to declare it with external