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 static const struct xlat resources[] = {
58 #ifdef RLIMIT_MSGQUEUE
59 XLAT(RLIMIT_MSGQUEUE),
79 #ifdef RLIMIT_SIGPENDING
80 XLAT(RLIMIT_SIGPENDING),
91 #if !(SIZEOF_RLIM_T == 4 || SIZEOF_RLIM_T == 8)
92 # error "Unsupported SIZEOF_RLIM_T value"
96 sprint_rlim64(uint64_t lim)
98 static char buf[sizeof(uint64_t)*3 + sizeof("*1024")];
100 if (lim == UINT64_MAX)
101 return "RLIM64_INFINITY";
103 if (lim > 1024 && lim % 1024 == 0)
104 sprintf(buf, "%" PRIu64 "*1024", lim / 1024);
106 sprintf(buf, "%" PRIu64, lim);
111 print_rlimit64(struct tcb *tcp, unsigned long addr)
118 if (umove(tcp, addr, &rlim) < 0)
119 tprintf("%#lx", addr);
121 tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur));
122 tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max));
127 decode_rlimit64(struct tcb *tcp, unsigned long addr)
131 else if (!verbose(tcp) ||
132 (exiting(tcp) && syserror(tcp)))
133 tprintf("%#lx", addr);
135 print_rlimit64(tcp, addr);
138 #if SIZEOF_RLIM_T == 4 || SUPPORTED_PERSONALITIES > 1
141 sprint_rlim32(uint32_t lim)
143 static char buf[sizeof(uint32_t)*3 + sizeof("*1024")];
145 if (lim == UINT32_MAX)
146 return "RLIM_INFINITY";
148 if (lim > 1024 && lim % 1024 == 0)
149 sprintf(buf, "%" PRIu32 "*1024", lim / 1024);
151 sprintf(buf, "%" PRIu32, lim);
156 print_rlimit32(struct tcb *tcp, unsigned long addr)
163 if (umove(tcp, addr, &rlim) < 0)
164 tprintf("%#lx", addr);
166 tprintf("{rlim_cur=%s,", sprint_rlim32(rlim.rlim_cur));
167 tprintf(" rlim_max=%s}", sprint_rlim32(rlim.rlim_max));
172 decode_rlimit(struct tcb *tcp, unsigned long addr)
176 else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
177 tprintf("%#lx", addr);
179 # if SIZEOF_RLIM_T == 4
180 print_rlimit32(tcp, addr);
182 if (current_wordsize == 4)
183 print_rlimit32(tcp, addr);
185 print_rlimit64(tcp, addr);
190 #else /* SIZEOF_RLIM_T == 8 && SUPPORTED_PERSONALITIES == 1 */
192 # define decode_rlimit decode_rlimit64
194 #endif /* SIZEOF_RLIM_T == 4 || SUPPORTED_PERSONALITIES > 1 */
197 sys_getrlimit(struct tcb *tcp)
200 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
204 decode_rlimit(tcp, tcp->u_arg[1]);
210 sys_setrlimit(struct tcb *tcp)
213 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
215 decode_rlimit(tcp, tcp->u_arg[1]);
221 sys_prlimit64(struct tcb *tcp)
224 tprintf("%ld, ", tcp->u_arg[0]);
225 printxval(resources, tcp->u_arg[1], "RLIMIT_???");
227 decode_rlimit64(tcp, tcp->u_arg[2]);
230 decode_rlimit64(tcp, tcp->u_arg[3]);
235 static const struct xlat usagewho[] = {
237 XLAT(RUSAGE_CHILDREN),
246 printrusage32(struct tcb *tcp, long addr)
253 struct timeval32 ru_utime; /* user time used */
254 struct timeval32 ru_stime; /* system time used */
255 long ru_maxrss; /* maximum resident set size */
256 long ru_ixrss; /* integral shared memory size */
257 long ru_idrss; /* integral unshared data size */
258 long ru_isrss; /* integral unshared stack size */
259 long ru_minflt; /* page reclaims */
260 long ru_majflt; /* page faults */
261 long ru_nswap; /* swaps */
262 long ru_inblock; /* block input operations */
263 long ru_oublock; /* block output operations */
264 long ru_msgsnd; /* messages sent */
265 long ru_msgrcv; /* messages received */
266 long ru_nsignals; /* signals received */
267 long ru_nvcsw; /* voluntary context switches */
268 long ru_nivcsw; /* involuntary " */
273 else if (syserror(tcp) || !verbose(tcp))
274 tprintf("%#lx", addr);
275 else if (umove(tcp, addr, &ru) < 0)
277 else if (!abbrev(tcp)) {
278 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
279 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
280 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
281 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
282 ru.ru_maxrss, ru.ru_ixrss);
283 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
284 ru.ru_idrss, ru.ru_isrss);
285 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
286 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
287 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
288 ru.ru_inblock, ru.ru_oublock);
289 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
290 ru.ru_msgsnd, ru.ru_msgrcv);
291 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
292 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
295 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
296 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
297 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
303 printrusage(struct tcb *tcp, long addr)
309 else if (syserror(tcp) || !verbose(tcp))
310 tprintf("%#lx", addr);
311 else if (umove(tcp, addr, &ru) < 0)
313 else if (!abbrev(tcp)) {
314 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
315 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
316 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
317 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
318 ru.ru_maxrss, ru.ru_ixrss);
319 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
320 ru.ru_idrss, ru.ru_isrss);
321 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
322 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
323 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
324 ru.ru_inblock, ru.ru_oublock);
325 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
326 ru.ru_msgsnd, ru.ru_msgrcv);
327 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
328 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
331 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
332 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
333 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
338 sys_getrusage(struct tcb *tcp)
341 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
345 printrusage(tcp, tcp->u_arg[1]);
351 sys_osf_getrusage(struct tcb *tcp)
354 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
358 printrusage32(tcp, tcp->u_arg[1]);
364 sys_sysinfo(struct tcb *tcp)
369 if (syserror(tcp) || !verbose(tcp))
370 tprintf("%#lx", tcp->u_arg[0]);
371 else if (umove(tcp, tcp->u_arg[0], &si) < 0)
374 tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ",
375 (long) si.uptime, (long) si.loads[0],
376 (long) si.loads[1], (long) si.loads[2]);
377 tprintf("totalram=%lu, freeram=%lu, ",
378 (long) si.totalram, (long) si.freeram);
379 tprintf("sharedram=%lu, bufferram=%lu} ",
380 (long) si.sharedram, (long) si.bufferram);
381 tprintf("totalswap=%lu, freeswap=%lu, procs=%u}",
382 (long) si.totalswap, (long) si.freeswap,
389 static const struct xlat priorities[] = {
397 sys_getpriority(struct tcb *tcp)
400 printxval(priorities, tcp->u_arg[0], "PRIO_???");
401 tprintf(", %lu", tcp->u_arg[1]);
407 sys_setpriority(struct tcb *tcp)
410 printxval(priorities, tcp->u_arg[0], "PRIO_???");
411 tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]);
417 sys_times(struct tcb *tcp)
422 if (tcp->u_arg[0] == 0)
424 else if (syserror(tcp))
425 tprintf("%#lx", tcp->u_arg[0]);
426 else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0)
429 tprintf("{tms_utime=%llu, tms_stime=%llu, ",
430 (unsigned long long) tbuf.tms_utime,
431 (unsigned long long) tbuf.tms_stime);
432 tprintf("tms_cutime=%llu, tms_cstime=%llu}",
433 (unsigned long long) tbuf.tms_cutime,
434 (unsigned long long) tbuf.tms_cstime);