]> granicus.if.org Git - strace/blob - resource.c
xattr: change address argument type from unsigned long to kernel_ureg_t
[strace] / resource.c
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  * 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.
29  */
30
31 #include "defs.h"
32 #include <sys/resource.h>
33
34 #include "xlat/resources.h"
35
36 static const char *
37 sprint_rlim64(uint64_t lim)
38 {
39         static char buf[sizeof(uint64_t)*3 + sizeof("*1024")];
40
41         if (lim == UINT64_MAX)
42                 return "RLIM64_INFINITY";
43
44         if (lim > 1024 && lim % 1024 == 0)
45                 sprintf(buf, "%" PRIu64 "*1024", lim / 1024);
46         else
47                 sprintf(buf, "%" PRIu64, lim);
48         return buf;
49 }
50
51 static void
52 print_rlimit64(struct tcb *const tcp, const kernel_ureg_t addr)
53 {
54         struct rlimit_64 {
55                 uint64_t rlim_cur;
56                 uint64_t rlim_max;
57         } rlim;
58
59         if (!umove_or_printaddr(tcp, addr, &rlim)) {
60                 tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur));
61                 tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max));
62         }
63 }
64
65 #if !defined(current_wordsize) || current_wordsize == 4
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 *const tcp, const kernel_ureg_t addr)
84 {
85         struct rlimit_32 {
86                 uint32_t rlim_cur;
87                 uint32_t rlim_max;
88         } rlim;
89
90         if (!umove_or_printaddr(tcp, addr, &rlim)) {
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 *const tcp, const kernel_ureg_t addr)
98 {
99         /*
100          * i386 is the only personality on X86_64 and X32
101          * with 32-bit rlim_t.
102          * When current_personality is X32, current_wordsize
103          * equals to 4 but rlim_t is 64-bit.
104          */
105         if (current_klongsize == 4)
106                 print_rlimit32(tcp, addr);
107         else
108                 print_rlimit64(tcp, addr);
109 }
110
111 #else /* defined(current_wordsize) && current_wordsize != 4 */
112
113 # define decode_rlimit print_rlimit64
114
115 #endif
116
117 SYS_FUNC(getrlimit)
118 {
119         if (entering(tcp)) {
120                 printxval(resources, tcp->u_arg[0], "RLIMIT_???");
121                 tprints(", ");
122         }
123         else {
124                 decode_rlimit(tcp, tcp->u_arg[1]);
125         }
126         return 0;
127 }
128
129 SYS_FUNC(setrlimit)
130 {
131         printxval(resources, tcp->u_arg[0], "RLIMIT_???");
132         tprints(", ");
133         decode_rlimit(tcp, tcp->u_arg[1]);
134
135         return RVAL_DECODED;
136 }
137
138 SYS_FUNC(prlimit64)
139 {
140         if (entering(tcp)) {
141                 tprintf("%d, ", (int) tcp->u_arg[0]);
142                 printxval(resources, tcp->u_arg[1], "RLIMIT_???");
143                 tprints(", ");
144                 print_rlimit64(tcp, tcp->u_arg[2]);
145                 tprints(", ");
146         } else {
147                 print_rlimit64(tcp, tcp->u_arg[3]);
148         }
149         return 0;
150 }
151
152 #include "xlat/usagewho.h"
153
154 SYS_FUNC(getrusage)
155 {
156         if (entering(tcp)) {
157                 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
158                 tprints(", ");
159         }
160         else
161                 printrusage(tcp, tcp->u_arg[1]);
162         return 0;
163 }
164
165 #ifdef ALPHA
166 SYS_FUNC(osf_getrusage)
167 {
168         if (entering(tcp)) {
169                 printxval(usagewho, tcp->u_arg[0], "RUSAGE_???");
170                 tprints(", ");
171         }
172         else
173                 printrusage32(tcp, tcp->u_arg[1]);
174         return 0;
175 }
176 #endif /* ALPHA */
177
178 #include "xlat/priorities.h"
179
180 SYS_FUNC(getpriority)
181 {
182         printxval(priorities, tcp->u_arg[0], "PRIO_???");
183         tprintf(", %d", (int) tcp->u_arg[1]);
184
185         return RVAL_DECODED;
186 }
187
188 SYS_FUNC(setpriority)
189 {
190         printxval(priorities, tcp->u_arg[0], "PRIO_???");
191         tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);
192
193         return RVAL_DECODED;
194 }