]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-process: Define kernel internal resource limit syscalls
authorSergiu Moga <sergiu@unikraft.io>
Thu, 13 Feb 2025 14:39:15 +0000 (16:39 +0200)
committerUnikraft Bot <monkey@unikraft.io>
Thu, 13 Feb 2025 16:51:07 +0000 (16:51 +0000)
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 <sergiu@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1584

lib/posix-process/deprecated.c
lib/posix-process/exportsyms.uk
lib/posix-process/include/uk/process.h

index 91ebe2244110b3e19d12415a8b26ca0ddfd8aa6a..7b4bd48253fb7dd9cf192e3b51bc2e4e366348dc 100644 (file)
@@ -37,6 +37,7 @@
 #include <string.h>
 #include <sys/prctl.h>
 #include <sys/resource.h>
+#include <uk/essentials.h>
 #include <uk/process.h>
 #include <uk/print.h>
 #include <uk/syscall.h>
@@ -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,
index 8b053daa3a5fd69deae571a33e5db617febff762..20908789bb4d18304e79558ff9bd11073f6f5080 100644 (file)
@@ -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
index dd2c1f93a8cceab0306e7e84225bb8c090fd1cc1..3171fb6f063d038a966d1f149bead0a74afea03b 100644 (file)
@@ -37,6 +37,7 @@
 #include <arch/clone.h>
 #include <uk/config.h>
 #include <stdbool.h>
+#include <sys/resource.h>
 #if CONFIG_LIBUKSCHED
 #include <uk/thread.h>
 #endif
 #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,