]> granicus.if.org Git - strace/blob - tests/prlimit64.c
Remove XLAT_END
[strace] / tests / prlimit64.c
1 /*
2  * Check decoding of prlimit64 syscall.
3  *
4  * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
5  * Copyright (c) 2016-2019 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_prlimit64
15
16 # include <inttypes.h>
17 # include <stdio.h>
18 # include <stdint.h>
19 # include <sys/resource.h>
20 # include <unistd.h>
21
22 # include "xlat.h"
23 # include "xlat/resources.h"
24
25 const char *
26 sprint_rlim(uint64_t lim)
27 {
28         if (lim == -1ULL)
29                 return "RLIM64_INFINITY";
30
31         static char buf[2][sizeof(lim)*3 + sizeof("*1024")];
32         static int i;
33         i &= 1;
34         if (lim > 1024 && lim % 1024 == 0)
35                 sprintf(buf[i], "%" PRIu64 "*1024", lim / 1024);
36         else
37                 sprintf(buf[i], "%" PRIu64, lim);
38
39         return buf[i++];
40 }
41
42 int
43 main(void)
44 {
45         unsigned long pid =
46                 (unsigned long) 0xdefaced00000000ULL | (unsigned) getpid();
47         uint64_t *const rlimit = tail_alloc(sizeof(*rlimit) * 2);
48         const struct xlat_data *xlat;
49         size_t i = 0;
50
51         for (xlat = resources->data; i < resources->size; ++xlat, ++i) {
52                 if (!xlat->str)
53                         continue;
54
55                 unsigned long res = 0xfacefeed00000000ULL | xlat->val;
56                 long rc = syscall(__NR_prlimit64, pid, res, 0, rlimit);
57                 if (rc)
58                         printf("prlimit64(%d, %s, NULL, %p) = %ld %s (%m)\n",
59                                (unsigned) pid, xlat->str, rlimit,
60                                rc, errno2name());
61                 else
62                         printf("prlimit64(%d, %s, NULL"
63                                ", {rlim_cur=%s, rlim_max=%s}) = 0\n",
64                                (unsigned) pid, xlat->str,
65                                sprint_rlim(rlimit[0]),
66                                sprint_rlim(rlimit[1]));
67         }
68
69         puts("+++ exited with 0 +++");
70         return 0;
71 }
72
73 #else
74
75 SKIP_MAIN_UNDEFINED("__NR_prlimit64")
76
77 #endif