Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: fusl/src/misc/setrlimit.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/misc/setpriority.c ('k') | fusl/src/misc/syscall.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/misc/setrlimit.c
diff --git a/fusl/src/misc/setrlimit.c b/fusl/src/misc/setrlimit.c
new file mode 100644
index 0000000000000000000000000000000000000000..7130d719e6fec053ca848590f0ea15712adee9f4
--- /dev/null
+++ b/fusl/src/misc/setrlimit.c
@@ -0,0 +1,50 @@
+#include <sys/resource.h>
+#include <errno.h>
+#include "syscall.h"
+#include "libc.h"
+
+#define MIN(a, b) ((a)<(b) ? (a) : (b))
+#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
+
+int __setrlimit(int resource, const struct rlimit *rlim)
+{
+ unsigned long k_rlim[2];
+ struct rlimit tmp;
+ if (SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
+ tmp = *rlim;
+ FIX(tmp.rlim_cur);
+ FIX(tmp.rlim_max);
+ rlim = &tmp;
+ }
+ int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0);
+ if (ret != -ENOSYS) return ret;
+ k_rlim[0] = MIN(rlim->rlim_cur, MIN(-1UL, SYSCALL_RLIM_INFINITY));
+ k_rlim[1] = MIN(rlim->rlim_max, MIN(-1UL, SYSCALL_RLIM_INFINITY));
+ return __syscall(SYS_setrlimit, resource, k_rlim);
+}
+
+struct ctx {
+ const struct rlimit *rlim;
+ int res;
+ int err;
+};
+
+static void do_setrlimit(void *p)
+{
+ struct ctx *c = p;
+ if (c->err>0) return;
+ c->err = -__setrlimit(c->res, c->rlim);
+}
+
+int setrlimit(int resource, const struct rlimit *rlim)
+{
+ struct ctx c = { .res = resource, .rlim = rlim, .err = -1 };
+ __synccall(do_setrlimit, &c);
+ if (c.err) {
+ if (c.err>0) errno = c.err;
+ return -1;
+ }
+ return 0;
+}
+
+LFS64(setrlimit);
« no previous file with comments | « fusl/src/misc/setpriority.c ('k') | fusl/src/misc/syscall.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698