Skip to content

Commit ebbe66c

Browse files
authored
Add RLIMIT_AS and RLIMIT_DATA support to prlimit64 (#984)
* add prlimit resource * add prlimit resource * add prlimit resource * update test * update constants
1 parent 2793f29 commit ebbe66c

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/rawposix/src/sys_calls.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ use std::time::Duration;
1818
use sysdefs::constants::err_const::{get_errno, handle_errno, syscall_error, Errno, VERBOSE};
1919
use sysdefs::constants::fs_const::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
2020
use sysdefs::constants::lind_platform_const::{
21-
RAWPOSIX_CAGEID, UNUSED_ARG, UNUSED_ID, UNUSED_NAME, WASMTIME_CAGEID,
21+
MAX_LINEAR_MEMORY_SIZE, RAWPOSIX_CAGEID, UNUSED_ARG, UNUSED_ID, UNUSED_NAME, WASMTIME_CAGEID,
2222
};
2323
use sysdefs::constants::sys_const::{
24-
DEFAULT_GID, DEFAULT_UID, EXIT_SUCCESS, ITIMER_REAL, SIGCHLD, SIGKILL, SIGSTOP, SIG_BLOCK,
25-
SIG_SETMASK, SIG_UNBLOCK, WNOHANG,
24+
DEFAULT_GID, DEFAULT_UID, EXIT_SUCCESS, ITIMER_REAL, RLIMIT_AS, RLIMIT_DATA, RLIMIT_NOFILE,
25+
RLIMIT_RSS, RLIMIT_STACK, SIGCHLD, SIGKILL, SIGSTOP, SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK,
26+
WNOHANG,
2627
};
2728
use sysdefs::data::fs_struct::{ITimerVal, Rlimit, SigactionStruct};
2829
use sysdefs::logging::lind_debug_panic;
@@ -1196,16 +1197,18 @@ pub extern "C" fn prlimit64_syscall(
11961197
Err(e) => return syscall_error(e, "prlimit64", "bad address"),
11971198
};
11981199
match resource {
1199-
3 => {
1200-
// RLIMIT_STACK: 8MiB
1200+
RLIMIT_STACK => {
12011201
old_limit.rlim_cur = 8 * 1024 * 1024;
12021202
old_limit.rlim_max = 8 * 1024 * 1024;
12031203
}
1204-
7 => {
1205-
// RLIMIT_NOFILE: 1024
1204+
RLIMIT_NOFILE => {
12061205
old_limit.rlim_cur = 1024;
12071206
old_limit.rlim_max = 1024;
12081207
}
1208+
RLIMIT_DATA | RLIMIT_RSS | RLIMIT_AS => {
1209+
old_limit.rlim_cur = MAX_LINEAR_MEMORY_SIZE as u32;
1210+
old_limit.rlim_max = MAX_LINEAR_MEMORY_SIZE as u32;
1211+
}
12091212
_ => {
12101213
lind_debug_panic(&format!("prlimit64: unsupported resource {}", resource));
12111214
old_limit.rlim_cur = 0;

src/sysdefs/src/constants/sys_const.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ pub const NOFILE_MAX: u64 = 4 * 1024; // Hard limit for number of open files
2323
pub const STACK_CUR: u64 = 8192 * 1024; // Soft limit for stack size (8MB)
2424
pub const STACK_MAX: u64 = 1 << 32; // Hard limit for stack size (4GB)
2525

26-
// Resource identifiers
27-
pub const RLIMIT_STACK: u64 = 0; // Limit type for stack size
28-
pub const RLIMIT_NOFILE: u64 = 1; // Limit type for number of files
26+
// Resource identifiers (must match glibc bits/resource.h)
27+
pub const RLIMIT_CPU: u32 = 0;
28+
pub const RLIMIT_FSIZE: u32 = 1;
29+
pub const RLIMIT_DATA: u32 = 2;
30+
pub const RLIMIT_STACK: u32 = 3;
31+
pub const RLIMIT_CORE: u32 = 4;
32+
pub const RLIMIT_RSS: u32 = 5;
33+
pub const RLIMIT_NPROC: u32 = 6;
34+
pub const RLIMIT_NOFILE: u32 = 7;
35+
pub const RLIMIT_MEMLOCK: u32 = 8;
36+
pub const RLIMIT_AS: u32 = 9;
2937

3038
// ===== Process Exit Status =====
3139
// Source: <stdlib.h> and POSIX standard

tests/unit-tests/file_tests/deterministic/prlimit64.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ int main(void) {
1616
return 1;
1717
}
1818

19+
ret = getrlimit(RLIMIT_AS, &rl);
20+
if (ret != 0 || rl.rlim_cur == 0) {
21+
printf("FAIL\n");
22+
return 1;
23+
}
24+
25+
ret = getrlimit(RLIMIT_DATA, &rl);
26+
if (ret != 0 || rl.rlim_cur == 0) {
27+
printf("FAIL\n");
28+
return 1;
29+
}
30+
1931
printf("All prlimit64 tests passed\n");
2032
return 0;
2133
}

0 commit comments

Comments
 (0)