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