summaryrefslogtreecommitdiffstats
path: root/tools/include
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2023-11-22 23:49:43 +0100
committerThomas Weißschuh <linux@weissschuh.net>2023-12-11 22:38:35 +0100
commita0bb5f88fc3d72bc92c24a631f2c7794362efac1 (patch)
tree8b79d1296b139f9e9b92e546c9e71f68a67d0072 /tools/include
parent7b20478b777c3be39a2b69b08a6c0b50c10105f1 (diff)
downloadlinux-a0bb5f88fc3d72bc92c24a631f2c7794362efac1.tar.gz
linux-a0bb5f88fc3d72bc92c24a631f2c7794362efac1.tar.bz2
linux-a0bb5f88fc3d72bc92c24a631f2c7794362efac1.zip
tools/nolibc: add support for getrlimit/setrlimit
The implementation uses the prlimit64 systemcall as that is available on all architectures. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://lore.kernel.org/lkml/20231123-nolibc-rlimit-v1-2-a428b131de2a@weissschuh.net/ Acked-by: Willy Tarreau <w@1wt.eu>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/nolibc/sys.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index 2f359cb03d10..dda9dffd1d74 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -21,6 +21,7 @@
#include <linux/fcntl.h> /* for O_* and AT_* */
#include <linux/stat.h> /* for statx() */
#include <linux/prctl.h>
+#include <linux/resource.h>
#include "arch.h"
#include "errno.h"
@@ -899,6 +900,43 @@ int reboot(int cmd)
/*
+ * int getrlimit(int resource, struct rlimit *rlim);
+ * int setrlimit(int resource, const struct rlimit *rlim);
+ */
+
+static __attribute__((unused))
+int sys_prlimit64(pid_t pid, int resource,
+ const struct rlimit64 *new_limit, struct rlimit64 *old_limit)
+{
+ return my_syscall4(__NR_prlimit64, pid, resource, new_limit, old_limit);
+}
+
+static __attribute__((unused))
+int getrlimit(int resource, struct rlimit *rlim)
+{
+ struct rlimit64 rlim64;
+ int ret;
+
+ ret = __sysret(sys_prlimit64(0, resource, NULL, &rlim64));
+ rlim->rlim_cur = rlim64.rlim_cur;
+ rlim->rlim_max = rlim64.rlim_max;
+
+ return ret;
+}
+
+static __attribute__((unused))
+int setrlimit(int resource, const struct rlimit *rlim)
+{
+ struct rlimit64 rlim64 = {
+ .rlim_cur = rlim->rlim_cur,
+ .rlim_max = rlim->rlim_max,
+ };
+
+ return __sysret(sys_prlimit64(0, resource, &rlim64, NULL));
+}
+
+
+/*
* int sched_yield(void);
*/