blob: 57ce17e0023f88ec009b44e9f8106e87961887d1 [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000146sys_getrlimit(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148 if (entering(tcp)) {
149 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200150 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151 }
152 else {
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400153 decode_rlimit(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000154 }
155 return 0;
156}
157
158int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000159sys_setrlimit(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161 if (entering(tcp)) {
162 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200163 tprints(", ");
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400164 decode_rlimit(tcp, tcp->u_arg[1]);
John Hughesbdf48f52001-03-06 15:08:09 +0000165 }
166 return 0;
167}
168
169int
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400170sys_prlimit64(struct tcb *tcp)
John Hughesbdf48f52001-03-06 15:08:09 +0000171{
John Hughesbdf48f52001-03-06 15:08:09 +0000172 if (entering(tcp)) {
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400173 tprintf("%ld, ", tcp->u_arg[0]);
174 printxval(resources, tcp->u_arg[1], "RLIMIT_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200175 tprints(", ");
Dmitry V. Levinb468f232012-03-16 23:05:21 +0400176 decode_rlimit64(tcp, tcp->u_arg[2]);
177 tprints(", ");
178 } else {
179 decode_rlimit64(tcp, tcp->u_arg[3]);
John Hughesbdf48f52001-03-06 15:08:09 +0000180 }
181 return 0;
182}
John Hughesbdf48f52001-03-06 15:08:09 +0000183
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000184#include "xlat/usagewho.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000186#ifdef ALPHA
187void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000188printrusage32(struct tcb *tcp, long addr)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000189{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000190 struct timeval32 {
191 unsigned tv_sec;
192 unsigned tv_usec;
193 };
194 struct rusage32 {
195 struct timeval32 ru_utime; /* user time used */
196 struct timeval32 ru_stime; /* system time used */
197 long ru_maxrss; /* maximum resident set size */
198 long ru_ixrss; /* integral shared memory size */
199 long ru_idrss; /* integral unshared data size */
200 long ru_isrss; /* integral unshared stack size */
201 long ru_minflt; /* page reclaims */
202 long ru_majflt; /* page faults */
203 long ru_nswap; /* swaps */
204 long ru_inblock; /* block input operations */
205 long ru_oublock; /* block output operations */
206 long ru_msgsnd; /* messages sent */
207 long ru_msgrcv; /* messages received */
208 long ru_nsignals; /* signals received */
209 long ru_nvcsw; /* voluntary context switches */
210 long ru_nivcsw; /* involuntary " */
211 } ru;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000212
Denys Vlasenko1d632462009-04-14 12:51:00 +0000213 if (!addr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200214 tprints("NULL");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000215 else if (syserror(tcp) || !verbose(tcp))
216 tprintf("%#lx", addr);
217 else if (umove(tcp, addr, &ru) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200218 tprints("{...}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000219 else if (!abbrev(tcp)) {
220 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
221 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
222 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
223 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
224 ru.ru_maxrss, ru.ru_ixrss);
225 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
226 ru.ru_idrss, ru.ru_isrss);
227 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
228 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
229 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
230 ru.ru_inblock, ru.ru_oublock);
231 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
232 ru.ru_msgsnd, ru.ru_msgrcv);
233 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
234 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
235 }
236 else {
237 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
238 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
239 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
240 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000241}
242#endif
243
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000244void
Denys Vlasenko1d632462009-04-14 12:51:00 +0000245printrusage(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000246{
247 struct rusage ru;
248
249 if (!addr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200250 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251 else if (syserror(tcp) || !verbose(tcp))
252 tprintf("%#lx", addr);
253 else if (umove(tcp, addr, &ru) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200254 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000255 else if (!abbrev(tcp)) {
256 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
257 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
258 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
259 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
260 ru.ru_maxrss, ru.ru_ixrss);
261 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
262 ru.ru_idrss, ru.ru_isrss);
263 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
264 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
265 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
266 ru.ru_inblock, ru.ru_oublock);
267 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
268 ru.ru_msgsnd, ru.ru_msgrcv);
269 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
270 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
271 }
272 else {
273 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
274 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
275 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
276 }
277}
278
279int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000280sys_getrusage(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281{
282 if (entering(tcp)) {
283 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200284 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285 }
286 else
287 printrusage(tcp, tcp->u_arg[1]);
288 return 0;
289}
290
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000291#ifdef ALPHA
292int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000293sys_osf_getrusage(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000294{
Denys Vlasenko59432db2009-01-26 19:09:35 +0000295 if (entering(tcp)) {
296 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200297 tprints(", ");
Denys Vlasenko59432db2009-01-26 19:09:35 +0000298 }
299 else
300 printrusage32(tcp, tcp->u_arg[1]);
301 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000302}
303#endif /* ALPHA */
304
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000305#include "xlat/priorities.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306
307int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000308sys_getpriority(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309{
310 if (entering(tcp)) {
311 printxval(priorities, tcp->u_arg[0], "PRIO_???");
312 tprintf(", %lu", tcp->u_arg[1]);
313 }
314 return 0;
315}
316
317int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000318sys_setpriority(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319{
320 if (entering(tcp)) {
321 printxval(priorities, tcp->u_arg[0], "PRIO_???");
322 tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]);
323 }
324 return 0;
325}
326
327int
Denys Vlasenko1d632462009-04-14 12:51:00 +0000328sys_times(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329{
330 struct tms tbuf;
331
332 if (exiting(tcp)) {
333 if (tcp->u_arg[0] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200334 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000335 else if (syserror(tcp))
336 tprintf("%#lx", tcp->u_arg[0]);
337 else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200338 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000339 else {
H.J. Lu2bb45812012-04-15 11:17:13 -0700340 tprintf("{tms_utime=%llu, tms_stime=%llu, ",
341 (unsigned long long) tbuf.tms_utime,
342 (unsigned long long) tbuf.tms_stime);
343 tprintf("tms_cutime=%llu, tms_cstime=%llu}",
344 (unsigned long long) tbuf.tms_cutime,
345 (unsigned long long) tbuf.tms_cstime);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000346 }
347 }
348 return 0;
349}