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>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/resource.h>
33 #include <sys/times.h>
34 #include <linux/kernel.h>
36 #include "xlat/resources.h"
39 sprint_rlim64(uint64_t lim)
41 static char buf[sizeof(uint64_t)*3 + sizeof("*1024")];
43 if (lim == UINT64_MAX)
44 return "RLIM64_INFINITY";
46 if (lim > 1024 && lim % 1024 == 0)
47 sprintf(buf, "%" PRIu64 "*1024", lim / 1024);
49 sprintf(buf, "%" PRIu64, lim);
54 print_rlimit64(struct tcb *tcp, unsigned long addr)
61 if (umove(tcp, addr, &rlim) < 0)
62 tprintf("%#lx", addr);
64 tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur));
65 tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max));
70 decode_rlimit64(struct tcb *tcp, unsigned long addr)
74 else if (!verbose(tcp) ||
75 (exiting(tcp) && syserror(tcp)))
76 tprintf("%#lx", addr);
78 print_rlimit64(tcp, addr);
81 #if !defined(current_wordsize) || current_wordsize == 4
84 sprint_rlim32(uint32_t lim)
86 static char buf[sizeof(uint32_t)*3 + sizeof("*1024")];
88 if (lim == UINT32_MAX)
89 return "RLIM_INFINITY";
91 if (lim > 1024 && lim % 1024 == 0)
92 sprintf(buf, "%" PRIu32 "*1024", lim / 1024);
94 sprintf(buf, "%" PRIu32, lim);
99 print_rlimit32(struct tcb *tcp, unsigned long addr)
106 if (umove(tcp, addr, &rlim) < 0)
107 tprintf("%#lx", addr);
109 tprintf("{rlim_cur=%s,", sprint_rlim32(rlim.rlim_cur));
110 tprintf(" rlim_max=%s}", sprint_rlim32(rlim.rlim_max));
115 decode_rlimit(struct tcb *tcp, unsigned long addr)
119 else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
120 tprintf("%#lx", addr);
122 # if defined(X86_64) || defined(X32)
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.
129 if (current_personality == 1)
131 if (current_wordsize == 4)
133 print_rlimit32(tcp, addr);
135 print_rlimit64(tcp, addr);
139 #else /* defined(current_wordsize) && current_wordsize != 4 */
141 # define decode_rlimit decode_rlimit64
146 sys_getrlimit(struct tcb *tcp)
149 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
153 decode_rlimit(tcp, tcp->u_arg[1]);
159 sys_setrlimit(struct tcb *tcp)
162 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
164 decode_rlimit(tcp, tcp->u_arg[1]);
170 sys_prlimit64(struct tcb *tcp)
173 tprintf("%ld, ", tcp->u_arg[0]);
174 printxval(resources, tcp->u_arg[1], "RLIMIT_???");
176 decode_rlimit64(tcp, tcp->u_arg[2]);
179 decode_rlimit64(tcp, tcp->u_arg[3]);
184 #include "xlat/usagewho.h"
188 printrusage32(struct tcb *tcp, long addr)
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 " */
215 else if (syserror(tcp) || !verbose(tcp))
216 tprintf("%#lx", addr);
217 else if (umove(tcp, addr, &ru) < 0)
219 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);
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);
245 printrusage(struct tcb *tcp, long addr)
251 else if (syserror(tcp) || !verbose(tcp))
252 tprintf("%#lx", addr);
253 else if (umove(tcp, addr, &ru) < 0)
255 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);
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);
280 sys_getrusage(struct tcb *tcp)
283 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
287 printrusage(tcp, tcp->u_arg[1]);
293 sys_osf_getrusage(struct tcb *tcp)
296 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
300 printrusage32(tcp, tcp->u_arg[1]);
305 #include "xlat/priorities.h"
308 sys_getpriority(struct tcb *tcp)
311 printxval(priorities, tcp->u_arg[0], "PRIO_???");
312 tprintf(", %lu", tcp->u_arg[1]);
318 sys_setpriority(struct tcb *tcp)
321 printxval(priorities, tcp->u_arg[0], "PRIO_???");
322 tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]);
328 sys_times(struct tcb *tcp)
333 if (tcp->u_arg[0] == 0)
335 else if (syserror(tcp))
336 tprintf("%#lx", tcp->u_arg[0]);
337 else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0)
340 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);