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