blob: 687f8d8861642f2b309555d1024dad88a77fa8f1 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <sys/resource.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000033#include <sys/times.h>
34#include <linux/kernel.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000036#include "xlat/resources.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037
Denys Vlasenko1945ccc2012-02-27 14:37:48 +010038static const char *
Dmitry V. Levinb468f232012-03-16 23:05:21 +040039sprint_rlim64(uint64_t lim)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040{
Dmitry V. Levinb468f232012-03-16 23:05:21 +040041 static char buf[sizeof(uint64_t)*3 + sizeof("*1024")];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042
Dmitry V. Levinb468f232012-03-16 23:05:21 +040043 if (lim == UINT64_MAX)
44 return "RLIM64_INFINITY";
Denys Vlasenko1945ccc2012-02-27 14:37:48 +010045
Dmitry V. Levinb468f232012-03-16 23:05:21 +040046 if (lim > 1024 && lim % 1024 == 0)
47 sprintf(buf, "%" PRIu64 "*1024", lim / 1024);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048 else
Dmitry V. Levinb468f232012-03-16 23:05:21 +040049 sprintf(buf, "%" PRIu64, lim);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000050 return buf;
51}
52
Andreas Schwabee81c8a2010-07-03 23:17:28 +020053static void
Dmitry V. Levinb468f232012-03-16 23:05:21 +040054print_rlimit64(struct tcb *tcp, unsigned long addr)
Andreas Schwabee81c8a2010-07-03 23:17:28 +020055{
Dmitry V. Levinb468f232012-03-16 23:05:21 +040056 struct rlimit_64 {
57 uint64_t rlim_cur;
58 uint64_t rlim_max;
Andreas Schwabee81c8a2010-07-03 23:17:28 +020059 } rlim;
60
Dmitry V. Levinb468f232012-03-16 23:05:21 +040061 if (umove(tcp, addr, &rlim) < 0)
62 tprintf("%#lx", addr);
Andreas Schwabee81c8a2010-07-03 23:17:28 +020063 else {
Dmitry V. Levinb468f232012-03-16 23:05:21 +040064 tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur));
65 tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max));
Andreas Schwabee81c8a2010-07-03 23:17:28 +020066 }
67}
Dmitry V. Levinb468f232012-03-16 23:05:21 +040068
69static void
70decode_rlimit64(struct tcb *tcp, unsigned long addr)
71{
72 if (!addr)
73 tprints("NULL");
74 else if (!verbose(tcp) ||
75 (exiting(tcp) && syserror(tcp)))
76 tprintf("%#lx", addr);
77 else
78 print_rlimit64(tcp, addr);
79}
80
James Hogan3b09ebe2014-05-02 14:15:41 +010081#if !defined(current_wordsize) || current_wordsize == 4
Dmitry V. Levinb468f232012-03-16 23:05:21 +040082
83static const char *
84sprint_rlim32(uint32_t lim)
85{
86 static char buf[sizeof(uint32_t)*3 + sizeof("*1024")];
87
88 if (lim == UINT32_MAX)
89 return "RLIM_INFINITY";
90
91 if (lim > 1024 && lim % 1024 == 0)
92 sprintf(buf, "%" PRIu32 "*1024", lim / 1024);
93 else
94 sprintf(buf, "%" PRIu32, lim);
95 return buf;
96}
97
98static void
99print_rlimit32(struct tcb *tcp, unsigned long addr)
100{
101 struct rlimit_32 {
102 uint32_t rlim_cur;
103 uint32_t rlim_max;
104 } rlim;
105
106 if (umove(tcp, addr, &rlim) < 0)
107 tprintf("%#lx", addr);
108 else {
109 tprintf("{rlim_cur=%s,", sprint_rlim32(rlim.rlim_cur));
110 tprintf(" rlim_max=%s}", sprint_rlim32(rlim.rlim_max));
111 }
112}
113
114static void
115decode_rlimit(struct tcb *tcp, unsigned long addr)
116{
117 if (!addr)
118 tprints("NULL");
Denys Vlasenkoe015d2d2013-02-15 14:58:52 +0100119 else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400120 tprintf("%#lx", addr);
121 else {
James Hogan3b09ebe2014-05-02 14:15:41 +0100122# if defined(X86_64) || defined(X32)
123 /*
124 * i386 is the only personality on X86_64 and X32
125 * with 32-bit rlim_t.
126 * When current_personality is X32, current_wordsize
127 * equals to 4 but rlim_t is 64-bit.
128 */
129 if (current_personality == 1)
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400130# else
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100131 if (current_wordsize == 4)
James Hogan3b09ebe2014-05-02 14:15:41 +0100132# endif
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400133 print_rlimit32(tcp, addr);
134 else
135 print_rlimit64(tcp, addr);
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400136 }
137}
138
James Hogan3b09ebe2014-05-02 14:15:41 +0100139#else /* defined(current_wordsize) && current_wordsize != 4 */
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400140
141# define decode_rlimit decode_rlimit64
142
James Hogan3b09ebe2014-05-02 14:15:41 +0100143#endif
Andreas Schwabee81c8a2010-07-03 23:17:28 +0200144
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000145SYS_FUNC(getrlimit)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147 if (entering(tcp)) {
148 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200149 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150 }
151 else {
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400152 decode_rlimit(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153 }
154 return 0;
155}
156
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000157SYS_FUNC(setrlimit)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000158{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159 if (entering(tcp)) {
160 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200161 tprints(", ");
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400162 decode_rlimit(tcp, tcp->u_arg[1]);
John Hughesbdf48f52001-03-06 15:08:09 +0000163 }
164 return 0;
165}
166
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000167SYS_FUNC(prlimit64)
John Hughesbdf48f52001-03-06 15:08:09 +0000168{
John Hughesbdf48f52001-03-06 15:08:09 +0000169 if (entering(tcp)) {
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400170 tprintf("%ld, ", tcp->u_arg[0]);
171 printxval(resources, tcp->u_arg[1], "RLIMIT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200172 tprints(", ");
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400173 decode_rlimit64(tcp, tcp->u_arg[2]);
174 tprints(", ");
175 } else {
176 decode_rlimit64(tcp, tcp->u_arg[3]);
John Hughesbdf48f52001-03-06 15:08:09 +0000177 }
178 return 0;
179}
John Hughesbdf48f52001-03-06 15:08:09 +0000180
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000181#include "xlat/usagewho.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000183#ifdef ALPHA
184void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000185printrusage32(struct tcb *tcp, long addr)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000186{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000187 struct timeval32 {
188 unsigned tv_sec;
189 unsigned tv_usec;
190 };
191 struct rusage32 {
192 struct timeval32 ru_utime; /* user time used */
193 struct timeval32 ru_stime; /* system time used */
194 long ru_maxrss; /* maximum resident set size */
195 long ru_ixrss; /* integral shared memory size */
196 long ru_idrss; /* integral unshared data size */
197 long ru_isrss; /* integral unshared stack size */
198 long ru_minflt; /* page reclaims */
199 long ru_majflt; /* page faults */
200 long ru_nswap; /* swaps */
201 long ru_inblock; /* block input operations */
202 long ru_oublock; /* block output operations */
203 long ru_msgsnd; /* messages sent */
204 long ru_msgrcv; /* messages received */
205 long ru_nsignals; /* signals received */
206 long ru_nvcsw; /* voluntary context switches */
207 long ru_nivcsw; /* involuntary " */
208 } ru;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000209
Denys Vlasenko1d632462009-04-14 12:51:00 +0000210 if (!addr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200211 tprints("NULL");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000212 else if (syserror(tcp) || !verbose(tcp))
213 tprintf("%#lx", addr);
214 else if (umove(tcp, addr, &ru) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200215 tprints("{...}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000216 else if (!abbrev(tcp)) {
217 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
218 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
219 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
220 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
221 ru.ru_maxrss, ru.ru_ixrss);
222 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
223 ru.ru_idrss, ru.ru_isrss);
224 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
225 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
226 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
227 ru.ru_inblock, ru.ru_oublock);
228 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
229 ru.ru_msgsnd, ru.ru_msgrcv);
230 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
231 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
232 }
233 else {
234 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
235 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
236 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
237 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000238}
239#endif
240
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000241void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000242printrusage(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000243{
244 struct rusage ru;
245
246 if (!addr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200247 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248 else if (syserror(tcp) || !verbose(tcp))
249 tprintf("%#lx", addr);
250 else if (umove(tcp, addr, &ru) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200251 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000252 else if (!abbrev(tcp)) {
253 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
254 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
255 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
256 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
257 ru.ru_maxrss, ru.ru_ixrss);
258 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
259 ru.ru_idrss, ru.ru_isrss);
260 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
261 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
262 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
263 ru.ru_inblock, ru.ru_oublock);
264 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
265 ru.ru_msgsnd, ru.ru_msgrcv);
266 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
267 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
268 }
269 else {
270 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
271 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
272 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
273 }
274}
275
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000276SYS_FUNC(getrusage)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277{
278 if (entering(tcp)) {
279 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200280 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281 }
282 else
283 printrusage(tcp, tcp->u_arg[1]);
284 return 0;
285}
286
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000287#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000288SYS_FUNC(osf_getrusage)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000289{
Denys Vlasenko59432db2009-01-26 19:09:35 +0000290 if (entering(tcp)) {
291 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200292 tprints(", ");
Denys Vlasenko59432db2009-01-26 19:09:35 +0000293 }
294 else
295 printrusage32(tcp, tcp->u_arg[1]);
296 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000297}
298#endif /* ALPHA */
299
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000300#include "xlat/priorities.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000302SYS_FUNC(getpriority)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303{
304 if (entering(tcp)) {
305 printxval(priorities, tcp->u_arg[0], "PRIO_???");
306 tprintf(", %lu", tcp->u_arg[1]);
307 }
308 return 0;
309}
310
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000311SYS_FUNC(setpriority)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312{
313 if (entering(tcp)) {
314 printxval(priorities, tcp->u_arg[0], "PRIO_???");
315 tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]);
316 }
317 return 0;
318}
319
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000320SYS_FUNC(times)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321{
322 struct tms tbuf;
323
324 if (exiting(tcp)) {
325 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200326 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 else if (syserror(tcp))
328 tprintf("%#lx", tcp->u_arg[0]);
329 else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200330 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331 else {
H.J. Lu2bb45812012-04-15 11:17:13 -0700332 tprintf("{tms_utime=%llu, tms_stime=%llu, ",
333 (unsigned long long) tbuf.tms_utime,
334 (unsigned long long) tbuf.tms_stime);
335 tprintf("tms_cutime=%llu, tms_cstime=%llu}",
336 (unsigned long long) tbuf.tms_cutime,
337 (unsigned long long) tbuf.tms_cstime);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338 }
339 }
340 return 0;
341}