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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « fusl/src/misc/setpriority.c ('k') | fusl/src/misc/syscall.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <sys/resource.h>
2 #include <errno.h>
3 #include "syscall.h"
4 #include "libc.h"
5
6 #define MIN(a, b) ((a)<(b) ? (a) : (b))
7 #define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
8
9 int __setrlimit(int resource, const struct rlimit *rlim)
10 {
11 unsigned long k_rlim[2];
12 struct rlimit tmp;
13 if (SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
14 tmp = *rlim;
15 FIX(tmp.rlim_cur);
16 FIX(tmp.rlim_max);
17 rlim = &tmp;
18 }
19 int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0);
20 if (ret != -ENOSYS) return ret;
21 k_rlim[0] = MIN(rlim->rlim_cur, MIN(-1UL, SYSCALL_RLIM_INFINITY));
22 k_rlim[1] = MIN(rlim->rlim_max, MIN(-1UL, SYSCALL_RLIM_INFINITY));
23 return __syscall(SYS_setrlimit, resource, k_rlim);
24 }
25
26 struct ctx {
27 const struct rlimit *rlim;
28 int res;
29 int err;
30 };
31
32 static void do_setrlimit(void *p)
33 {
34 struct ctx *c = p;
35 if (c->err>0) return;
36 c->err = -__setrlimit(c->res, c->rlim);
37 }
38
39 int setrlimit(int resource, const struct rlimit *rlim)
40 {
41 struct ctx c = { .res = resource, .rlim = rlim, .err = -1 };
42 __synccall(do_setrlimit, &c);
43 if (c.err) {
44 if (c.err>0) errno = c.err;
45 return -1;
46 }
47 return 0;
48 }
49
50 LFS64(setrlimit);
OLDNEW
« 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