blob: 7607a7e1d695662582b37e92a85c0ee71f665457 [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.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <sys/resource.h>
36#ifdef LINUX
37#include <sys/times.h>
38#include <linux/kernel.h>
39#endif /* LINUX */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000040#if defined(SVR4) || defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041#include <sys/times.h>
42#include <sys/time.h>
43#endif
44
John Hughes70623be2001-03-08 13:59:00 +000045#if HAVE_LONG_LONG_RLIM_T
46/*
47 * Hacks for systems that have a long long rlim_t
48 */
49
50#define rlimit64 rlimit /* Ugly hack */
51#define rlim64_t rlim_t /* Ugly hack */
52#define RLIM64_INFINITY RLIM_INFINITY /* You guessed it */
53
54#define sys_getrlimit64 sys_getrlimit
55#define sys_setrlimit64 sys_setrlimit
56#endif
57
Roland McGrathd9f816f2004-09-04 03:39:20 +000058static const struct xlat resources[] = {
Roland McGrath70d99092005-12-02 04:08:27 +000059#ifdef RLIMIT_AS
60 { RLIMIT_AS, "RLIMIT_AS" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000061#endif
62#ifdef RLIMIT_CORE
63 { RLIMIT_CORE, "RLIMIT_CORE" },
64#endif
Roland McGrath70d99092005-12-02 04:08:27 +000065#ifdef RLIMIT_CPU
66 { RLIMIT_CPU, "RLIMIT_CPU" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000067#endif
Roland McGrath70d99092005-12-02 04:08:27 +000068#ifdef RLIMIT_DATA
69 { RLIMIT_DATA, "RLIMIT_DATA" },
Wichert Akkermanc7926982000-04-10 22:22:31 +000070#endif
Roland McGrath70d99092005-12-02 04:08:27 +000071#ifdef RLIMIT_FSIZE
72 { RLIMIT_FSIZE, "RLIMIT_FSIZE" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073#endif
Roland McGrath566ce1f2004-10-06 22:14:53 +000074#ifdef RLIMIT_LOCKS
75 { RLIMIT_LOCKS, "RLIMIT_LOCKS" },
76#endif
Roland McGrath70d99092005-12-02 04:08:27 +000077#ifdef RLIMIT_MEMLOCK
78 { RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK" },
Roland McGrath566ce1f2004-10-06 22:14:53 +000079#endif
80#ifdef RLIMIT_MSGQUEUE
81 { RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE" },
82#endif
Roland McGrath70d99092005-12-02 04:08:27 +000083#ifdef RLIMIT_NICE
84 { RLIMIT_NICE, "RLIMIT_NICE" },
85#endif
86#ifdef RLIMIT_NOFILE
87 { RLIMIT_NOFILE, "RLIMIT_NOFILE" },
88#endif
89#ifdef RLIMIT_NPROC
90 { RLIMIT_NPROC, "RLIMIT_NPROC" },
91#endif
92#ifdef RLIMIT_RSS
93 { RLIMIT_RSS, "RLIMIT_RSS" },
94#endif
95#ifdef RLIMIT_RTPRIO
96 { RLIMIT_RTPRIO, "RLIMIT_RTPRIO" },
97#endif
98#ifdef RLIMIT_SIGPENDING
99 { RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING" },
100#endif
101#ifdef RLIMIT_STACK
102 { RLIMIT_STACK, "RLIMIT_STACK" },
103#endif
104#ifdef RLIMIT_VMEM
105 { RLIMIT_VMEM, "RLIMIT_VMEM" },
106#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000107 { 0, NULL },
108};
109
John Hughes70623be2001-03-08 13:59:00 +0000110#if !HAVE_LONG_LONG_RLIM_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000111static char *
112sprintrlim(lim)
113long lim;
114{
115 static char buf[32];
116
117 if (lim == RLIM_INFINITY)
118 sprintf(buf, "RLIM_INFINITY");
119 else if (lim > 1024 && lim%1024 == 0)
120 sprintf(buf, "%ld*1024", lim/1024);
121 else
122 sprintf(buf, "%ld", lim);
123 return buf;
124}
125
126int
127sys_getrlimit(tcp)
128struct tcb *tcp;
129{
130 struct rlimit rlim;
131
132 if (entering(tcp)) {
133 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
134 tprintf(", ");
135 }
136 else {
137 if (syserror(tcp) || !verbose(tcp))
138 tprintf("%#lx", tcp->u_arg[1]);
139 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
140 tprintf("{...}");
141 else {
142 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
143 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
144 }
145 }
146 return 0;
147}
148
149int
150sys_setrlimit(tcp)
151struct tcb *tcp;
152{
153 struct rlimit rlim;
154
155 if (entering(tcp)) {
156 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
157 tprintf(", ");
158 if (!verbose(tcp))
159 tprintf("%#lx", tcp->u_arg[1]);
160 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
161 tprintf("{...}");
162 else {
163 tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur));
164 tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max));
165 }
166 }
167 return 0;
168}
John Hughes70623be2001-03-08 13:59:00 +0000169#endif /* !HAVE_LONG_LONG_RLIM_T */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000170
John Hughes70623be2001-03-08 13:59:00 +0000171#if _LFS64_LARGEFILE || HAVE_LONG_LONG_RLIM_T
John Hughesbdf48f52001-03-06 15:08:09 +0000172static char *
173sprintrlim64(lim)
174rlim64_t lim;
175{
176 static char buf[64];
177
178 if (lim == RLIM64_INFINITY)
179 sprintf(buf, "RLIM64_INFINITY");
180 else if (lim > 1024 && lim%1024 == 0)
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000181 sprintf(buf, "%lld*1024", (long long) lim/1024);
John Hughesbdf48f52001-03-06 15:08:09 +0000182 else
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000183 sprintf(buf, "%lld", (long long) lim);
John Hughesbdf48f52001-03-06 15:08:09 +0000184 return buf;
185}
186
187int
188sys_getrlimit64(tcp)
189struct tcb *tcp;
190{
191 struct rlimit64 rlim;
192
193 if (entering(tcp)) {
194 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
195 tprintf(", ");
196 }
197 else {
198 if (syserror(tcp) || !verbose(tcp))
199 tprintf("%#lx", tcp->u_arg[1]);
200 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
201 tprintf("{...}");
202 else {
203 tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur));
204 tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max));
205 }
206 }
207 return 0;
208}
209
210int
211sys_setrlimit64(tcp)
212struct tcb *tcp;
213{
214 struct rlimit64 rlim;
215
216 if (entering(tcp)) {
217 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
218 tprintf(", ");
219 if (!verbose(tcp))
220 tprintf("%#lx", tcp->u_arg[1]);
221 else if (umove(tcp, tcp->u_arg[1], &rlim) < 0)
222 tprintf("{...}");
223 else {
224 tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur));
225 tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max));
226 }
227 }
228 return 0;
229}
John Hughes70623be2001-03-08 13:59:00 +0000230#endif /* _LFS64_LARGEFILES || HAVE_LONG_LONG_RLIM_T */
John Hughesbdf48f52001-03-06 15:08:09 +0000231
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000232#ifndef SVR4
233
Roland McGrathd9f816f2004-09-04 03:39:20 +0000234static const struct xlat usagewho[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000235 { RUSAGE_SELF, "RUSAGE_SELF" },
236 { RUSAGE_CHILDREN, "RUSAGE_CHILDREN" },
Wichert Akkermanc7926982000-04-10 22:22:31 +0000237#ifdef RUSAGE_BOTH
238 { RUSAGE_BOTH, "RUSAGE_BOTH" },
239#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000240 { 0, NULL },
241};
242
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000243#ifdef ALPHA
244void
245printrusage32(tcp, addr)
246struct tcb *tcp;
247long addr;
248{
249 struct timeval32
250 {
251 unsigned tv_sec;
252 unsigned tv_usec;
253 };
254 struct rusage32
255 {
256 struct timeval32 ru_utime; /* user time used */
257 struct timeval32 ru_stime; /* system time used */
258 long ru_maxrss; /* maximum resident set size */
259 long ru_ixrss; /* integral shared memory size */
260 long ru_idrss; /* integral unshared data size */
261 long ru_isrss; /* integral unshared stack size */
262 long ru_minflt; /* page reclaims */
263 long ru_majflt; /* page faults */
264 long ru_nswap; /* swaps */
265 long ru_inblock; /* block input operations */
266 long ru_oublock; /* block output operations */
267 long ru_msgsnd; /* messages sent */
268 long ru_msgrcv; /* messages received */
269 long ru_nsignals; /* signals received */
270 long ru_nvcsw; /* voluntary context switches */
271 long ru_nivcsw; /* involuntary " */
272 } ru;
273
274 if (!addr)
275 tprintf("NULL");
276 else if (syserror(tcp) || !verbose(tcp))
277 tprintf("%#lx", addr);
278 else if (umove(tcp, addr, &ru) < 0)
279 tprintf("{...}");
280 else if (!abbrev(tcp)) {
281 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
282 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
283 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
284 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
285 ru.ru_maxrss, ru.ru_ixrss);
286 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
287 ru.ru_idrss, ru.ru_isrss);
288 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
289 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
290 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
291 ru.ru_inblock, ru.ru_oublock);
292 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
293 ru.ru_msgsnd, ru.ru_msgrcv);
294 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
295 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
296 }
297 else {
298 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
299 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
300 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
301 }
302}
303#endif
304
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000305void
306printrusage(tcp, addr)
307struct tcb *tcp;
308long addr;
309{
310 struct rusage ru;
311
312 if (!addr)
313 tprintf("NULL");
314 else if (syserror(tcp) || !verbose(tcp))
315 tprintf("%#lx", addr);
316 else if (umove(tcp, addr, &ru) < 0)
317 tprintf("{...}");
318 else if (!abbrev(tcp)) {
319 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ",
320 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
321 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
322 tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ",
323 ru.ru_maxrss, ru.ru_ixrss);
324 tprintf("ru_idrss=%lu, ru_isrss=%lu, ",
325 ru.ru_idrss, ru.ru_isrss);
326 tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ",
327 ru.ru_minflt, ru.ru_majflt, ru.ru_nswap);
328 tprintf("ru_inblock=%lu, ru_oublock=%lu, ",
329 ru.ru_inblock, ru.ru_oublock);
330 tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ",
331 ru.ru_msgsnd, ru.ru_msgrcv);
332 tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}",
333 ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw);
334 }
335 else {
336 tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}",
337 (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec,
338 (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec);
339 }
340}
341
342int
343sys_getrusage(tcp)
344struct tcb *tcp;
345{
346 if (entering(tcp)) {
347 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
348 tprintf(", ");
349 }
350 else
351 printrusage(tcp, tcp->u_arg[1]);
352 return 0;
353}
354
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000355#ifdef ALPHA
356int
357sys_osf_getrusage(tcp)
358struct tcb *tcp;
359{
Denys Vlasenko59432db2009-01-26 19:09:35 +0000360 if (entering(tcp)) {
361 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
362 tprintf(", ");
363 }
364 else
365 printrusage32(tcp, tcp->u_arg[1]);
366 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000367}
368#endif /* ALPHA */
369
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000370#endif /* !SVR4 */
371
372#ifdef LINUX
373
374int
375sys_sysinfo(tcp)
376struct tcb *tcp;
377{
378 struct sysinfo si;
379
380 if (exiting(tcp)) {
381 if (syserror(tcp) || !verbose(tcp))
382 tprintf("%#lx", tcp->u_arg[0]);
383 else if (umove(tcp, tcp->u_arg[0], &si) < 0)
384 tprintf("{...}");
385 else {
386 tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ",
387 si.uptime, si.loads[0], si.loads[1],
388 si.loads[2]);
389 tprintf("totalram=%lu, freeram=%lu, ",
390 si.totalram, si.freeram);
391 tprintf("sharedram=%lu, bufferram=%lu} ",
392 si.sharedram, si.bufferram);
393 tprintf("totalswap=%lu, freeswap=%lu, procs=%hu}",
394 si.totalswap, si.freeswap, si.procs);
395 }
396 }
397 return 0;
398}
399
400#endif /* LINUX */
401
Roland McGrathd9f816f2004-09-04 03:39:20 +0000402static const struct xlat priorities[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403 { PRIO_PROCESS, "PRIO_PROCESS" },
404 { PRIO_PGRP, "PRIO_PGRP" },
405 { PRIO_USER, "PRIO_USER" },
406 { 0, NULL },
407};
408
409int
410sys_getpriority(tcp)
411struct tcb *tcp;
412{
413 if (entering(tcp)) {
414 printxval(priorities, tcp->u_arg[0], "PRIO_???");
415 tprintf(", %lu", tcp->u_arg[1]);
416 }
417 return 0;
418}
419
420int
421sys_setpriority(tcp)
422struct tcb *tcp;
423{
424 if (entering(tcp)) {
425 printxval(priorities, tcp->u_arg[0], "PRIO_???");
426 tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]);
427 }
428 return 0;
429}
430
431int
432sys_nice(tcp)
433struct tcb *tcp;
434{
435 if (entering(tcp))
436 tprintf("%ld", tcp->u_arg[0]);
437 return 0;
438}
439
440#ifndef SUNOS4
441
442int
443sys_times(tcp)
444struct tcb *tcp;
445{
446 struct tms tbuf;
447
448 if (exiting(tcp)) {
449 if (tcp->u_arg[0] == 0)
450 tprintf("NULL");
451 else if (syserror(tcp))
452 tprintf("%#lx", tcp->u_arg[0]);
453 else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0)
454 tprintf("{...}");
455 else {
456 tprintf("{tms_utime=%lu, tms_stime=%lu, ",
457 tbuf.tms_utime, tbuf.tms_stime);
458 tprintf("tms_cutime=%lu, tms_cstime=%lu}",
459 tbuf.tms_cutime, tbuf.tms_cstime);
460 }
461 }
462 return 0;
463}
464
465#endif /* !SUNOS4 */