Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 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 Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 6 | * 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 Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 40 | #if defined(SVR4) || defined(FREEBSD) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 41 | #include <sys/times.h> |
| 42 | #include <sys/time.h> |
| 43 | #endif |
| 44 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 45 | #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 */ |
H.J. Lu | d602542 | 2012-02-03 10:17:01 -0800 | [diff] [blame^] | 52 | #ifndef RLIM64_INFINITY |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 53 | #define RLIM64_INFINITY RLIM_INFINITY /* You guessed it */ |
H.J. Lu | d602542 | 2012-02-03 10:17:01 -0800 | [diff] [blame^] | 54 | #endif |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 55 | |
| 56 | #define sys_getrlimit64 sys_getrlimit |
| 57 | #define sys_setrlimit64 sys_setrlimit |
| 58 | #endif |
| 59 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 60 | static const struct xlat resources[] = { |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 61 | #ifdef RLIMIT_AS |
| 62 | { RLIMIT_AS, "RLIMIT_AS" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 63 | #endif |
| 64 | #ifdef RLIMIT_CORE |
| 65 | { RLIMIT_CORE, "RLIMIT_CORE" }, |
| 66 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 67 | #ifdef RLIMIT_CPU |
| 68 | { RLIMIT_CPU, "RLIMIT_CPU" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 69 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 70 | #ifdef RLIMIT_DATA |
| 71 | { RLIMIT_DATA, "RLIMIT_DATA" }, |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 72 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 73 | #ifdef RLIMIT_FSIZE |
| 74 | { RLIMIT_FSIZE, "RLIMIT_FSIZE" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 75 | #endif |
Roland McGrath | 566ce1f | 2004-10-06 22:14:53 +0000 | [diff] [blame] | 76 | #ifdef RLIMIT_LOCKS |
| 77 | { RLIMIT_LOCKS, "RLIMIT_LOCKS" }, |
| 78 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 79 | #ifdef RLIMIT_MEMLOCK |
| 80 | { RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK" }, |
Roland McGrath | 566ce1f | 2004-10-06 22:14:53 +0000 | [diff] [blame] | 81 | #endif |
| 82 | #ifdef RLIMIT_MSGQUEUE |
| 83 | { RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE" }, |
| 84 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 85 | #ifdef RLIMIT_NICE |
| 86 | { RLIMIT_NICE, "RLIMIT_NICE" }, |
| 87 | #endif |
| 88 | #ifdef RLIMIT_NOFILE |
| 89 | { RLIMIT_NOFILE, "RLIMIT_NOFILE" }, |
| 90 | #endif |
| 91 | #ifdef RLIMIT_NPROC |
| 92 | { RLIMIT_NPROC, "RLIMIT_NPROC" }, |
| 93 | #endif |
| 94 | #ifdef RLIMIT_RSS |
| 95 | { RLIMIT_RSS, "RLIMIT_RSS" }, |
| 96 | #endif |
| 97 | #ifdef RLIMIT_RTPRIO |
| 98 | { RLIMIT_RTPRIO, "RLIMIT_RTPRIO" }, |
| 99 | #endif |
| 100 | #ifdef RLIMIT_SIGPENDING |
| 101 | { RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING" }, |
| 102 | #endif |
| 103 | #ifdef RLIMIT_STACK |
| 104 | { RLIMIT_STACK, "RLIMIT_STACK" }, |
| 105 | #endif |
| 106 | #ifdef RLIMIT_VMEM |
| 107 | { RLIMIT_VMEM, "RLIMIT_VMEM" }, |
| 108 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 109 | { 0, NULL }, |
| 110 | }; |
| 111 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 112 | #if !HAVE_LONG_LONG_RLIM_T |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 113 | static char * |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 114 | sprintrlim(long lim) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 115 | { |
| 116 | static char buf[32]; |
| 117 | |
| 118 | if (lim == RLIM_INFINITY) |
| 119 | sprintf(buf, "RLIM_INFINITY"); |
| 120 | else if (lim > 1024 && lim%1024 == 0) |
| 121 | sprintf(buf, "%ld*1024", lim/1024); |
| 122 | else |
| 123 | sprintf(buf, "%ld", lim); |
| 124 | return buf; |
| 125 | } |
| 126 | |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 127 | # if defined LINUX && (defined POWERPC64 || defined X86_64) |
| 128 | static void |
| 129 | print_rlimit32(struct tcb *tcp) |
| 130 | { |
| 131 | struct rlimit32 { |
| 132 | unsigned int rlim_cur; |
| 133 | unsigned int rlim_max; |
| 134 | } rlim; |
| 135 | |
| 136 | if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 137 | tprints("{...}"); |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 138 | else { |
| 139 | tprintf("{rlim_cur=%s,", |
| 140 | sprintrlim(rlim.rlim_cur == -1 ? RLIM_INFINITY |
| 141 | : rlim.rlim_cur)); |
| 142 | tprintf(" rlim_max=%s}", |
| 143 | sprintrlim(rlim.rlim_max == -1 ? RLIM_INFINITY |
| 144 | : rlim.rlim_max)); |
| 145 | } |
| 146 | } |
| 147 | # endif |
| 148 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 149 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 150 | sys_getrlimit(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 151 | { |
| 152 | struct rlimit rlim; |
| 153 | |
| 154 | if (entering(tcp)) { |
| 155 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 156 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 157 | } |
| 158 | else { |
| 159 | if (syserror(tcp) || !verbose(tcp)) |
| 160 | tprintf("%#lx", tcp->u_arg[1]); |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 161 | # if defined LINUX && (defined POWERPC64 || defined X86_64) |
| 162 | else if (current_personality == 1) |
| 163 | print_rlimit32(tcp); |
| 164 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 165 | else if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 166 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 167 | else { |
| 168 | tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur)); |
| 169 | tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max)); |
| 170 | } |
| 171 | } |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 176 | sys_setrlimit(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 177 | { |
| 178 | struct rlimit rlim; |
| 179 | |
| 180 | if (entering(tcp)) { |
| 181 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 182 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 183 | if (!verbose(tcp)) |
| 184 | tprintf("%#lx", tcp->u_arg[1]); |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 185 | # if defined LINUX && (defined POWERPC64 || defined X86_64) |
| 186 | else if (current_personality == 1) |
| 187 | print_rlimit32(tcp); |
| 188 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 189 | else if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 190 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 191 | else { |
| 192 | tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur)); |
| 193 | tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max)); |
| 194 | } |
| 195 | } |
| 196 | return 0; |
| 197 | } |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 198 | #endif /* !HAVE_LONG_LONG_RLIM_T */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 199 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 200 | #if _LFS64_LARGEFILE || HAVE_LONG_LONG_RLIM_T |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 201 | static char * |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 202 | sprintrlim64(rlim64_t lim) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 203 | { |
| 204 | static char buf[64]; |
| 205 | |
| 206 | if (lim == RLIM64_INFINITY) |
| 207 | sprintf(buf, "RLIM64_INFINITY"); |
| 208 | else if (lim > 1024 && lim%1024 == 0) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 209 | sprintf(buf, "%lld*1024", (long long) lim/1024); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 210 | else |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 211 | sprintf(buf, "%lld", (long long) lim); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 212 | return buf; |
| 213 | } |
| 214 | |
| 215 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 216 | sys_getrlimit64(struct tcb *tcp) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 217 | { |
| 218 | struct rlimit64 rlim; |
| 219 | |
| 220 | if (entering(tcp)) { |
| 221 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 222 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 223 | } |
| 224 | else { |
| 225 | if (syserror(tcp) || !verbose(tcp)) |
| 226 | tprintf("%#lx", tcp->u_arg[1]); |
| 227 | else if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 228 | tprints("{...}"); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 229 | else { |
| 230 | tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur)); |
| 231 | tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max)); |
| 232 | } |
| 233 | } |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 238 | sys_setrlimit64(struct tcb *tcp) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 239 | { |
| 240 | struct rlimit64 rlim; |
| 241 | |
| 242 | if (entering(tcp)) { |
| 243 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 244 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 245 | if (!verbose(tcp)) |
| 246 | tprintf("%#lx", tcp->u_arg[1]); |
| 247 | else if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 248 | tprints("{...}"); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 249 | else { |
| 250 | tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur)); |
| 251 | tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max)); |
| 252 | } |
| 253 | } |
| 254 | return 0; |
| 255 | } |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 256 | #endif /* _LFS64_LARGEFILES || HAVE_LONG_LONG_RLIM_T */ |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 257 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 258 | #ifndef SVR4 |
| 259 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 260 | static const struct xlat usagewho[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 261 | { RUSAGE_SELF, "RUSAGE_SELF" }, |
| 262 | { RUSAGE_CHILDREN, "RUSAGE_CHILDREN" }, |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 263 | #ifdef RUSAGE_BOTH |
| 264 | { RUSAGE_BOTH, "RUSAGE_BOTH" }, |
| 265 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 266 | { 0, NULL }, |
| 267 | }; |
| 268 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 269 | #ifdef ALPHA |
| 270 | void |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 271 | printrusage32(struct tcb *tcp, long addr) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 272 | { |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 273 | struct timeval32 { |
| 274 | unsigned tv_sec; |
| 275 | unsigned tv_usec; |
| 276 | }; |
| 277 | struct rusage32 { |
| 278 | struct timeval32 ru_utime; /* user time used */ |
| 279 | struct timeval32 ru_stime; /* system time used */ |
| 280 | long ru_maxrss; /* maximum resident set size */ |
| 281 | long ru_ixrss; /* integral shared memory size */ |
| 282 | long ru_idrss; /* integral unshared data size */ |
| 283 | long ru_isrss; /* integral unshared stack size */ |
| 284 | long ru_minflt; /* page reclaims */ |
| 285 | long ru_majflt; /* page faults */ |
| 286 | long ru_nswap; /* swaps */ |
| 287 | long ru_inblock; /* block input operations */ |
| 288 | long ru_oublock; /* block output operations */ |
| 289 | long ru_msgsnd; /* messages sent */ |
| 290 | long ru_msgrcv; /* messages received */ |
| 291 | long ru_nsignals; /* signals received */ |
| 292 | long ru_nvcsw; /* voluntary context switches */ |
| 293 | long ru_nivcsw; /* involuntary " */ |
| 294 | } ru; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 295 | |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 296 | if (!addr) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 297 | tprints("NULL"); |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 298 | else if (syserror(tcp) || !verbose(tcp)) |
| 299 | tprintf("%#lx", addr); |
| 300 | else if (umove(tcp, addr, &ru) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 301 | tprints("{...}"); |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 302 | else if (!abbrev(tcp)) { |
| 303 | tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ", |
| 304 | (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec, |
| 305 | (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec); |
| 306 | tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ", |
| 307 | ru.ru_maxrss, ru.ru_ixrss); |
| 308 | tprintf("ru_idrss=%lu, ru_isrss=%lu, ", |
| 309 | ru.ru_idrss, ru.ru_isrss); |
| 310 | tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ", |
| 311 | ru.ru_minflt, ru.ru_majflt, ru.ru_nswap); |
| 312 | tprintf("ru_inblock=%lu, ru_oublock=%lu, ", |
| 313 | ru.ru_inblock, ru.ru_oublock); |
| 314 | tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ", |
| 315 | ru.ru_msgsnd, ru.ru_msgrcv); |
| 316 | tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}", |
| 317 | ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw); |
| 318 | } |
| 319 | else { |
| 320 | tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}", |
| 321 | (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec, |
| 322 | (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec); |
| 323 | } |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 324 | } |
| 325 | #endif |
| 326 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 327 | void |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 328 | printrusage(struct tcb *tcp, long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 329 | { |
| 330 | struct rusage ru; |
| 331 | |
| 332 | if (!addr) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 333 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 334 | else if (syserror(tcp) || !verbose(tcp)) |
| 335 | tprintf("%#lx", addr); |
| 336 | else if (umove(tcp, addr, &ru) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 337 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 338 | else if (!abbrev(tcp)) { |
| 339 | tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ", |
| 340 | (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec, |
| 341 | (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec); |
| 342 | tprintf("ru_maxrss=%lu, ru_ixrss=%lu, ", |
| 343 | ru.ru_maxrss, ru.ru_ixrss); |
| 344 | tprintf("ru_idrss=%lu, ru_isrss=%lu, ", |
| 345 | ru.ru_idrss, ru.ru_isrss); |
| 346 | tprintf("ru_minflt=%lu, ru_majflt=%lu, ru_nswap=%lu, ", |
| 347 | ru.ru_minflt, ru.ru_majflt, ru.ru_nswap); |
| 348 | tprintf("ru_inblock=%lu, ru_oublock=%lu, ", |
| 349 | ru.ru_inblock, ru.ru_oublock); |
| 350 | tprintf("ru_msgsnd=%lu, ru_msgrcv=%lu, ", |
| 351 | ru.ru_msgsnd, ru.ru_msgrcv); |
| 352 | tprintf("ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}", |
| 353 | ru.ru_nsignals, ru.ru_nvcsw, ru.ru_nivcsw); |
| 354 | } |
| 355 | else { |
| 356 | tprintf("{ru_utime={%lu, %lu}, ru_stime={%lu, %lu}, ...}", |
| 357 | (long) ru.ru_utime.tv_sec, (long) ru.ru_utime.tv_usec, |
| 358 | (long) ru.ru_stime.tv_sec, (long) ru.ru_stime.tv_usec); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 363 | sys_getrusage(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 364 | { |
| 365 | if (entering(tcp)) { |
| 366 | printxval(usagewho, tcp->u_arg[0], "RUSAGE_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 367 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 368 | } |
| 369 | else |
| 370 | printrusage(tcp, tcp->u_arg[1]); |
| 371 | return 0; |
| 372 | } |
| 373 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 374 | #ifdef ALPHA |
| 375 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 376 | sys_osf_getrusage(struct tcb *tcp) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 377 | { |
Denys Vlasenko | 59432db | 2009-01-26 19:09:35 +0000 | [diff] [blame] | 378 | if (entering(tcp)) { |
| 379 | printxval(usagewho, tcp->u_arg[0], "RUSAGE_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 380 | tprints(", "); |
Denys Vlasenko | 59432db | 2009-01-26 19:09:35 +0000 | [diff] [blame] | 381 | } |
| 382 | else |
| 383 | printrusage32(tcp, tcp->u_arg[1]); |
| 384 | return 0; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 385 | } |
| 386 | #endif /* ALPHA */ |
| 387 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 388 | #endif /* !SVR4 */ |
| 389 | |
| 390 | #ifdef LINUX |
| 391 | |
| 392 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 393 | sys_sysinfo(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 394 | { |
| 395 | struct sysinfo si; |
| 396 | |
| 397 | if (exiting(tcp)) { |
| 398 | if (syserror(tcp) || !verbose(tcp)) |
| 399 | tprintf("%#lx", tcp->u_arg[0]); |
| 400 | else if (umove(tcp, tcp->u_arg[0], &si) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 401 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 402 | else { |
| 403 | tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 404 | (long) si.uptime, (long) si.loads[0], |
| 405 | (long) si.loads[1], (long) si.loads[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 406 | tprintf("totalram=%lu, freeram=%lu, ", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 407 | (long) si.totalram, (long) si.freeram); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 408 | tprintf("sharedram=%lu, bufferram=%lu} ", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 409 | (long) si.sharedram, (long) si.bufferram); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 410 | tprintf("totalswap=%lu, freeswap=%lu, procs=%hu}", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 411 | (long) si.totalswap, (long) si.freeswap, |
| 412 | si.procs); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | #endif /* LINUX */ |
| 419 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 420 | static const struct xlat priorities[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 421 | { PRIO_PROCESS, "PRIO_PROCESS" }, |
| 422 | { PRIO_PGRP, "PRIO_PGRP" }, |
| 423 | { PRIO_USER, "PRIO_USER" }, |
| 424 | { 0, NULL }, |
| 425 | }; |
| 426 | |
| 427 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 428 | sys_getpriority(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 429 | { |
| 430 | if (entering(tcp)) { |
| 431 | printxval(priorities, tcp->u_arg[0], "PRIO_???"); |
| 432 | tprintf(", %lu", tcp->u_arg[1]); |
| 433 | } |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 438 | sys_setpriority(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 439 | { |
| 440 | if (entering(tcp)) { |
| 441 | printxval(priorities, tcp->u_arg[0], "PRIO_???"); |
| 442 | tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]); |
| 443 | } |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 448 | sys_nice(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 449 | { |
| 450 | if (entering(tcp)) |
| 451 | tprintf("%ld", tcp->u_arg[0]); |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | #ifndef SUNOS4 |
| 456 | |
| 457 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 458 | sys_times(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 459 | { |
| 460 | struct tms tbuf; |
| 461 | |
| 462 | if (exiting(tcp)) { |
| 463 | if (tcp->u_arg[0] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 464 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 465 | else if (syserror(tcp)) |
| 466 | tprintf("%#lx", tcp->u_arg[0]); |
| 467 | else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 468 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 469 | else { |
| 470 | tprintf("{tms_utime=%lu, tms_stime=%lu, ", |
| 471 | tbuf.tms_utime, tbuf.tms_stime); |
| 472 | tprintf("tms_cutime=%lu, tms_cstime=%lu}", |
| 473 | tbuf.tms_cutime, tbuf.tms_cstime); |
| 474 | } |
| 475 | } |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | #endif /* !SUNOS4 */ |