1 /*
2 * Check decoding of setrlimit syscall.
3 *
4 * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@strace.io>
5 * Copyright (c) 2016-2021 The strace developers.
6 * All rights reserved.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "tests.h"
12 #include "scno.h"
13
14 #ifdef __NR_setrlimit
15
16 # include "xgetrlimit.c"
17
18 int
19 main(void)
20 {
21 kernel_ulong_t *const rlimit = tail_alloc(sizeof(*rlimit) * 2);
22 const struct xlat_data *xlat;
23 size_t i = 0;
24
25 for (xlat = resources->data, i = 0; i < resources->size; ++xlat, ++i) {
26 if (!xlat->str)
27 continue;
28
29 unsigned long res = 0xfacefeed00000000ULL | xlat->val;
30 long rc = syscall(__NR_setrlimit, res, 0);
31 # if XLAT_RAW
32 printf("setrlimit(%#x, NULL) = %s\n",
33 (unsigned int) xlat->val, sprintrc(rc));
34 # elif XLAT_VERBOSE
35 printf("setrlimit(%#x /* %s */, NULL) = %s\n",
36 (unsigned int) xlat->val,
37 xlat->str, sprintrc(rc));
38 # else
39 printf("setrlimit(%s, NULL) = %s\n", xlat->str, sprintrc(rc));
40 # endif
41
42 struct rlimit libc_rlim = {};
43 if (getrlimit((int) res, &libc_rlim))
44 continue;
45 rlimit[0] = libc_rlim.rlim_cur;
46 rlimit[1] = libc_rlim.rlim_max;
47
48 rc = syscall(__NR_setrlimit, res, rlimit);
49 const char *errstr = sprintrc(rc);
50 # if XLAT_RAW
51 printf("setrlimit(%#x, {rlim_cur=%s, rlim_max=%s}) = %s\n",
52 (unsigned int) xlat->val,
53 sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
54 errstr);
55 # elif XLAT_VERBOSE
56 printf("setrlimit(%#x /* %s */,"
57 " {rlim_cur=%s, rlim_max=%s}) = %s\n",
58 (unsigned int) xlat->val, xlat->str,
59 sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
60 errstr);
61 # else
62 printf("setrlimit(%s, {rlim_cur=%s, rlim_max=%s}) = %s\n",
63 xlat->str,
64 sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
65 errstr);
66 # endif
67 }
68
69 puts("+++ exited with 0 +++");
70 return 0;
71 }
72
73 #else
74
75 SKIP_MAIN_UNDEFINED("__NR_setrlimit")
76
77 #endif