From: Sergiu Moga Date: Thu, 13 Feb 2025 14:39:15 +0000 (+0200) Subject: lib/posix-process: Define kernel internal resource limit syscalls X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d40b2dca337acf4eee3407a7bbd8b97469cba53f;p=unikraft%2Funikraft.git lib/posix-process: Define kernel internal resource limit syscalls Add the kernel internal variants of `prlimit64`, `getrlimit` and `setrlimit`: `uk_sys_prlimit64`, `uk_sys_getrlimit` and `uk_sys_setrlimit` respectively. This allows kernel internal code to call these system calls' logic without having the syscall shim wrapper logic intervene. Note how only `uk_sys_prlimit64` has been added to `exportsyms.uk` since the others are defined as inline. Signed-off-by: Sergiu Moga Approved-by: Andrei Tatar Reviewed-by: Andrei Tatar GitHub-Closes: #1584 --- diff --git a/lib/posix-process/deprecated.c b/lib/posix-process/deprecated.c index 91ebe2244..7b4bd4825 100644 --- a/lib/posix-process/deprecated.c +++ b/lib/posix-process/deprecated.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -302,8 +303,8 @@ UK_SYSCALL_R_DEFINE(int, prctl, int, option, return 0; /* syscall has no effect */ } -UK_LLSYSCALL_R_DEFINE(int, prlimit64, int, pid, unsigned int, resource, - struct rlimit *, new_limit, struct rlimit *, old_limit) +int uk_sys_prlimit64(int pid, unsigned int resource, + struct rlimit *new_limit, struct rlimit *old_limit) { if (unlikely(pid != 0)) uk_pr_debug("Do not support prlimit64 on PID %u, use current process\n", @@ -374,16 +375,20 @@ UK_LLSYSCALL_R_DEFINE(int, prlimit64, int, pid, unsigned int, resource, return 0; } +UK_LLSYSCALL_R_DEFINE(int, prlimit64, int, pid, unsigned int, resource, + struct rlimit *, new_limit, struct rlimit *, old_limit) +{ + return uk_sys_prlimit64(pid, resource, new_limit, old_limit); +} + UK_SYSCALL_R_DEFINE(int, getrlimit, int, resource, struct rlimit *, rlim) { - return uk_syscall_r_prlimit64(0, (long) resource, - (long) NULL, (long) rlim); + return uk_sys_getrlimit(resource, rlim); } UK_SYSCALL_R_DEFINE(int, setrlimit, int, resource, const struct rlimit *, rlim) { - return uk_syscall_r_prlimit64(0, (long) resource, - (long) rlim, (long) NULL); + return uk_sys_setrlimit(resource, rlim); } UK_SYSCALL_R_DEFINE(int, getrusage, int, who, diff --git a/lib/posix-process/exportsyms.uk b/lib/posix-process/exportsyms.uk index 8b053daa3..20908789b 100644 --- a/lib/posix-process/exportsyms.uk +++ b/lib/posix-process/exportsyms.uk @@ -32,6 +32,7 @@ popen prctl uk_syscall_r_prctl uk_syscall_e_prctl +uk_sys_prlimit64 prlimit uk_syscall_r_prlimit64 uk_syscall_e_prlimit64 diff --git a/lib/posix-process/include/uk/process.h b/lib/posix-process/include/uk/process.h index dd2c1f93a..3171fb6f0 100644 --- a/lib/posix-process/include/uk/process.h +++ b/lib/posix-process/include/uk/process.h @@ -37,6 +37,7 @@ #include #include #include +#include #if CONFIG_LIBUKSCHED #include #endif @@ -131,6 +132,20 @@ #endif #endif /* CONFIG_LIBPOSIX_PROCESS_CLONE */ +int uk_sys_prlimit64(int pid, unsigned int resource, + struct rlimit *new_limit, struct rlimit *old_limit); + +static inline int uk_sys_getrlimit(int resource, struct rlimit *rlim) +{ + return uk_sys_prlimit64(0, resource, NULL, rlim); +} + +static inline int uk_sys_setrlimit(int resource, const struct rlimit *rlim) +{ + return uk_sys_prlimit64(0, resource, + DECONST(struct rlimit *, rlim), NULL); +} + #if CONFIG_LIBUKSCHED int uk_posix_process_create(struct uk_alloc *a, struct uk_thread *thread,