Branch data Line data Source code
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>
5 : : * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 : : * Copyright (c) 1999-2017 The strace developers.
7 : : * All rights reserved.
8 : : *
9 : : * Redistribution and use in source and binary forms, with or without
10 : : * modification, are permitted provided that the following conditions
11 : : * are met:
12 : : * 1. Redistributions of source code must retain the above copyright
13 : : * notice, this list of conditions and the following disclaimer.
14 : : * 2. Redistributions in binary form must reproduce the above copyright
15 : : * notice, this list of conditions and the following disclaimer in the
16 : : * documentation and/or other materials provided with the distribution.
17 : : * 3. The name of the author may not be used to endorse or promote products
18 : : * derived from this software without specific prior written permission.
19 : : *
20 : : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 : : * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 : : * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 : : * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 : : * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 : : * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 : : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 : : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 : : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 : : * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 : : */
31 : :
32 : : #include "defs.h"
33 : : #include <sys/resource.h>
34 : :
35 : : #include "xlat/resources.h"
36 : :
37 : : static const char *
38 : 128 : sprint_rlim64(uint64_t lim)
39 : : {
40 : : static char buf[sizeof(uint64_t)*3 + sizeof("*1024")];
41 : :
42 [ + + ]: 128 : if (lim == UINT64_MAX)
43 : : return "RLIM64_INFINITY";
44 : :
45 [ + + ][ + + ]: 60 : if (lim > 1024 && lim % 1024 == 0)
46 : 24 : sprintf(buf, "%" PRIu64 "*1024", lim / 1024);
47 : : else
48 : 36 : sprintf(buf, "%" PRIu64, lim);
49 : : return buf;
50 : : }
51 : :
52 : : static void
53 : 128 : print_rlimit64(struct tcb *const tcp, const kernel_ulong_t addr)
54 : : {
55 : : struct rlimit_64 {
56 : : uint64_t rlim_cur;
57 : : uint64_t rlim_max;
58 : : } rlim;
59 : :
60 [ + + ]: 128 : if (!umove_or_printaddr(tcp, addr, &rlim)) {
61 : 64 : tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur));
62 : 64 : tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max));
63 : : }
64 : 128 : }
65 : :
66 : : #if !defined(current_wordsize) || current_wordsize == 4
67 : :
68 : : static const char *
69 : 96 : sprint_rlim32(uint32_t lim)
70 : : {
71 : : static char buf[sizeof(uint32_t)*3 + sizeof("*1024")];
72 : :
73 [ + + ]: 96 : if (lim == UINT32_MAX)
74 : : return "RLIM_INFINITY";
75 : :
76 [ + + ][ + + ]: 62 : if (lim > 1024 && lim % 1024 == 0)
77 : 18 : sprintf(buf, "%" PRIu32 "*1024", lim / 1024);
78 : : else
79 : 44 : sprintf(buf, "%" PRIu32, lim);
80 : : return buf;
81 : : }
82 : :
83 : : static void
84 : 96 : print_rlimit32(struct tcb *const tcp, const kernel_ulong_t addr)
85 : : {
86 : : struct rlimit_32 {
87 : : uint32_t rlim_cur;
88 : : uint32_t rlim_max;
89 : : } rlim;
90 : :
91 [ + + ]: 96 : if (!umove_or_printaddr(tcp, addr, &rlim)) {
92 : 48 : tprintf("{rlim_cur=%s,", sprint_rlim32(rlim.rlim_cur));
93 : 48 : tprintf(" rlim_max=%s}", sprint_rlim32(rlim.rlim_max));
94 : : }
95 : 96 : }
96 : :
97 : : static void
98 : 160 : decode_rlimit(struct tcb *const tcp, const kernel_ulong_t addr)
99 : : {
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 [ + + ]: 160 : if (current_klongsize == 4)
107 : 96 : print_rlimit32(tcp, addr);
108 : : else
109 : 64 : print_rlimit64(tcp, addr);
110 : 160 : }
111 : :
112 : : #else /* defined(current_wordsize) && current_wordsize != 4 */
113 : :
114 : : # define decode_rlimit print_rlimit64
115 : :
116 : : #endif
117 : :
118 : 192 : SYS_FUNC(getrlimit)
119 : : {
120 [ + + ]: 192 : if (entering(tcp)) {
121 : 96 : printxval(resources, tcp->u_arg[0], "RLIMIT_???");
122 : 96 : tprints(", ");
123 : : } else {
124 : 96 : decode_rlimit(tcp, tcp->u_arg[1]);
125 : : }
126 : 192 : return 0;
127 : : }
128 : :
129 : 64 : SYS_FUNC(setrlimit)
130 : : {
131 : 64 : printxval(resources, tcp->u_arg[0], "RLIMIT_???");
132 : 64 : tprints(", ");
133 : 64 : decode_rlimit(tcp, tcp->u_arg[1]);
134 : :
135 : 64 : return RVAL_DECODED;
136 : : }
137 : :
138 : 64 : SYS_FUNC(prlimit64)
139 : : {
140 [ + + ]: 64 : if (entering(tcp)) {
141 : 32 : tprintf("%d, ", (int) tcp->u_arg[0]);
142 : 32 : printxval(resources, tcp->u_arg[1], "RLIMIT_???");
143 : 32 : tprints(", ");
144 : 32 : print_rlimit64(tcp, tcp->u_arg[2]);
145 : 32 : tprints(", ");
146 : : } else {
147 : 32 : print_rlimit64(tcp, tcp->u_arg[3]);
148 : : }
149 : 64 : return 0;
150 : : }
151 : :
152 : : #include "xlat/usagewho.h"
153 : :
154 : 8 : SYS_FUNC(getrusage)
155 : : {
156 [ + + ]: 8 : if (entering(tcp)) {
157 : 4 : printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
158 : 4 : tprints(", ");
159 : : } else
160 : 4 : printrusage(tcp, tcp->u_arg[1]);
161 : 8 : return 0;
162 : : }
163 : :
164 : : #ifdef ALPHA
165 : : SYS_FUNC(osf_getrusage)
166 : : {
167 : : if (entering(tcp)) {
168 : : printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
169 : : tprints(", ");
170 : : } else
171 : : printrusage32(tcp, tcp->u_arg[1]);
172 : : return 0;
173 : : }
174 : : #endif /* ALPHA */
175 : :
176 : : #include "xlat/priorities.h"
177 : :
178 : 2 : SYS_FUNC(getpriority)
179 : : {
180 : 2 : printxval(priorities, tcp->u_arg[0], "PRIO_???");
181 : 2 : tprintf(", %d", (int) tcp->u_arg[1]);
182 : :
183 : 2 : return RVAL_DECODED;
184 : : }
185 : :
186 : 2 : SYS_FUNC(setpriority)
187 : : {
188 : 2 : printxval(priorities, tcp->u_arg[0], "PRIO_???");
189 : 2 : tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);
190 : :
191 : 2 : return RVAL_DECODED;
192 : : }
|