2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 1999-2019 The strace developers.
9 * SPDX-License-Identifier: LGPL-2.1-or-later
13 #include <sys/resource.h>
17 #include "xlat/resources.h"
20 print_rlim64_t(uint64_t lim) {
21 const char *str = NULL;
23 if (lim == UINT64_MAX)
24 str = "RLIM64_INFINITY";
25 else if (lim > 1024 && lim % 1024 == 0) {
26 static char buf[sizeof(lim) * 3 + sizeof("*1024")];
28 xsprintf(buf, "%" PRIu64 "*1024", lim / 1024);
32 if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
33 tprintf("%" PRIu64, lim);
35 if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
38 (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
39 ? tprints_comment : tprints)(str);
43 print_rlimit64(struct tcb *const tcp, const kernel_ulong_t addr)
50 if (!umove_or_printaddr(tcp, addr, &rlim)) {
51 tprints("{rlim_cur=");
52 print_rlim64_t(rlim.rlim_cur);
53 tprints(", rlim_max=");
54 print_rlim64_t(rlim.rlim_max);
59 #if !defined(current_wordsize) || current_wordsize == 4
62 print_rlim32_t(uint32_t lim) {
63 const char *str = NULL;
65 if (lim == UINT32_MAX)
66 str = "RLIM_INFINITY";
67 else if (lim > 1024 && lim % 1024 == 0) {
68 static char buf[sizeof(lim) * 3 + sizeof("*1024")];
70 xsprintf(buf, "%" PRIu32 "*1024", lim / 1024);
74 if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
75 tprintf("%" PRIu32, lim);
77 if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
80 (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
81 ? tprints_comment : tprints)(str);
85 print_rlimit32(struct tcb *const tcp, const kernel_ulong_t addr)
92 if (!umove_or_printaddr(tcp, addr, &rlim)) {
93 tprints("{rlim_cur=");
94 print_rlim32_t(rlim.rlim_cur);
95 tprints(", rlim_max=");
96 print_rlim32_t(rlim.rlim_max);
102 decode_rlimit(struct tcb *const tcp, const kernel_ulong_t addr)
105 * i386 is the only personality on X86_64 and X32
106 * with 32-bit rlim_t.
107 * When current_personality is X32, current_wordsize
108 * equals to 4 but rlim_t is 64-bit.
110 if (current_klongsize == 4)
111 print_rlimit32(tcp, addr);
113 print_rlimit64(tcp, addr);
116 #else /* defined(current_wordsize) && current_wordsize != 4 */
118 # define decode_rlimit print_rlimit64
125 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
128 decode_rlimit(tcp, tcp->u_arg[1]);
135 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
137 decode_rlimit(tcp, tcp->u_arg[1]);
145 tprintf("%d, ", (int) tcp->u_arg[0]);
146 printxval(resources, tcp->u_arg[1], "RLIMIT_???");
148 print_rlimit64(tcp, tcp->u_arg[2]);
151 print_rlimit64(tcp, tcp->u_arg[3]);
156 #include "xlat/usagewho.h"
161 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
164 printrusage(tcp, tcp->u_arg[1]);
169 SYS_FUNC(osf_getrusage)
172 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
175 printrusage32(tcp, tcp->u_arg[1]);
180 #include "xlat/priorities.h"
182 SYS_FUNC(getpriority)
184 printxval(priorities, tcp->u_arg[0], "PRIO_???");
185 tprintf(", %d", (int) tcp->u_arg[1]);
190 SYS_FUNC(setpriority)
192 printxval(priorities, tcp->u_arg[0], "PRIO_???");
193 tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);