]> granicus.if.org Git - strace/blob - resource.c
xlat: provide fallback definitions for XDP_FLAGS_* constants
[strace] / resource.c
1 /*
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.
7  * All rights reserved.
8  *
9  * SPDX-License-Identifier: LGPL-2.1-or-later
10  */
11
12 #include "defs.h"
13 #include <sys/resource.h>
14
15 #include "xstring.h"
16
17 #include "xlat/resources.h"
18
19 static void
20 print_rlim64_t(uint64_t lim) {
21         const char *str = NULL;
22
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")];
27
28                 xsprintf(buf, "%" PRIu64 "*1024", lim / 1024);
29                 str = buf;
30         }
31
32         if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
33                 tprintf("%" PRIu64, lim);
34
35         if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
36                 return;
37
38         (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
39                 ? tprints_comment : tprints)(str);
40 }
41
42 static void
43 print_rlimit64(struct tcb *const tcp, const kernel_ulong_t addr)
44 {
45         struct rlimit_64 {
46                 uint64_t rlim_cur;
47                 uint64_t rlim_max;
48         } rlim;
49
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);
55                 tprints("}");
56         }
57 }
58
59 #if !defined(current_wordsize) || current_wordsize == 4
60
61 static void
62 print_rlim32_t(uint32_t lim) {
63         const char *str = NULL;
64
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")];
69
70                 xsprintf(buf, "%" PRIu32 "*1024", lim / 1024);
71                 str = buf;
72         }
73
74         if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
75                 tprintf("%" PRIu32, lim);
76
77         if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
78                 return;
79
80         (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
81                 ? tprints_comment : tprints)(str);
82 }
83
84 static void
85 print_rlimit32(struct tcb *const tcp, const kernel_ulong_t addr)
86 {
87         struct rlimit_32 {
88                 uint32_t rlim_cur;
89                 uint32_t rlim_max;
90         } rlim;
91
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);
97                 tprints("}");
98         }
99 }
100
101 static void
102 decode_rlimit(struct tcb *const tcp, const kernel_ulong_t addr)
103 {
104         /*
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.
109          */
110         if (current_klongsize == 4)
111                 print_rlimit32(tcp, addr);
112         else
113                 print_rlimit64(tcp, addr);
114 }
115
116 #else /* defined(current_wordsize) && current_wordsize != 4 */
117
118 # define decode_rlimit print_rlimit64
119
120 #endif
121
122 SYS_FUNC(getrlimit)
123 {
124         if (entering(tcp)) {
125                 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
126                 tprints(", ");
127         } else {
128                 decode_rlimit(tcp, tcp->u_arg[1]);
129         }
130         return 0;
131 }
132
133 SYS_FUNC(setrlimit)
134 {
135         printxval(resources, tcp->u_arg[0], "RLIMIT_???");
136         tprints(", ");
137         decode_rlimit(tcp, tcp->u_arg[1]);
138
139         return RVAL_DECODED;
140 }
141
142 SYS_FUNC(prlimit64)
143 {
144         if (entering(tcp)) {
145                 tprintf("%d, ", (int) tcp->u_arg[0]);
146                 printxval(resources, tcp->u_arg[1], "RLIMIT_???");
147                 tprints(", ");
148                 print_rlimit64(tcp, tcp->u_arg[2]);
149                 tprints(", ");
150         } else {
151                 print_rlimit64(tcp, tcp->u_arg[3]);
152         }
153         return 0;
154 }
155
156 #include "xlat/usagewho.h"
157
158 SYS_FUNC(getrusage)
159 {
160         if (entering(tcp)) {
161                 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
162                 tprints(", ");
163         } else
164                 printrusage(tcp, tcp->u_arg[1]);
165         return 0;
166 }
167
168 #ifdef ALPHA
169 SYS_FUNC(osf_getrusage)
170 {
171         if (entering(tcp)) {
172                 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
173                 tprints(", ");
174         } else
175                 printrusage32(tcp, tcp->u_arg[1]);
176         return 0;
177 }
178 #endif /* ALPHA */
179
180 #include "xlat/priorities.h"
181
182 SYS_FUNC(getpriority)
183 {
184         printxval(priorities, tcp->u_arg[0], "PRIO_???");
185         tprintf(", %d", (int) tcp->u_arg[1]);
186
187         return RVAL_DECODED;
188 }
189
190 SYS_FUNC(setpriority)
191 {
192         printxval(priorities, tcp->u_arg[0], "PRIO_???");
193         tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);
194
195         return RVAL_DECODED;
196 }