Skip to content

Commit 62d4b1c

Browse files
authored
Implement getrlimit(RLIMIT_STACK) (#24054)
1 parent 1eb4e0f commit 62d4b1c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

system/lib/libc/emscripten_syscall_stubs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <sys/utsname.h>
2424
#include <emscripten/console.h>
2525
#include <emscripten/version.h>
26+
#include <emscripten/stack.h>
2627

2728
static int g_pid = 42;
2829
static int g_pgid = 42;
@@ -232,6 +233,13 @@ weak int __syscall_prlimit64(int pid, int resource, intptr_t new_limit, intptr_t
232233
// See FS.MAX_OPEN_FDS in src/lib/libfs.js
233234
old->rlim_cur = 4096;
234235
old->rlim_max = 4096;
236+
} else if (resource == RLIMIT_STACK) {
237+
uintptr_t end = emscripten_stack_get_end();
238+
uintptr_t base = emscripten_stack_get_base();
239+
240+
old->rlim_cur = base - end;
241+
// we can not change the stack size, so the maximum is the same as the current
242+
old->rlim_max = base - end;
235243
} else {
236244
// Just report no limits
237245
old->rlim_cur = RLIM_INFINITY;

test/other/test_rlimit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ int main() {
1414
printf("RLIMIT_CORE: rlim_cur: %lld\n", rlim.rlim_cur);
1515
printf("RLIMIT_CORE: rlim_max: %lld\n", rlim.rlim_max);
1616

17+
assert(getrlimit(RLIMIT_STACK, &rlim) == 0);
18+
printf("RLIMIT_STACK: rlim_cur: %lld\n", rlim.rlim_cur);
19+
printf("RLIMIT_STACK: rlim_max: %lld\n", rlim.rlim_max);
20+
1721
// setrlimit should always fail with EPERM
1822
assert(setrlimit(RLIMIT_NOFILE, &rlim) == -1);
1923
assert(errno == EPERM);

0 commit comments

Comments
 (0)