2 * Check decoding of getrlimit/ugetrlimit syscall.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include <sys/resource.h>
17 #include "xlat/resources.h"
20 sprint_rlim(kernel_ulong_t lim)
22 if (sizeof(lim) == sizeof(uint64_t)) {
23 if (lim == (kernel_ulong_t) -1ULL)
24 return "RLIM64_INFINITY";
26 if (lim == (kernel_ulong_t) -1U)
27 return "RLIM_INFINITY";
30 static char buf[2][sizeof(lim)*3 + sizeof("*1024")];
33 if (lim > 1024 && lim % 1024 == 0)
34 sprintf(buf[i], "%llu*1024", (unsigned long long) lim / 1024);
36 sprintf(buf[i], "%llu", (unsigned long long) lim);
46 kernel_ulong_t *const rlimit = tail_alloc(sizeof(*rlimit) * 2);
47 const struct xlat *xlat;
49 for (xlat = resources; xlat->str; ++xlat) {
50 unsigned long res = 0xfacefeed00000000ULL | xlat->val;
51 long rc = syscall(NR_GETRLIMIT, res, 0);
52 if (rc && ENOSYS == errno)
53 perror_msg_and_skip(STR_GETRLIMIT);
54 printf("%s(%s, NULL) = %ld %s (%m)\n",
55 STR_GETRLIMIT, xlat->str, rc, errno2name());
57 rc = syscall(NR_GETRLIMIT, res, rlimit);
59 printf("%s(%s, NULL) = %ld %s (%m)\n",
60 STR_GETRLIMIT, xlat->str, rc, errno2name());
62 printf("%s(%s, {rlim_cur=%s, rlim_max=%s})"
63 " = 0\n", STR_GETRLIMIT, xlat->str,
64 sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]));
67 puts("+++ exited with 0 +++");
71 #endif /* NR_GETRLIMIT */