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.
35 #include <sys/resource.h>
36 #include <sys/times.h>
37 #include <linux/kernel.h>
39 #if HAVE_LONG_LONG_RLIM_T
41 * Hacks for systems that have a long long rlim_t
44 #define rlimit64 rlimit /* Ugly hack */
45 #define rlim64_t rlim_t /* Ugly hack */
46 #ifndef RLIM64_INFINITY
47 #define RLIM64_INFINITY RLIM_INFINITY /* You guessed it */
50 #define sys_getrlimit64 sys_getrlimit
51 #define sys_setrlimit64 sys_setrlimit
54 static const struct xlat resources[] = {
56 { RLIMIT_AS, "RLIMIT_AS" },
59 { RLIMIT_CORE, "RLIMIT_CORE" },
62 { RLIMIT_CPU, "RLIMIT_CPU" },
65 { RLIMIT_DATA, "RLIMIT_DATA" },
68 { RLIMIT_FSIZE, "RLIMIT_FSIZE" },
71 { RLIMIT_LOCKS, "RLIMIT_LOCKS" },
74 { RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK" },
76 #ifdef RLIMIT_MSGQUEUE
77 { RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE" },
80 { RLIMIT_NICE, "RLIMIT_NICE" },
83 { RLIMIT_NOFILE, "RLIMIT_NOFILE" },
86 { RLIMIT_NPROC, "RLIMIT_NPROC" },
89 { RLIMIT_RSS, "RLIMIT_RSS" },
92 { RLIMIT_RTPRIO, "RLIMIT_RTPRIO" },
94 #ifdef RLIMIT_SIGPENDING
95 { RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING" },
98 { RLIMIT_STACK, "RLIMIT_STACK" },
101 { RLIMIT_VMEM, "RLIMIT_VMEM" },
106 #if !HAVE_LONG_LONG_RLIM_T
110 static char buf[sizeof(long)*3 + sizeof("%ld*1024")];
112 if (lim == RLIM_INFINITY)
113 return "RLIM_INFINITY";
115 if (lim > 1024 && lim%1024 == 0)
116 sprintf(buf, "%ld*1024", lim/1024);
118 sprintf(buf, "%ld", lim);
122 # if defined(POWERPC64) || defined(X86_64)
124 print_rlimit32(struct tcb *tcp)
127 unsigned int rlim_cur;
128 unsigned int rlim_max;
131 if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
134 tprintf("{rlim_cur=%s,",
135 sprintrlim(rlim.rlim_cur == -1 ? RLIM_INFINITY
137 tprintf(" rlim_max=%s}",
138 sprintrlim(rlim.rlim_max == -1 ? RLIM_INFINITY
145 sys_getrlimit(struct tcb *tcp)
150 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
154 if (syserror(tcp) || !verbose(tcp))
155 tprintf("%#lx", tcp->u_arg[1]);
156 # if defined(POWERPC64) || defined(X86_64)
157 else if (current_personality == 1)
160 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
163 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
164 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
171 sys_setrlimit(struct tcb *tcp)
176 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
179 tprintf("%#lx", tcp->u_arg[1]);
180 # if defined(POWERPC64) || defined(X86_64)
181 else if (current_personality == 1)
184 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
187 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
188 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
193 #endif /* !HAVE_LONG_LONG_RLIM_T */
195 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_RLIM_T
197 sprintrlim64(rlim64_t lim)
199 static char buf[sizeof(long long)*3 + sizeof("%lld*1024")];
201 if (lim == RLIM64_INFINITY)
202 return "RLIM64_INFINITY";
204 if (lim > 1024 && lim%1024 == 0)
205 sprintf(buf, "%lld*1024", (long long) lim/1024);
207 sprintf(buf, "%lld", (long long) lim);
212 sys_getrlimit64(struct tcb *tcp)
214 struct rlimit64 rlim;
217 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
221 if (syserror(tcp) || !verbose(tcp))
222 tprintf("%#lx", tcp->u_arg[1]);
223 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
226 tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur));
227 tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max));
234 sys_setrlimit64(struct tcb *tcp)
236 struct rlimit64 rlim;
239 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
242 tprintf("%#lx", tcp->u_arg[1]);
243 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
246 tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur));
247 tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max));
252 #endif /* _LFS64_LARGEFILES || HAVE_LONG_LONG_RLIM_T */
254 static const struct xlat usagewho[] = {
255 { RUSAGE_SELF, "RUSAGE_SELF" },
256 { RUSAGE_CHILDREN, "RUSAGE_CHILDREN" },
258 { RUSAGE_BOTH, "RUSAGE_BOTH" },
265 printrusage32(struct tcb *tcp, long addr)
272 struct timeval32 ru_utime; /* user time used */
273 struct timeval32 ru_stime; /* system time used */
274 long ru_maxrss; /* maximum resident set size */
275 long ru_ixrss; /* integral shared memory size */
276 long ru_idrss; /* integral unshared data size */
277 long ru_isrss; /* integral unshared stack size */
278 long ru_minflt; /* page reclaims */
279 long ru_majflt; /* page faults */
280 long ru_nswap; /* swaps */
281 long ru_inblock; /* block input operations */
282 long ru_oublock; /* block output operations */
283 long ru_msgsnd; /* messages sent */
284 long ru_msgrcv; /* messages received */
285 long ru_nsignals; /* signals received */
286 long ru_nvcsw; /* voluntary context switches */
287 long ru_nivcsw; /* involuntary " */
292 else if (syserror(tcp) || !verbose(tcp))
293 tprintf("%#lx", addr);
294 else if (umove(tcp, addr, &ru) < 0)
296 else if (!abbrev(tcp)) {
297 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
298 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
299 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
300 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
301 ru.ru_maxrss, ru.ru_ixrss);
302 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
303 ru.ru_idrss, ru.ru_isrss);
304 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
305 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
306 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
307 ru.ru_inblock, ru.ru_oublock);
308 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
309 ru.ru_msgsnd, ru.ru_msgrcv);
310 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
311 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
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);
322 printrusage(struct tcb *tcp, long addr)
328 else if (syserror(tcp) || !verbose(tcp))
329 tprintf("%#lx", addr);
330 else if (umove(tcp, addr, &ru) < 0)
332 else if (!abbrev(tcp)) {
333 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
334 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
335 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
336 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
337 ru.ru_maxrss, ru.ru_ixrss);
338 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
339 ru.ru_idrss, ru.ru_isrss);
340 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
341 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
342 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
343 ru.ru_inblock, ru.ru_oublock);
344 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
345 ru.ru_msgsnd, ru.ru_msgrcv);
346 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
347 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
350 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
351 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
352 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
357 sys_getrusage(struct tcb *tcp)
360 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
364 printrusage(tcp, tcp->u_arg[1]);
370 sys_osf_getrusage(struct tcb *tcp)
373 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
377 printrusage32(tcp, tcp->u_arg[1]);
383 sys_sysinfo(struct tcb *tcp)
388 if (syserror(tcp) || !verbose(tcp))
389 tprintf("%#lx", tcp->u_arg[0]);
390 else if (umove(tcp, tcp->u_arg[0], &si) < 0)
393 tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ",
394 (long) si.uptime, (long) si.loads[0],
395 (long) si.loads[1], (long) si.loads[2]);
396 tprintf("totalram=%lu, freeram=%lu, ",
397 (long) si.totalram, (long) si.freeram);
398 tprintf("sharedram=%lu, bufferram=%lu} ",
399 (long) si.sharedram, (long) si.bufferram);
400 tprintf("totalswap=%lu, freeswap=%lu, procs=%hu}",
401 (long) si.totalswap, (long) si.freeswap,
408 static const struct xlat priorities[] = {
409 { PRIO_PROCESS, "PRIO_PROCESS" },
410 { PRIO_PGRP, "PRIO_PGRP" },
411 { PRIO_USER, "PRIO_USER" },
416 sys_getpriority(struct tcb *tcp)
419 printxval(priorities, tcp->u_arg[0], "PRIO_???");
420 tprintf(", %lu", tcp->u_arg[1]);
426 sys_setpriority(struct tcb *tcp)
429 printxval(priorities, tcp->u_arg[0], "PRIO_???");
430 tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]);
436 sys_times(struct tcb *tcp)
441 if (tcp->u_arg[0] == 0)
443 else if (syserror(tcp))
444 tprintf("%#lx", tcp->u_arg[0]);
445 else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0)
448 tprintf("{tms_utime=%lu, tms_stime=%lu, ",
449 tbuf.tms_utime, tbuf.tms_stime);
450 tprintf("tms_cutime=%lu, tms_cstime=%lu}",
451 tbuf.tms_cutime, tbuf.tms_cstime);