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> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | #include <sys/times.h> |
| 37 | #include <linux/kernel.h> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 38 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 39 | #if HAVE_LONG_LONG_RLIM_T |
| 40 | /* |
| 41 | * Hacks for systems that have a long long rlim_t |
| 42 | */ |
| 43 | |
| 44 | #define rlimit64 rlimit /* Ugly hack */ |
| 45 | #define rlim64_t rlim_t /* Ugly hack */ |
H.J. Lu | d602542 | 2012-02-03 10:17:01 -0800 | [diff] [blame] | 46 | #ifndef RLIM64_INFINITY |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 47 | #define RLIM64_INFINITY RLIM_INFINITY /* You guessed it */ |
H.J. Lu | d602542 | 2012-02-03 10:17:01 -0800 | [diff] [blame] | 48 | #endif |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 49 | |
| 50 | #define sys_getrlimit64 sys_getrlimit |
| 51 | #define sys_setrlimit64 sys_setrlimit |
| 52 | #endif |
| 53 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 54 | static const struct xlat resources[] = { |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 55 | #ifdef RLIMIT_AS |
| 56 | { RLIMIT_AS, "RLIMIT_AS" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 57 | #endif |
| 58 | #ifdef RLIMIT_CORE |
| 59 | { RLIMIT_CORE, "RLIMIT_CORE" }, |
| 60 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 61 | #ifdef RLIMIT_CPU |
| 62 | { RLIMIT_CPU, "RLIMIT_CPU" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 63 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 64 | #ifdef RLIMIT_DATA |
| 65 | { RLIMIT_DATA, "RLIMIT_DATA" }, |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 66 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 67 | #ifdef RLIMIT_FSIZE |
| 68 | { RLIMIT_FSIZE, "RLIMIT_FSIZE" }, |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 69 | #endif |
Roland McGrath | 566ce1f | 2004-10-06 22:14:53 +0000 | [diff] [blame] | 70 | #ifdef RLIMIT_LOCKS |
| 71 | { RLIMIT_LOCKS, "RLIMIT_LOCKS" }, |
| 72 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 73 | #ifdef RLIMIT_MEMLOCK |
| 74 | { RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK" }, |
Roland McGrath | 566ce1f | 2004-10-06 22:14:53 +0000 | [diff] [blame] | 75 | #endif |
| 76 | #ifdef RLIMIT_MSGQUEUE |
| 77 | { RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE" }, |
| 78 | #endif |
Roland McGrath | 70d9909 | 2005-12-02 04:08:27 +0000 | [diff] [blame] | 79 | #ifdef RLIMIT_NICE |
| 80 | { RLIMIT_NICE, "RLIMIT_NICE" }, |
| 81 | #endif |
| 82 | #ifdef RLIMIT_NOFILE |
| 83 | { RLIMIT_NOFILE, "RLIMIT_NOFILE" }, |
| 84 | #endif |
| 85 | #ifdef RLIMIT_NPROC |
| 86 | { RLIMIT_NPROC, "RLIMIT_NPROC" }, |
| 87 | #endif |
| 88 | #ifdef RLIMIT_RSS |
| 89 | { RLIMIT_RSS, "RLIMIT_RSS" }, |
| 90 | #endif |
| 91 | #ifdef RLIMIT_RTPRIO |
| 92 | { RLIMIT_RTPRIO, "RLIMIT_RTPRIO" }, |
| 93 | #endif |
| 94 | #ifdef RLIMIT_SIGPENDING |
| 95 | { RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING" }, |
| 96 | #endif |
| 97 | #ifdef RLIMIT_STACK |
| 98 | { RLIMIT_STACK, "RLIMIT_STACK" }, |
| 99 | #endif |
| 100 | #ifdef RLIMIT_VMEM |
| 101 | { RLIMIT_VMEM, "RLIMIT_VMEM" }, |
| 102 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 103 | { 0, NULL }, |
| 104 | }; |
| 105 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 106 | #if !HAVE_LONG_LONG_RLIM_T |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 107 | static const char * |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 108 | sprintrlim(long lim) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 109 | { |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 110 | static char buf[sizeof(long)*3 + sizeof("%ld*1024")]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 111 | |
| 112 | if (lim == RLIM_INFINITY) |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 113 | return "RLIM_INFINITY"; |
| 114 | |
| 115 | if (lim > 1024 && lim%1024 == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 116 | sprintf(buf, "%ld*1024", lim/1024); |
| 117 | else |
| 118 | sprintf(buf, "%ld", lim); |
| 119 | return buf; |
| 120 | } |
| 121 | |
Denys Vlasenko | aa925db | 2012-02-25 15:19:02 +0100 | [diff] [blame] | 122 | # if defined(POWERPC64) || defined(X86_64) |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 123 | static void |
| 124 | print_rlimit32(struct tcb *tcp) |
| 125 | { |
| 126 | struct rlimit32 { |
| 127 | unsigned int rlim_cur; |
| 128 | unsigned int rlim_max; |
| 129 | } rlim; |
| 130 | |
| 131 | if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 132 | tprints("{...}"); |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 133 | else { |
| 134 | tprintf("{rlim_cur=%s,", |
| 135 | sprintrlim(rlim.rlim_cur == -1 ? RLIM_INFINITY |
| 136 | : rlim.rlim_cur)); |
| 137 | tprintf(" rlim_max=%s}", |
| 138 | sprintrlim(rlim.rlim_max == -1 ? RLIM_INFINITY |
| 139 | : rlim.rlim_max)); |
| 140 | } |
| 141 | } |
| 142 | # endif |
| 143 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 144 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 145 | sys_getrlimit(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 146 | { |
| 147 | struct rlimit rlim; |
| 148 | |
| 149 | if (entering(tcp)) { |
| 150 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 151 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 152 | } |
| 153 | else { |
| 154 | if (syserror(tcp) || !verbose(tcp)) |
| 155 | tprintf("%#lx", tcp->u_arg[1]); |
Denys Vlasenko | aa925db | 2012-02-25 15:19:02 +0100 | [diff] [blame] | 156 | # if defined(POWERPC64) || defined(X86_64) |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 157 | else if (current_personality == 1) |
| 158 | print_rlimit32(tcp); |
| 159 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 160 | else if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 161 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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 | } |
| 169 | |
| 170 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 171 | sys_setrlimit(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 172 | { |
| 173 | struct rlimit rlim; |
| 174 | |
| 175 | if (entering(tcp)) { |
| 176 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 177 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 178 | if (!verbose(tcp)) |
| 179 | tprintf("%#lx", tcp->u_arg[1]); |
Denys Vlasenko | aa925db | 2012-02-25 15:19:02 +0100 | [diff] [blame] | 180 | # if defined(POWERPC64) || defined(X86_64) |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 181 | else if (current_personality == 1) |
| 182 | print_rlimit32(tcp); |
| 183 | # endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 184 | else if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 185 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 186 | else { |
| 187 | tprintf("{rlim_cur=%s,", sprintrlim(rlim.rlim_cur)); |
| 188 | tprintf(" rlim_max=%s}", sprintrlim(rlim.rlim_max)); |
| 189 | } |
| 190 | } |
| 191 | return 0; |
| 192 | } |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 193 | #endif /* !HAVE_LONG_LONG_RLIM_T */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 194 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 195 | #if _LFS64_LARGEFILE || HAVE_LONG_LONG_RLIM_T |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 196 | static const char * |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 197 | sprintrlim64(rlim64_t lim) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 198 | { |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 199 | static char buf[sizeof(long long)*3 + sizeof("%lld*1024")]; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 200 | |
| 201 | if (lim == RLIM64_INFINITY) |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 202 | return "RLIM64_INFINITY"; |
| 203 | |
| 204 | if (lim > 1024 && lim%1024 == 0) |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 205 | sprintf(buf, "%lld*1024", (long long) lim/1024); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 206 | else |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 207 | sprintf(buf, "%lld", (long long) lim); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 208 | return buf; |
| 209 | } |
| 210 | |
| 211 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 212 | sys_getrlimit64(struct tcb *tcp) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 213 | { |
| 214 | struct rlimit64 rlim; |
| 215 | |
| 216 | if (entering(tcp)) { |
| 217 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 218 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 219 | } |
| 220 | else { |
| 221 | if (syserror(tcp) || !verbose(tcp)) |
| 222 | tprintf("%#lx", tcp->u_arg[1]); |
| 223 | else if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 224 | tprints("{...}"); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 225 | else { |
| 226 | tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur)); |
| 227 | tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max)); |
| 228 | } |
| 229 | } |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 234 | sys_setrlimit64(struct tcb *tcp) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 235 | { |
| 236 | struct rlimit64 rlim; |
| 237 | |
| 238 | if (entering(tcp)) { |
| 239 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 240 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 241 | if (!verbose(tcp)) |
| 242 | tprintf("%#lx", tcp->u_arg[1]); |
| 243 | else if (umove(tcp, tcp->u_arg[1], &rlim) < 0) |
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 | else { |
| 246 | tprintf("{rlim_cur=%s,", sprintrlim64(rlim.rlim_cur)); |
| 247 | tprintf(" rlim_max=%s}", sprintrlim64(rlim.rlim_max)); |
| 248 | } |
| 249 | } |
| 250 | return 0; |
| 251 | } |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 252 | #endif /* _LFS64_LARGEFILES || HAVE_LONG_LONG_RLIM_T */ |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 253 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 254 | static const struct xlat usagewho[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 255 | { RUSAGE_SELF, "RUSAGE_SELF" }, |
| 256 | { RUSAGE_CHILDREN, "RUSAGE_CHILDREN" }, |
Wichert Akkerman | c792698 | 2000-04-10 22:22:31 +0000 | [diff] [blame] | 257 | #ifdef RUSAGE_BOTH |
| 258 | { RUSAGE_BOTH, "RUSAGE_BOTH" }, |
| 259 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 260 | { 0, NULL }, |
| 261 | }; |
| 262 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 263 | #ifdef ALPHA |
| 264 | void |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 265 | printrusage32(struct tcb *tcp, long addr) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 266 | { |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 267 | struct timeval32 { |
| 268 | unsigned tv_sec; |
| 269 | unsigned tv_usec; |
| 270 | }; |
| 271 | struct rusage32 { |
| 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 " */ |
| 288 | } ru; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 289 | |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 290 | if (!addr) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 291 | tprints("NULL"); |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 292 | else if (syserror(tcp) || !verbose(tcp)) |
| 293 | tprintf("%#lx", addr); |
| 294 | else if (umove(tcp, addr, &ru) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 295 | tprints("{...}"); |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 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); |
| 312 | } |
| 313 | else { |
| 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 | } |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 318 | } |
| 319 | #endif |
| 320 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 321 | void |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 322 | printrusage(struct tcb *tcp, long addr) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 323 | { |
| 324 | struct rusage ru; |
| 325 | |
| 326 | if (!addr) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 327 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 328 | else if (syserror(tcp) || !verbose(tcp)) |
| 329 | tprintf("%#lx", addr); |
| 330 | else if (umove(tcp, addr, &ru) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 331 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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); |
| 348 | } |
| 349 | else { |
| 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); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 357 | sys_getrusage(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 358 | { |
| 359 | if (entering(tcp)) { |
| 360 | printxval(usagewho, tcp->u_arg[0], "RUSAGE_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 361 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 362 | } |
| 363 | else |
| 364 | printrusage(tcp, tcp->u_arg[1]); |
| 365 | return 0; |
| 366 | } |
| 367 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 368 | #ifdef ALPHA |
| 369 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 370 | sys_osf_getrusage(struct tcb *tcp) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 371 | { |
Denys Vlasenko | 59432db | 2009-01-26 19:09:35 +0000 | [diff] [blame] | 372 | if (entering(tcp)) { |
| 373 | printxval(usagewho, tcp->u_arg[0], "RUSAGE_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 374 | tprints(", "); |
Denys Vlasenko | 59432db | 2009-01-26 19:09:35 +0000 | [diff] [blame] | 375 | } |
| 376 | else |
| 377 | printrusage32(tcp, tcp->u_arg[1]); |
| 378 | return 0; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 379 | } |
| 380 | #endif /* ALPHA */ |
| 381 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 382 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 383 | sys_sysinfo(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 384 | { |
| 385 | struct sysinfo si; |
| 386 | |
| 387 | if (exiting(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) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 391 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 392 | else { |
| 393 | tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 394 | (long) si.uptime, (long) si.loads[0], |
| 395 | (long) si.loads[1], (long) si.loads[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 396 | tprintf("totalram=%lu, freeram=%lu, ", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 397 | (long) si.totalram, (long) si.freeram); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 398 | tprintf("sharedram=%lu, bufferram=%lu} ", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 399 | (long) si.sharedram, (long) si.bufferram); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 400 | tprintf("totalswap=%lu, freeswap=%lu, procs=%hu}", |
H.J. Lu | 0b315b6 | 2012-02-03 10:16:03 -0800 | [diff] [blame] | 401 | (long) si.totalswap, (long) si.freeswap, |
| 402 | si.procs); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | return 0; |
| 406 | } |
| 407 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 408 | static const struct xlat priorities[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 409 | { PRIO_PROCESS, "PRIO_PROCESS" }, |
| 410 | { PRIO_PGRP, "PRIO_PGRP" }, |
| 411 | { PRIO_USER, "PRIO_USER" }, |
| 412 | { 0, NULL }, |
| 413 | }; |
| 414 | |
| 415 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 416 | sys_getpriority(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 417 | { |
| 418 | if (entering(tcp)) { |
| 419 | printxval(priorities, tcp->u_arg[0], "PRIO_???"); |
| 420 | tprintf(", %lu", tcp->u_arg[1]); |
| 421 | } |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 426 | sys_setpriority(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 427 | { |
| 428 | if (entering(tcp)) { |
| 429 | printxval(priorities, tcp->u_arg[0], "PRIO_???"); |
| 430 | tprintf(", %lu, %ld", tcp->u_arg[1], tcp->u_arg[2]); |
| 431 | } |
| 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | int |
Denys Vlasenko | 1d63246 | 2009-04-14 12:51:00 +0000 | [diff] [blame] | 436 | sys_times(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 437 | { |
| 438 | struct tms tbuf; |
| 439 | |
| 440 | if (exiting(tcp)) { |
| 441 | if (tcp->u_arg[0] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 442 | tprints("NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 443 | else if (syserror(tcp)) |
| 444 | tprintf("%#lx", tcp->u_arg[0]); |
| 445 | else if (umove(tcp, tcp->u_arg[0], &tbuf) < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 446 | tprints("{...}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 447 | else { |
| 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); |
| 452 | } |
| 453 | } |
| 454 | return 0; |
| 455 | } |