View Issue Details

IDProjectCategoryView StatusLast Update
0037345FPCRTLpublic2020-07-13 17:43
ReporterCyrax Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformLinux x86_64OSArch 
Product Version3.3.1 
Summary0037345: fpgetrlimit/fpugetrlimit with RLIMIT_STACK argument gives bogus values under i386-linux target.
DescriptionI noticed this bug during my debugging session on why lazbuild fails randomly by trying to limit how much stack is reserved on program and threads it creates (https://bugs.freepascal.org/view.php?id=37179)

Also setting stack values (namely rlim_cur) will fail under i386-linux.

x86_64-linux target does not inhibit this problem.

Fix is to change calls to syscall_nr_getrlimit, syscall_nr_ugetrlimit and syscall_nr_setrlimit to syscall_nr_prlimit64 one.

See attached test project (project1.zip) and patch (ossysc.inc.diff) for more info.
Additional Informationtest project output under i386-linux target:
syscall_nr_getrlimit : success TRUE
syscall_nr_getrlimit : alimits.rlim_cur 9223372032568197120
syscall_nr_getrlimit : alimits.rlim_max 0

syscall_nr_ugetrlimit : success TRUE
syscall_nr_ugetrlimit : alimits.rlim_cur 18446744069422972928
syscall_nr_ugetrlimit : alimits.rlim_max 0

syscall_nr_getrlimit : success TRUE
syscall_nr_getrlimit : blimits.rlim_cur 9223372032568197120
syscall_nr_getrlimit : blimits.rlim_max 0
set syscall_nr_setrlimit : blimits.rlim_cur 2097152
syscall_nr_setrlimit : success FALSE
syscall_nr_setrlimit : blimits.rlim_cur 2097152
syscall_nr_setrlimit : blimits.rlim_max 0

syscall_nr_getrlimit : success TRUE
syscall_nr_getrlimit : blimits.rlim_cur 9223372032568197120
syscall_nr_getrlimit : blimits.rlim_max 0

get syscall_nr_prlimit64 : success TRUE
get syscall_nr_prlimit64 : alimits.rlim_cur 8388608
get syscall_nr_prlimit64 : alimits.rlim_max 18446744073709551615

get syscall_nr_prlimit64 : success TRUE
get syscall_nr_prlimit64 : alimits.rlim_cur 8388608
get syscall_nr_prlimit64 : alimits.rlim_max 18446744073709551615
set syscall_nr_prlimit64 : alimits.rlim_cur 2097152
set syscall_nr_prlimit64 : success TRUE
get syscall_nr_prlimit64 : success TRUE
get syscall_nr_prlimit64 : alimits.rlim_cur 2097152
get syscall_nr_prlimit64 : alimits.rlim_max 18446744073709551615


---


test project output under x86_64-linux target:
syscall_nr_getrlimit : success TRUE
syscall_nr_getrlimit : alimits.rlim_cur 8388608
syscall_nr_getrlimit : alimits.rlim_max 18446744073709551615

syscall_nr_getrlimit : success TRUE
syscall_nr_getrlimit : blimits.rlim_cur 8388608
syscall_nr_getrlimit : blimits.rlim_max 18446744073709551615
set syscall_nr_setrlimit : blimits.rlim_cur 2097152
syscall_nr_setrlimit : success TRUE
syscall_nr_setrlimit : blimits.rlim_cur 2097152
syscall_nr_setrlimit : blimits.rlim_max 18446744073709551615

syscall_nr_getrlimit : success TRUE
syscall_nr_getrlimit : blimits.rlim_cur 2097152
syscall_nr_getrlimit : blimits.rlim_max 18446744073709551615

get syscall_nr_prlimit64 : success TRUE
get syscall_nr_prlimit64 : alimits.rlim_cur 2097152
get syscall_nr_prlimit64 : alimits.rlim_max 18446744073709551615

get syscall_nr_prlimit64 : success TRUE
get syscall_nr_prlimit64 : alimits.rlim_cur 2097152
get syscall_nr_prlimit64 : alimits.rlim_max 18446744073709551615
set syscall_nr_prlimit64 : alimits.rlim_cur 2097152
set syscall_nr_prlimit64 : success TRUE
get syscall_nr_prlimit64 : success TRUE
get syscall_nr_prlimit64 : alimits.rlim_cur 2097152
get syscall_nr_prlimit64 : alimits.rlim_max 18446744073709551615
Tagspatch
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Cyrax

2020-07-13 17:41

reporter  

project1.zip (1,437 bytes)
ossysc.inc.diff (1,267 bytes)   
diff --git a/rtl/linux/ossysc.inc b/rtl/linux/ossysc.inc
index 074ad4b9a8..5a8f1793a1 100644
--- a/rtl/linux/ossysc.inc
+++ b/rtl/linux/ossysc.inc
@@ -701,21 +701,14 @@ end;
 
 function FpGetRLimit(resource : cInt; rlim : PRLimit) : cInt; [public, alias : 'FPC_SYSC_GETRLIMIT'];
 begin
-{$ifndef NO_SYSCALL_GETRLIMIT}
-  FpGetRLimit := do_syscall(syscall_nr_getrlimit,
-    TSysParam(resource), TSysParam(rlim));
-{$else}
-  FpGetRLimit := do_syscall(syscall_nr_ugetrlimit,
-    TSysParam(resource), TSysParam(rlim));
-{$endif}
+   FpGetRLimit := do_syscall(syscall_nr_prlimit64, 0, resource, TSysParam(NIL), TSysParam(rlim));
 end;
 
 
 {$ifdef HAS_UGETRLIMIT}
 function fpugetrlimit(resource : cInt; rlim : PRLimit) : cInt;
 begin
-  FpUGetRLimit := do_syscall(syscall_nr_ugetrlimit,
-    TSysParam(resource), TSysParam(rlim));
+  FpUGetRLimit := do_syscall(syscall_nr_prlimit64, 0, resource, TSysParam(NIL), TSysParam(rlim));
 end;
 {$endif}
 
@@ -729,6 +722,6 @@ end;
 
 function FpSetRLimit(Resource:cint;rlim:PRLimit):cint; [public, alias : 'FPC_SYSC_SETRLIMIT'];
 begin
-  fpsetrlimit:=do_syscall(syscall_nr_setrlimit,TSysParam(Resource),TSysParam(rlim));
+  fpsetrlimit:=do_syscall(syscall_nr_prlimit64, 0, Resource, TSysParam(rlim), TSysParam(NIL));
 end;
 
ossysc.inc.diff (1,267 bytes)   

Issue History

Date Modified Username Field Change
2020-07-13 17:41 Cyrax New Issue
2020-07-13 17:41 Cyrax File Added: project1.zip
2020-07-13 17:41 Cyrax File Added: ossysc.inc.diff
2020-07-13 17:43 Cyrax Tag Attached: patch