From 744a99d75c258b317aaad74c6a80bb664993305e Mon Sep 17 00:00:00 2001 From: "Qinsi (James) ZHU" Date: Fri, 9 Jun 2023 22:03:28 +0800 Subject: [PATCH] add const RLIMIT_STACK (#21772) * add const RLIMIT_STACK * generate by detect.nim * add generated const for linux-amd64 --- lib/posix/posix_linux_amd64_consts.nim | 1 + lib/posix/posix_other_consts.nim | 1 + tests/stdlib/tposix.nim | 24 ++++++++++++++++++++++++ tools/detect/detect.nim | 1 + 4 files changed, 27 insertions(+) diff --git a/lib/posix/posix_linux_amd64_consts.nim b/lib/posix/posix_linux_amd64_consts.nim index f3230f71d6..6ac0279fcc 100644 --- a/lib/posix/posix_linux_amd64_consts.nim +++ b/lib/posix/posix_linux_amd64_consts.nim @@ -453,6 +453,7 @@ const MAP_POPULATE* = cint(32768) # const RLIMIT_NOFILE* = cint(7) +const RLIMIT_STACK* = cint(3) # const FD_SETSIZE* = cint(1024) diff --git a/lib/posix/posix_other_consts.nim b/lib/posix/posix_other_consts.nim index 08069fe9a7..f4809a9c27 100644 --- a/lib/posix/posix_other_consts.nim +++ b/lib/posix/posix_other_consts.nim @@ -467,6 +467,7 @@ var POSIX_TYPED_MEM_MAP_ALLOCATABLE* {.importc: "POSIX_TYPED_MEM_MAP_ALLOCATABLE # var RLIMIT_NOFILE* {.importc: "RLIMIT_NOFILE", header: "".}: cint +var RLIMIT_STACK* {.importc: "RLIMIT_STACK", header: "".}: cint # var FD_SETSIZE* {.importc: "FD_SETSIZE", header: "".}: cint diff --git a/tests/stdlib/tposix.nim b/tests/stdlib/tposix.nim index c5e820836a..060482229a 100644 --- a/tests/stdlib/tposix.nim +++ b/tests/stdlib/tposix.nim @@ -62,3 +62,27 @@ when not defined(windows): ) doAssert buffer == sent doAssert bytesRead == int(MQ_MESSAGE_SIZE) + + block: + var rl: RLimit + var res = getrlimit(RLIMIT_STACK, rl) + doAssert res == 0 + + # save old value + let oldrlim = rl.rlim_cur + + # set new value + rl.rlim_cur = rl.rlim_max - 1 + res = setrlimit(RLIMIT_STACK, rl) + doAssert res == 0 + + # get new value + var rl1: RLimit + res = getrlimit(RLIMIT_STACK, rl1) + doAssert res == 0 + doAssert rl1.rlim_cur == rl.rlim_max - 1 + + # restore old value + rl.rlim_cur = oldrlim + res = setrlimit(RLIMIT_STACK, rl) + doAssert res == 0 diff --git a/tools/detect/detect.nim b/tools/detect/detect.nim index ed1caf78ca..fe233420b5 100644 --- a/tools/detect/detect.nim +++ b/tools/detect/detect.nim @@ -618,6 +618,7 @@ v("MAP_POPULATE", no_other = true) header("") v("RLIMIT_NOFILE") +v("RLIMIT_STACK") header("") v("FD_SETSIZE")