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