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 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 34 | #include "xlat/resources.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 35 | |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 36 | static const char * |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 37 | sprint_rlim64(uint64_t lim) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 38 | { |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 39 | static char buf[sizeof(uint64_t)*3 + sizeof("*1024")]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 40 | |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 41 | if (lim == UINT64_MAX) |
| 42 | return "RLIM64_INFINITY"; |
Denys Vlasenko | 1945ccc | 2012-02-27 14:37:48 +0100 | [diff] [blame] | 43 | |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 44 | if (lim > 1024 && lim % 1024 == 0) |
| 45 | sprintf(buf, "%" PRIu64 "*1024", lim / 1024); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 46 | else |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 47 | sprintf(buf, "%" PRIu64, lim); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 48 | return buf; |
| 49 | } |
| 50 | |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 51 | static void |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 52 | print_rlimit64(struct tcb *tcp, unsigned long addr) |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 53 | { |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 54 | struct rlimit_64 { |
| 55 | uint64_t rlim_cur; |
| 56 | uint64_t rlim_max; |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 57 | } rlim; |
| 58 | |
Dmitry V. Levin | 7cc79b4 | 2015-07-17 16:25:21 +0000 | [diff] [blame] | 59 | if (!umove_or_printaddr(tcp, addr, &rlim)) { |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 60 | tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur)); |
| 61 | tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max)); |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 62 | } |
| 63 | } |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 64 | |
James Hogan | 3b09ebe | 2014-05-02 14:15:41 +0100 | [diff] [blame] | 65 | #if !defined(current_wordsize) || current_wordsize == 4 |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 66 | |
| 67 | static const char * |
| 68 | sprint_rlim32(uint32_t lim) |
| 69 | { |
| 70 | static char buf[sizeof(uint32_t)*3 + sizeof("*1024")]; |
| 71 | |
| 72 | if (lim == UINT32_MAX) |
| 73 | return "RLIM_INFINITY"; |
| 74 | |
| 75 | if (lim > 1024 && lim % 1024 == 0) |
| 76 | sprintf(buf, "%" PRIu32 "*1024", lim / 1024); |
| 77 | else |
| 78 | sprintf(buf, "%" PRIu32, lim); |
| 79 | return buf; |
| 80 | } |
| 81 | |
| 82 | static void |
| 83 | print_rlimit32(struct tcb *tcp, unsigned long addr) |
| 84 | { |
| 85 | struct rlimit_32 { |
| 86 | uint32_t rlim_cur; |
| 87 | uint32_t rlim_max; |
| 88 | } rlim; |
| 89 | |
Dmitry V. Levin | 7cc79b4 | 2015-07-17 16:25:21 +0000 | [diff] [blame] | 90 | if (!umove_or_printaddr(tcp, addr, &rlim)) { |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 91 | tprintf("{rlim_cur=%s,", sprint_rlim32(rlim.rlim_cur)); |
| 92 | tprintf(" rlim_max=%s}", sprint_rlim32(rlim.rlim_max)); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | static void |
| 97 | decode_rlimit(struct tcb *tcp, unsigned long addr) |
| 98 | { |
James Hogan | 3b09ebe | 2014-05-02 14:15:41 +0100 | [diff] [blame] | 99 | # if defined(X86_64) || defined(X32) |
Dmitry V. Levin | 7cc79b4 | 2015-07-17 16:25:21 +0000 | [diff] [blame] | 100 | /* |
| 101 | * i386 is the only personality on X86_64 and X32 |
| 102 | * with 32-bit rlim_t. |
| 103 | * When current_personality is X32, current_wordsize |
| 104 | * equals to 4 but rlim_t is 64-bit. |
| 105 | */ |
| 106 | if (current_personality == 1) |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 107 | # else |
Dmitry V. Levin | 7cc79b4 | 2015-07-17 16:25:21 +0000 | [diff] [blame] | 108 | if (current_wordsize == 4) |
James Hogan | 3b09ebe | 2014-05-02 14:15:41 +0100 | [diff] [blame] | 109 | # endif |
Dmitry V. Levin | 7cc79b4 | 2015-07-17 16:25:21 +0000 | [diff] [blame] | 110 | print_rlimit32(tcp, addr); |
| 111 | else |
| 112 | print_rlimit64(tcp, addr); |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 113 | } |
| 114 | |
James Hogan | 3b09ebe | 2014-05-02 14:15:41 +0100 | [diff] [blame] | 115 | #else /* defined(current_wordsize) && current_wordsize != 4 */ |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 116 | |
Dmitry V. Levin | 7cc79b4 | 2015-07-17 16:25:21 +0000 | [diff] [blame] | 117 | # define decode_rlimit print_rlimit64 |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 118 | |
James Hogan | 3b09ebe | 2014-05-02 14:15:41 +0100 | [diff] [blame] | 119 | #endif |
Andreas Schwab | ee81c8a | 2010-07-03 23:17:28 +0200 | [diff] [blame] | 120 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 121 | SYS_FUNC(getrlimit) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 122 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 123 | if (entering(tcp)) { |
| 124 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 125 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 126 | } |
| 127 | else { |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 128 | decode_rlimit(tcp, tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 129 | } |
| 130 | return 0; |
| 131 | } |
| 132 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 133 | SYS_FUNC(setrlimit) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 134 | { |
Dmitry V. Levin | 2b15a58 | 2015-07-17 16:39:54 +0000 | [diff] [blame] | 135 | printxval(resources, tcp->u_arg[0], "RLIMIT_???"); |
| 136 | tprints(", "); |
| 137 | decode_rlimit(tcp, tcp->u_arg[1]); |
| 138 | |
| 139 | return RVAL_DECODED; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 142 | SYS_FUNC(prlimit64) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 143 | { |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 144 | if (entering(tcp)) { |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 145 | tprintf("%ld, ", tcp->u_arg[0]); |
| 146 | printxval(resources, tcp->u_arg[1], "RLIMIT_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 147 | tprints(", "); |
Dmitry V. Levin | 7cc79b4 | 2015-07-17 16:25:21 +0000 | [diff] [blame] | 148 | print_rlimit64(tcp, tcp->u_arg[2]); |
Dmitry V. Levin | b468f23 | 2012-03-16 23:05:21 +0400 | [diff] [blame] | 149 | tprints(", "); |
| 150 | } else { |
Dmitry V. Levin | 7cc79b4 | 2015-07-17 16:25:21 +0000 | [diff] [blame] | 151 | print_rlimit64(tcp, tcp->u_arg[3]); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 152 | } |
| 153 | return 0; |
| 154 | } |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 155 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 156 | #include "xlat/usagewho.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 157 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 158 | SYS_FUNC(getrusage) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 159 | { |
| 160 | if (entering(tcp)) { |
| 161 | printxval(usagewho, tcp->u_arg[0], "RUSAGE_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 162 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 163 | } |
| 164 | else |
Dmitry V. Levin | e2fb0bb | 2015-09-15 21:51:15 +0000 | [diff] [blame] | 165 | printrusage(tcp, tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 169 | #ifdef ALPHA |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 170 | SYS_FUNC(osf_getrusage) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 171 | { |
Denys Vlasenko | 59432db | 2009-01-26 19:09:35 +0000 | [diff] [blame] | 172 | if (entering(tcp)) { |
| 173 | printxval(usagewho, tcp->u_arg[0], "RUSAGE_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 174 | tprints(", "); |
Denys Vlasenko | 59432db | 2009-01-26 19:09:35 +0000 | [diff] [blame] | 175 | } |
| 176 | else |
| 177 | printrusage32(tcp, tcp->u_arg[1]); |
| 178 | return 0; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 179 | } |
| 180 | #endif /* ALPHA */ |
| 181 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 182 | #include "xlat/priorities.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 183 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 184 | SYS_FUNC(getpriority) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 185 | { |
Dmitry V. Levin | 2b15a58 | 2015-07-17 16:39:54 +0000 | [diff] [blame] | 186 | printxval(priorities, tcp->u_arg[0], "PRIO_???"); |
Fei Jie | 032a9a4 | 2016-03-17 17:30:45 +0800 | [diff] [blame] | 187 | tprintf(", %d", (int) tcp->u_arg[1]); |
Dmitry V. Levin | 2b15a58 | 2015-07-17 16:39:54 +0000 | [diff] [blame] | 188 | |
| 189 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 192 | SYS_FUNC(setpriority) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 193 | { |
Dmitry V. Levin | 2b15a58 | 2015-07-17 16:39:54 +0000 | [diff] [blame] | 194 | printxval(priorities, tcp->u_arg[0], "PRIO_???"); |
Fei Jie | 032a9a4 | 2016-03-17 17:30:45 +0800 | [diff] [blame] | 195 | tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]); |
Dmitry V. Levin | 2b15a58 | 2015-07-17 16:39:54 +0000 | [diff] [blame] | 196 | |
| 197 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 198 | } |