blob: 3909d5192b1c80cd3cc7789d1850af1f4d4f7a8f [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000028 */
29
30#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000031#include <linux/version.h>
Wichert Akkermand856b992000-10-13 12:47:12 +000032#include <sys/timex.h>
Roland McGrathd83c50b2004-10-06 22:27:43 +000033#include <linux/ioctl.h>
34#include <linux/rtc.h>
Roland McGrath6afc5652007-07-24 01:57:11 +000035
36#ifndef UTIME_NOW
37#define UTIME_NOW ((1l << 30) - 1l)
38#endif
39#ifndef UTIME_OMIT
40#define UTIME_OMIT ((1l << 30) - 2l)
41#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042
Dmitry V. Levina7945a32006-12-13 17:10:11 +000043struct timeval32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044{
Dmitry V. Levina7945a32006-12-13 17:10:11 +000045 u_int32_t tv_sec, tv_usec;
46};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +000048static void
49tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
50{
51 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
52}
53
54static void
55tprint_timeval(struct tcb *tcp, const struct timeval *tv)
56{
57 tprintf("{%lu, %lu}",
58 (unsigned long) tv->tv_sec, (unsigned long) tv->tv_usec);
59}
60
Dmitry V. Levina7945a32006-12-13 17:10:11 +000061void
Roland McGrath6afc5652007-07-24 01:57:11 +000062printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
Dmitry V. Levina7945a32006-12-13 17:10:11 +000063{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +010064 char buf[TIMEVAL_TEXT_BUFSIZE];
65 sprinttv(buf, tcp, addr, bitness, special);
66 tprints(buf);
Dmitry V. Levina7945a32006-12-13 17:10:11 +000067}
Wichert Akkerman221f54f1999-11-18 17:26:45 +000068
Denys Vlasenko2fb4db32011-08-31 12:26:03 +020069char *
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +010070sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000071{
Denys Vlasenko2fb4db32011-08-31 12:26:03 +020072 int rc;
73
Dmitry V. Levina7945a32006-12-13 17:10:11 +000074 if (addr == 0)
Denys Vlasenko2fb4db32011-08-31 12:26:03 +020075 return stpcpy(buf, "NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000076
Denys Vlasenkob9c7ae62011-09-01 11:40:40 +020077 if (!verbose(tcp))
78 return buf + sprintf(buf, "%#lx", addr);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +020079
80 if (bitness == BITNESS_32
Denys Vlasenko84703742012-02-25 02:38:52 +010081#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenko9fd4f962012-03-19 09:36:42 +010082 || current_wordsize == 4
Denys Vlasenko2fb4db32011-08-31 12:26:03 +020083#endif
84 )
85 {
86 struct timeval32 tv;
87
88 rc = umove(tcp, addr, &tv);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +010089 if (rc >= 0) {
90 if (special && tv.tv_sec == 0) {
91 if (tv.tv_usec == UTIME_NOW)
92 return stpcpy(buf, "UTIME_NOW");
93 if (tv.tv_usec == UTIME_OMIT)
94 return stpcpy(buf, "UTIME_OMIT");
95 }
Denys Vlasenkob9c7ae62011-09-01 11:40:40 +020096 return buf + sprintf(buf, "{%u, %u}",
Denys Vlasenko2fb4db32011-08-31 12:26:03 +020097 tv.tv_sec, tv.tv_usec);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +010098 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +020099 } else {
100 struct timeval tv;
101
102 rc = umove(tcp, addr, &tv);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100103 if (rc >= 0) {
104 if (special && tv.tv_sec == 0) {
105 if (tv.tv_usec == UTIME_NOW)
106 return stpcpy(buf, "UTIME_NOW");
107 if (tv.tv_usec == UTIME_OMIT)
108 return stpcpy(buf, "UTIME_OMIT");
109 }
Denys Vlasenkob9c7ae62011-09-01 11:40:40 +0200110 return buf + sprintf(buf, "{%lu, %lu}",
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200111 (unsigned long) tv.tv_sec,
112 (unsigned long) tv.tv_usec);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100113 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200114 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200115
Denys Vlasenkob9c7ae62011-09-01 11:40:40 +0200116 return stpcpy(buf, "{...}");
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000117}
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000118
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100119void
120print_timespec(struct tcb *tcp, long addr)
Roland McGrath6bc09da2007-11-01 21:50:54 +0000121{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100122 char buf[TIMESPEC_TEXT_BUFSIZE];
123 sprint_timespec(buf, tcp, addr);
124 tprints(buf);
Roland McGrath6bc09da2007-11-01 21:50:54 +0000125}
126
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100127void
128sprint_timespec(char *buf, struct tcb *tcp, long addr)
Roland McGrath6bc09da2007-11-01 21:50:54 +0000129{
130 if (addr == 0)
131 strcpy(buf, "NULL");
132 else if (!verbose(tcp))
133 sprintf(buf, "%#lx", addr);
134 else {
Denys Vlasenko1d632462009-04-14 12:51:00 +0000135 int rc;
Roland McGrath6bc09da2007-11-01 21:50:54 +0000136
Denys Vlasenko84703742012-02-25 02:38:52 +0100137#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100138 if (current_wordsize == 4) {
Roland McGrath6bc09da2007-11-01 21:50:54 +0000139 struct timeval32 tv;
140
Denys Vlasenko5d645812011-08-20 12:48:18 +0200141 rc = umove(tcp, addr, &tv);
142 if (rc >= 0)
Roland McGrath6bc09da2007-11-01 21:50:54 +0000143 sprintf(buf, "{%u, %u}",
144 tv.tv_sec, tv.tv_usec);
145 } else
Roland McGrath6bc09da2007-11-01 21:50:54 +0000146#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +0000147 {
Roland McGrath6bc09da2007-11-01 21:50:54 +0000148 struct timespec ts;
149
Denys Vlasenko5d645812011-08-20 12:48:18 +0200150 rc = umove(tcp, addr, &ts);
151 if (rc >= 0)
Roland McGrath6bc09da2007-11-01 21:50:54 +0000152 sprintf(buf, "{%lu, %lu}",
153 (unsigned long) ts.tv_sec,
154 (unsigned long) ts.tv_nsec);
Roland McGrath6bc09da2007-11-01 21:50:54 +0000155 }
Roland McGrath6bc09da2007-11-01 21:50:54 +0000156 if (rc < 0)
157 strcpy(buf, "{...}");
158 }
159}
160
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161int
Denys Vlasenko12014262011-05-30 14:00:14 +0200162sys_time(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163{
164 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165 printnum(tcp, tcp->u_arg[0], "%ld");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166 }
167 return 0;
168}
169
170int
Denys Vlasenko12014262011-05-30 14:00:14 +0200171sys_stime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172{
173 if (exiting(tcp)) {
174 printnum(tcp, tcp->u_arg[0], "%ld");
175 }
176 return 0;
177}
178
179int
Denys Vlasenko12014262011-05-30 14:00:14 +0200180sys_gettimeofday(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181{
182 if (exiting(tcp)) {
183 if (syserror(tcp)) {
184 tprintf("%#lx, %#lx",
185 tcp->u_arg[0], tcp->u_arg[1]);
186 return 0;
187 }
188 printtv(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200189 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000190 printtv(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191 }
192 return 0;
193}
194
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000195#ifdef ALPHA
196int
Denys Vlasenko12014262011-05-30 14:00:14 +0200197sys_osf_gettimeofday(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000198{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000199 if (exiting(tcp)) {
200 if (syserror(tcp)) {
201 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
202 return 0;
203 }
204 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200205 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000206 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000207 }
208 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000209}
210#endif
211
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000212int
Denys Vlasenko12014262011-05-30 14:00:14 +0200213sys_settimeofday(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000214{
215 if (entering(tcp)) {
216 printtv(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200217 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218 printtv(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000219 }
220 return 0;
221}
222
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000223#ifdef ALPHA
224int
Denys Vlasenko12014262011-05-30 14:00:14 +0200225sys_osf_settimeofday(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000226{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000227 if (entering(tcp)) {
228 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200229 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000230 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000231 }
232 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000233}
234#endif
235
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236int
Denys Vlasenko12014262011-05-30 14:00:14 +0200237sys_adjtime(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238{
239 if (entering(tcp)) {
240 printtv(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200241 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242 } else {
243 if (syserror(tcp))
244 tprintf("%#lx", tcp->u_arg[1]);
245 else
246 printtv(tcp, tcp->u_arg[1]);
247 }
248 return 0;
249}
250
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000251int
252sys_nanosleep(struct tcb *tcp)
253{
254 if (entering(tcp)) {
255 print_timespec(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200256 tprints(", ");
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000257 } else {
Denys Vlasenko64acaa12012-01-28 02:29:36 +0100258 /* Second (returned) timespec is only significant
Denys Vlasenko47932212013-06-30 23:53:49 +0200259 * if syscall was interrupted. On success, we print
260 * only its address, since kernel doesn't modify it,
261 * and printing the value may show uninitialized data.
Denys Vlasenko64acaa12012-01-28 02:29:36 +0100262 */
Denys Vlasenko47932212013-06-30 23:53:49 +0200263 switch (tcp->u_error) {
264 default:
265 /* Not interrupted (slept entire interval) */
266 if (tcp->u_arg[1]) {
267 tprintf("%#lx", tcp->u_arg[1]);
268 break;
269 }
270 /* Fall through: print_timespec(NULL) prints "NULL" */
271 case ERESTARTSYS:
272 case ERESTARTNOINTR:
273 case ERESTARTNOHAND:
274 case ERESTART_RESTARTBLOCK:
275 /* Interrupted */
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000276 print_timespec(tcp, tcp->u_arg[1]);
Denys Vlasenko47932212013-06-30 23:53:49 +0200277 }
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000278 }
279 return 0;
280}
281
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000282static const struct xlat itimer_which[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000283 XLAT(ITIMER_REAL),
284 XLAT(ITIMER_VIRTUAL),
285 XLAT(ITIMER_PROF),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000286 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000287};
288
289static void
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000290printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000292 if (addr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200293 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294 else if (!verbose(tcp))
295 tprintf("%#lx", addr);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000296 else {
297 int rc;
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000298
299 if (bitness == BITNESS_32
Denys Vlasenko84703742012-02-25 02:38:52 +0100300#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100301 || current_wordsize == 4
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000302#endif
303 )
304 {
Denys Vlasenko1d632462009-04-14 12:51:00 +0000305 struct {
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000306 struct timeval32 it_interval, it_value;
307 } itv;
308
Denys Vlasenko5d645812011-08-20 12:48:18 +0200309 rc = umove(tcp, addr, &itv);
310 if (rc >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200311 tprints("{it_interval=");
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000312 tprint_timeval32(tcp, &itv.it_interval);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200313 tprints(", it_value=");
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000314 tprint_timeval32(tcp, &itv.it_value);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200315 tprints("}");
Roland McGrathe4662342007-08-02 01:25:34 +0000316 }
Denys Vlasenko1d632462009-04-14 12:51:00 +0000317 } else {
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000318 struct itimerval itv;
319
Denys Vlasenko5d645812011-08-20 12:48:18 +0200320 rc = umove(tcp, addr, &itv);
321 if (rc >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200322 tprints("{it_interval=");
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000323 tprint_timeval(tcp, &itv.it_interval);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200324 tprints(", it_value=");
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000325 tprint_timeval(tcp, &itv.it_value);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200326 tprints("}");
Roland McGrathe4662342007-08-02 01:25:34 +0000327 }
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000328 }
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000329 if (rc < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200330 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000331 }
332}
333
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000334#define printitv(tcp, addr) \
335 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000336
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337int
Denys Vlasenko12014262011-05-30 14:00:14 +0200338sys_getitimer(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000339{
340 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000341 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200342 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000343 } else {
344 if (syserror(tcp))
345 tprintf("%#lx", tcp->u_arg[1]);
346 else
347 printitv(tcp, tcp->u_arg[1]);
348 }
349 return 0;
350}
351
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000352#ifdef ALPHA
353int
Denys Vlasenko12014262011-05-30 14:00:14 +0200354sys_osf_getitimer(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000355{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000356 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000357 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200358 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000359 } else {
360 if (syserror(tcp))
361 tprintf("%#lx", tcp->u_arg[1]);
362 else
363 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
364 }
365 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000366}
367#endif
368
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369int
Denys Vlasenko12014262011-05-30 14:00:14 +0200370sys_setitimer(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371{
372 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000373 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200374 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375 printitv(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200376 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377 } else {
378 if (syserror(tcp))
379 tprintf("%#lx", tcp->u_arg[2]);
380 else
381 printitv(tcp, tcp->u_arg[2]);
382 }
383 return 0;
384}
385
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000386#ifdef ALPHA
387int
Denys Vlasenko12014262011-05-30 14:00:14 +0200388sys_osf_setitimer(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000389{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000390 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000391 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200392 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000393 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200394 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000395 } else {
396 if (syserror(tcp))
397 tprintf("%#lx", tcp->u_arg[2]);
398 else
399 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
400 }
401 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000402}
403#endif
404
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000405static const struct xlat adjtimex_modes[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000406 XLAT(0),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000407#ifdef ADJ_OFFSET
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000408 XLAT(ADJ_OFFSET),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000409#endif
410#ifdef ADJ_FREQUENCY
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000411 XLAT(ADJ_FREQUENCY),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000412#endif
413#ifdef ADJ_MAXERROR
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000414 XLAT(ADJ_MAXERROR),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000415#endif
416#ifdef ADJ_ESTERROR
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000417 XLAT(ADJ_ESTERROR),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000418#endif
419#ifdef ADJ_STATUS
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000420 XLAT(ADJ_STATUS),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000421#endif
422#ifdef ADJ_TIMECONST
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000423 XLAT(ADJ_TIMECONST),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000424#endif
Stefan Sørensencdf022a2014-01-31 12:01:02 +0100425#ifdef ADJ_TAI
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000426 XLAT(ADJ_TAI),
Stefan Sørensencdf022a2014-01-31 12:01:02 +0100427#endif
428#ifdef ADJ_SETOFFSET
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000429 XLAT(ADJ_SETOFFSET),
Stefan Sørensencdf022a2014-01-31 12:01:02 +0100430#endif
431#ifdef ADJ_MICRO
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000432 XLAT(ADJ_MICRO),
Stefan Sørensencdf022a2014-01-31 12:01:02 +0100433#endif
434#ifdef ADJ_NANO
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000435 XLAT(ADJ_NANO),
Stefan Sørensencdf022a2014-01-31 12:01:02 +0100436#endif
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000437#ifdef ADJ_TICK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000438 XLAT(ADJ_TICK),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000439#endif
440#ifdef ADJ_OFFSET_SINGLESHOT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000441 XLAT(ADJ_OFFSET_SINGLESHOT),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000442#endif
Stefan Sørensencdf022a2014-01-31 12:01:02 +0100443#ifdef ADJ_OFFSET_SS_READ
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000444 XLAT(ADJ_OFFSET_SS_READ),
Stefan Sørensencdf022a2014-01-31 12:01:02 +0100445#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000446 XLAT_END
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000447};
448
449static const struct xlat adjtimex_status[] = {
450#ifdef STA_PLL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000451 XLAT(STA_PLL),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000452#endif
453#ifdef STA_PPSFREQ
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000454 XLAT(STA_PPSFREQ),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000455#endif
456#ifdef STA_PPSTIME
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000457 XLAT(STA_PPSTIME),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000458#endif
459#ifdef STA_FLL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000460 XLAT(STA_FLL),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000461#endif
462#ifdef STA_INS
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000463 XLAT(STA_INS),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000464#endif
465#ifdef STA_DEL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000466 XLAT(STA_DEL),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000467#endif
468#ifdef STA_UNSYNC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000469 XLAT(STA_UNSYNC),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000470#endif
471#ifdef STA_FREQHOLD
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000472 XLAT(STA_FREQHOLD),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000473#endif
474#ifdef STA_PPSSIGNAL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000475 XLAT(STA_PPSSIGNAL),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000476#endif
477#ifdef STA_PPSJITTER
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000478 XLAT(STA_PPSJITTER),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000479#endif
480#ifdef STA_PPSWANDER
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000481 XLAT(STA_PPSWANDER),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000482#endif
483#ifdef STA_PPSERROR
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000484 XLAT(STA_PPSERROR),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000485#endif
486#ifdef STA_CLOCKERR
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000487 XLAT(STA_CLOCKERR),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000488#endif
Dmitry V. Levina28fbfd2012-05-01 21:17:51 +0000489#ifdef STA_NANO
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000490 XLAT(STA_NANO),
Dmitry V. Levina28fbfd2012-05-01 21:17:51 +0000491#endif
492#ifdef STA_MODE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000493 XLAT(STA_MODE),
Dmitry V. Levina28fbfd2012-05-01 21:17:51 +0000494#endif
495#ifdef STA_CLK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000496 XLAT(STA_CLK),
Dmitry V. Levina28fbfd2012-05-01 21:17:51 +0000497#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000498 XLAT_END
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000499};
500
501static const struct xlat adjtimex_state[] = {
502#ifdef TIME_OK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000503 XLAT(TIME_OK),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000504#endif
505#ifdef TIME_INS
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000506 XLAT(TIME_INS),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000507#endif
508#ifdef TIME_DEL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000509 XLAT(TIME_DEL),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000510#endif
511#ifdef TIME_OOP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000512 XLAT(TIME_OOP),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000513#endif
514#ifdef TIME_WAIT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000515 XLAT(TIME_WAIT),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000516#endif
517#ifdef TIME_ERROR
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000518 XLAT(TIME_ERROR),
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000519#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000520 XLAT_END
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000521};
522
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000523#if SUPPORTED_PERSONALITIES > 1
524static int
525tprint_timex32(struct tcb *tcp, long addr)
526{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000527 struct {
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000528 unsigned int modes;
529 int offset;
530 int freq;
531 int maxerror;
532 int esterror;
533 int status;
534 int constant;
535 int precision;
536 int tolerance;
537 struct timeval32 time;
538 int tick;
539 int ppsfreq;
540 int jitter;
541 int shift;
542 int stabil;
543 int jitcnt;
544 int calcnt;
545 int errcnt;
546 int stbcnt;
547 } tx;
548
549 if (umove(tcp, addr, &tx) < 0)
550 return -1;
551
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200552 tprints("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000553 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000554 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
555 tx.offset, tx.freq, tx.maxerror);
556 tprintf("esterror=%u, status=", tx.esterror);
557 printflags(adjtimex_status, tx.status, "STA_???");
558 tprintf(", constant=%d, precision=%u, ",
559 tx.constant, tx.precision);
560 tprintf("tolerance=%d, time=", tx.tolerance);
561 tprint_timeval32(tcp, &tx.time);
562 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
563 tx.tick, tx.ppsfreq, tx.jitter);
564 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
565 tx.shift, tx.stabil, tx.jitcnt);
566 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
567 tx.calcnt, tx.errcnt, tx.stbcnt);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200568 tprints("}");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000569 return 0;
570}
571#endif /* SUPPORTED_PERSONALITIES > 1 */
572
573static int
574tprint_timex(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575{
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000576 struct timex tx;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000578#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100579 if (current_wordsize == 4)
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000580 return tprint_timex32(tcp, addr);
581#endif
582 if (umove(tcp, addr, &tx) < 0)
583 return -1;
584
585#if LINUX_VERSION_CODE < 66332
586 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
587 tx.mode, tx.offset, tx.frequency);
588 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
589 tx.maxerror, tx.esterror, tx.status);
590 tprintf("time_constant=%ld, precision=%lu, ",
591 tx.time_constant, tx.precision);
592 tprintf("tolerance=%ld, time=", tx.tolerance);
593 tprint_timeval(tcp, &tx.time);
594#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200595 tprints("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000596 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000597 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
H.J. Lu0b315b62012-02-03 10:16:03 -0800598 (long) tx.offset, (long) tx.freq, (long) tx.maxerror);
599 tprintf("esterror=%lu, status=", (long) tx.esterror);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000600 printflags(adjtimex_status, tx.status, "STA_???");
601 tprintf(", constant=%ld, precision=%lu, ",
H.J. Lu0b315b62012-02-03 10:16:03 -0800602 (long) tx.constant, (long) tx.precision);
603 tprintf("tolerance=%ld, time=", (long) tx.tolerance);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000604 tprint_timeval(tcp, &tx.time);
605 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
H.J. Lu0b315b62012-02-03 10:16:03 -0800606 (long) tx.tick, (long) tx.ppsfreq, (long) tx.jitter);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000607 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
H.J. Lu0b315b62012-02-03 10:16:03 -0800608 tx.shift, (long) tx.stabil, (long) tx.jitcnt);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000609 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
H.J. Lu0b315b62012-02-03 10:16:03 -0800610 (long) tx.calcnt, (long) tx.errcnt, (long) tx.stbcnt);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000611#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200612 tprints("}");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000613 return 0;
614}
615
Dmitry V. Levin73215472012-03-11 21:25:51 +0000616static int
617do_adjtimex(struct tcb *tcp, long addr)
618{
619 if (addr == 0)
620 tprints("NULL");
621 else if (syserror(tcp) || !verbose(tcp))
622 tprintf("%#lx", addr);
623 else if (tprint_timex(tcp, addr) < 0)
624 tprints("{...}");
625 if (syserror(tcp))
626 return 0;
627 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
628 if (tcp->auxstr)
629 return RVAL_STR;
630 return 0;
631}
632
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000633int
634sys_adjtimex(struct tcb *tcp)
635{
Dmitry V. Levin73215472012-03-11 21:25:51 +0000636 if (exiting(tcp))
637 return do_adjtimex(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000638 return 0;
639}
Roland McGrath1e356792003-03-30 23:52:28 +0000640
Roland McGrathd9f816f2004-09-04 03:39:20 +0000641static const struct xlat clockflags[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000642 XLAT(TIMER_ABSTIME),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000643 XLAT_END
Roland McGrath1e356792003-03-30 23:52:28 +0000644};
645
Roland McGrathd9f816f2004-09-04 03:39:20 +0000646static const struct xlat clocknames[] = {
Roland McGrath55a00f82004-08-31 08:26:39 +0000647#ifdef CLOCK_REALTIME
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000648 XLAT(CLOCK_REALTIME),
Roland McGrath55a00f82004-08-31 08:26:39 +0000649#endif
650#ifdef CLOCK_MONOTONIC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000651 XLAT(CLOCK_MONOTONIC),
Roland McGrath55a00f82004-08-31 08:26:39 +0000652#endif
Dmitry V. Levincbaaf792010-09-17 09:19:49 +0000653#ifdef CLOCK_PROCESS_CPUTIME_ID
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000654 XLAT(CLOCK_PROCESS_CPUTIME_ID),
Dmitry V. Levincbaaf792010-09-17 09:19:49 +0000655#endif
656#ifdef CLOCK_THREAD_CPUTIME_ID
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000657 XLAT(CLOCK_THREAD_CPUTIME_ID),
Dmitry V. Levincbaaf792010-09-17 09:19:49 +0000658#endif
659#ifdef CLOCK_MONOTONIC_RAW
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000660 XLAT(CLOCK_MONOTONIC_RAW),
Dmitry V. Levincbaaf792010-09-17 09:19:49 +0000661#endif
662#ifdef CLOCK_REALTIME_COARSE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000663 XLAT(CLOCK_REALTIME_COARSE),
Dmitry V. Levincbaaf792010-09-17 09:19:49 +0000664#endif
665#ifdef CLOCK_MONOTONIC_COARSE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000666 XLAT(CLOCK_MONOTONIC_COARSE),
Dmitry V. Levincbaaf792010-09-17 09:19:49 +0000667#endif
Dmitry V. Levinfb7ae842014-04-17 14:01:42 +0000668#ifdef CLOCK_BOOTTIME
669 XLAT(CLOCK_BOOTTIME),
670#endif
671#ifdef CLOCK_REALTIME_ALARM
672 XLAT(CLOCK_REALTIME_ALARM),
673#endif
674#ifdef CLOCK_BOOTTIME_ALARM
675 XLAT(CLOCK_BOOTTIME_ALARM),
676#endif
677#ifdef CLOCK_SGI_CYCLE
678 XLAT(CLOCK_SGI_CYCLE),
679#endif
680#ifdef CLOCK_TAI
681 XLAT(CLOCK_TAI),
682#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000683 XLAT_END
Roland McGrath54a4edd2004-08-31 06:52:45 +0000684};
685
Stefan Sørensena5fea902014-02-03 10:01:27 +0100686#ifdef CLOCKID_TO_FD
687static const struct xlat cpuclocknames[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000688 XLAT(CPUCLOCK_PROF),
689 XLAT(CPUCLOCK_VIRT),
690 XLAT(CPUCLOCK_SCHED),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000691 XLAT_END
Stefan Sørensena5fea902014-02-03 10:01:27 +0100692};
693#endif
694
695static void
696printclockname(int clockid)
697{
698#ifdef CLOCKID_TO_FD
699 if (clockid < 0) {
700 if ((clockid & CLOCKFD_MASK) == CLOCKFD)
701 tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
702 else {
703 if(CPUCLOCK_PERTHREAD(clockid))
704 tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
705 else
706 tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
707 printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
708 tprints(")");
709 }
710 }
711 else
712#endif
713 printxval(clocknames, clockid, "CLOCK_???");
714}
715
Roland McGrath1e356792003-03-30 23:52:28 +0000716int
Denys Vlasenko12014262011-05-30 14:00:14 +0200717sys_clock_settime(struct tcb *tcp)
Roland McGrath1e356792003-03-30 23:52:28 +0000718{
719 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100720 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200721 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000722 printtv(tcp, tcp->u_arg[1]);
723 }
724 return 0;
725}
726
727int
Denys Vlasenko12014262011-05-30 14:00:14 +0200728sys_clock_gettime(struct tcb *tcp)
Roland McGrath1e356792003-03-30 23:52:28 +0000729{
730 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100731 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200732 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000733 } else {
734 if (syserror(tcp))
735 tprintf("%#lx", tcp->u_arg[1]);
736 else
737 printtv(tcp, tcp->u_arg[1]);
738 }
739 return 0;
740}
741
742int
Denys Vlasenko12014262011-05-30 14:00:14 +0200743sys_clock_nanosleep(struct tcb *tcp)
Roland McGrath1e356792003-03-30 23:52:28 +0000744{
745 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100746 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200747 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000748 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200749 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000750 printtv(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200751 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000752 } else {
753 if (syserror(tcp))
754 tprintf("%#lx", tcp->u_arg[3]);
755 else
756 printtv(tcp, tcp->u_arg[3]);
757 }
758 return 0;
759}
760
Dmitry V. Levin73215472012-03-11 21:25:51 +0000761int
762sys_clock_adjtime(struct tcb *tcp)
763{
764 if (exiting(tcp))
765 return do_adjtimex(tcp, tcp->u_arg[1]);
Stefan Sørensena5fea902014-02-03 10:01:27 +0100766 printclockname(tcp->u_arg[0]);
Dmitry V. Levin73215472012-03-11 21:25:51 +0000767 tprints(", ");
768 return 0;
769}
770
Roland McGrath1e356792003-03-30 23:52:28 +0000771#ifndef SIGEV_THREAD_ID
772# define SIGEV_THREAD_ID 4
773#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000774static const struct xlat sigev_value[] = {
Dmitry V. Levinbae549e2014-02-05 01:46:10 +0000775 XLAT(SIGEV_SIGNAL),
776 XLAT(SIGEV_NONE),
777 XLAT(SIGEV_THREAD),
778 XLAT(SIGEV_THREAD_ID),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000779 XLAT_END
Roland McGrath1e356792003-03-30 23:52:28 +0000780};
781
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000782#if SUPPORTED_PERSONALITIES > 1
783static void
784printsigevent32(struct tcb *tcp, long arg)
785{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000786 struct {
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000787 int sigev_value;
788 int sigev_signo;
789 int sigev_notify;
790
Denys Vlasenko1d632462009-04-14 12:51:00 +0000791 union {
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000792 int tid;
Denys Vlasenko1d632462009-04-14 12:51:00 +0000793 struct {
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000794 int function, attribute;
795 } thread;
796 } un;
797 } sev;
798
799 if (umove(tcp, arg, &sev) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200800 tprints("{...}");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000801 else {
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000802 tprintf("{%#x, ", sev.sigev_value);
803 if (sev.sigev_notify == SIGEV_SIGNAL)
804 tprintf("%s, ", signame(sev.sigev_signo));
805 else
806 tprintf("%u, ", sev.sigev_signo);
Dmitry V. Levinbae549e2014-02-05 01:46:10 +0000807 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200808 tprints(", ");
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000809 if (sev.sigev_notify == SIGEV_THREAD_ID)
810 tprintf("{%d}", sev.un.tid);
811 else if (sev.sigev_notify == SIGEV_THREAD)
812 tprintf("{%#x, %#x}",
813 sev.un.thread.function,
814 sev.un.thread.attribute);
815 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200816 tprints("{...}");
817 tprints("}");
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000818 }
819}
820#endif
821
Roland McGrath1e356792003-03-30 23:52:28 +0000822void
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000823printsigevent(struct tcb *tcp, long arg)
Roland McGrath1e356792003-03-30 23:52:28 +0000824{
825 struct sigevent sev;
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000826
827#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100828 if (current_wordsize == 4) {
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000829 printsigevent32(tcp, arg);
830 return;
831 }
832#endif
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200833 if (umove(tcp, arg, &sev) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200834 tprints("{...}");
Roland McGrath1e356792003-03-30 23:52:28 +0000835 else {
Roland McGrath675d4a62004-09-11 08:12:45 +0000836 tprintf("{%p, ", sev.sigev_value.sival_ptr);
837 if (sev.sigev_notify == SIGEV_SIGNAL)
838 tprintf("%s, ", signame(sev.sigev_signo));
839 else
840 tprintf("%u, ", sev.sigev_signo);
Dmitry V. Levinbae549e2014-02-05 01:46:10 +0000841 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200842 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000843 if (sev.sigev_notify == SIGEV_THREAD_ID)
Dmitry V. Levinae5aa472013-11-11 23:54:30 +0000844#if defined(HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD)
Roland McGrath1e356792003-03-30 23:52:28 +0000845 /* _pad[0] is the _tid field which might not be
846 present in the userlevel definition of the
847 struct. */
848 tprintf("{%d}", sev._sigev_un._pad[0]);
Dmitry V. Levinae5aa472013-11-11 23:54:30 +0000849#elif defined(HAVE_STRUCT_SIGEVENT___PAD)
850 tprintf("{%d}", sev.__pad[0]);
851#else
852# warning unfamiliar struct sigevent => incomplete SIGEV_THREAD_ID decoding
853 tprints("{...}");
854#endif
Roland McGrathd4c85eb2004-04-16 21:48:44 +0000855 else if (sev.sigev_notify == SIGEV_THREAD)
856 tprintf("{%p, %p}", sev.sigev_notify_function,
857 sev.sigev_notify_attributes);
Roland McGrath1e356792003-03-30 23:52:28 +0000858 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200859 tprints("{...}");
860 tprints("}");
Roland McGrath1e356792003-03-30 23:52:28 +0000861 }
862}
863
864int
Denys Vlasenko12014262011-05-30 14:00:14 +0200865sys_timer_create(struct tcb *tcp)
Roland McGrath1e356792003-03-30 23:52:28 +0000866{
867 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100868 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200869 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000870 printsigevent(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200871 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000872 } else {
Andi Kleen732f3962011-06-13 21:37:40 +0000873 int timer_id;
Dmitry V. Levinac518d12006-12-13 17:03:02 +0000874
Andi Kleen732f3962011-06-13 21:37:40 +0000875 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
Roland McGrath1e356792003-03-30 23:52:28 +0000876 tprintf("%#lx", tcp->u_arg[2]);
Dmitry V. Levinac518d12006-12-13 17:03:02 +0000877 else
Andi Kleen732f3962011-06-13 21:37:40 +0000878 tprintf("{%d}", timer_id);
Roland McGrath1e356792003-03-30 23:52:28 +0000879 }
880 return 0;
881}
882
883int
Denys Vlasenko12014262011-05-30 14:00:14 +0200884sys_timer_settime(struct tcb *tcp)
Roland McGrath1e356792003-03-30 23:52:28 +0000885{
886 if (entering(tcp)) {
887 tprintf("%#lx, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000888 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200889 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000890 printitv(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200891 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000892 } else {
893 if (syserror(tcp))
894 tprintf("%#lx", tcp->u_arg[3]);
895 else
896 printitv(tcp, tcp->u_arg[3]);
897 }
898 return 0;
899}
900
901int
Denys Vlasenko12014262011-05-30 14:00:14 +0200902sys_timer_gettime(struct tcb *tcp)
Roland McGrath1e356792003-03-30 23:52:28 +0000903{
904 if (entering(tcp)) {
905 tprintf("%#lx, ", tcp->u_arg[0]);
906 } else {
907 if (syserror(tcp))
908 tprintf("%#lx", tcp->u_arg[1]);
909 else
910 printitv(tcp, tcp->u_arg[1]);
911 }
912 return 0;
913}
Roland McGrathd83c50b2004-10-06 22:27:43 +0000914
915static void
Denys Vlasenko12014262011-05-30 14:00:14 +0200916print_rtc(struct tcb *tcp, const struct rtc_time *rt)
Roland McGrathd83c50b2004-10-06 22:27:43 +0000917{
918 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
919 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
920 rt->tm_sec, rt->tm_min, rt->tm_hour,
921 rt->tm_mday, rt->tm_mon, rt->tm_year);
922 if (!abbrev(tcp))
923 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
924 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
925 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200926 tprints("...}");
Roland McGrathd83c50b2004-10-06 22:27:43 +0000927}
928
929int
Denys Vlasenko12014262011-05-30 14:00:14 +0200930rtc_ioctl(struct tcb *tcp, long code, long arg)
Roland McGrathd83c50b2004-10-06 22:27:43 +0000931{
932 switch (code) {
933 case RTC_ALM_SET:
934 case RTC_SET_TIME:
935 if (entering(tcp)) {
936 struct rtc_time rt;
937 if (umove(tcp, arg, &rt) < 0)
938 tprintf(", %#lx", arg);
939 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200940 tprints(", ");
Roland McGrathd83c50b2004-10-06 22:27:43 +0000941 print_rtc(tcp, &rt);
942 }
943 }
944 break;
945 case RTC_ALM_READ:
946 case RTC_RD_TIME:
947 if (exiting(tcp)) {
948 struct rtc_time rt;
949 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
950 tprintf(", %#lx", arg);
951 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200952 tprints(", ");
Roland McGrathd83c50b2004-10-06 22:27:43 +0000953 print_rtc(tcp, &rt);
954 }
955 }
956 break;
957 case RTC_IRQP_SET:
958 case RTC_EPOCH_SET:
959 if (entering(tcp))
960 tprintf(", %lu", arg);
961 break;
962 case RTC_IRQP_READ:
963 case RTC_EPOCH_READ:
964 if (exiting(tcp))
965 tprintf(", %lu", arg);
966 break;
967 case RTC_WKALM_SET:
968 if (entering(tcp)) {
969 struct rtc_wkalrm wk;
970 if (umove(tcp, arg, &wk) < 0)
971 tprintf(", %#lx", arg);
972 else {
973 tprintf(", {enabled=%d, pending=%d, ",
974 wk.enabled, wk.pending);
975 print_rtc(tcp, &wk.time);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200976 tprints("}");
Roland McGrathd83c50b2004-10-06 22:27:43 +0000977 }
978 }
979 break;
980 case RTC_WKALM_RD:
981 if (exiting(tcp)) {
982 struct rtc_wkalrm wk;
983 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
984 tprintf(", %#lx", arg);
985 else {
986 tprintf(", {enabled=%d, pending=%d, ",
987 wk.enabled, wk.pending);
988 print_rtc(tcp, &wk.time);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200989 tprints("}");
Roland McGrathd83c50b2004-10-06 22:27:43 +0000990 }
991 }
992 break;
993 default:
994 if (entering(tcp))
995 tprintf(", %#lx", arg);
996 break;
997 }
998 return 1;
999}
Roland McGrathe4662342007-08-02 01:25:34 +00001000
1001#ifndef TFD_TIMER_ABSTIME
1002#define TFD_TIMER_ABSTIME (1 << 0)
1003#endif
1004
1005static const struct xlat timerfdflags[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +00001006 XLAT(TFD_TIMER_ABSTIME),
Dmitry V. Levin59452732014-02-05 02:20:51 +00001007 XLAT_END
Roland McGrathe4662342007-08-02 01:25:34 +00001008};
1009
1010int
Denys Vlasenko12014262011-05-30 14:00:14 +02001011sys_timerfd(struct tcb *tcp)
Roland McGrathe4662342007-08-02 01:25:34 +00001012{
1013 if (entering(tcp)) {
1014 /* It does not matter that the kernel uses itimerspec. */
1015 tprintf("%ld, ", tcp->u_arg[0]);
Stefan Sørensena5fea902014-02-03 10:01:27 +01001016 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001017 tprints(", ");
Roland McGrathe4662342007-08-02 01:25:34 +00001018 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001019 tprints(", ");
Roland McGrathe4662342007-08-02 01:25:34 +00001020 printitv(tcp, tcp->u_arg[3]);
1021 }
1022 return 0;
1023}
Roland McGrathde328e62008-05-20 04:56:13 +00001024
1025int
1026sys_timerfd_create(struct tcb *tcp)
1027{
1028 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +01001029 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001030 tprints(", ");
Roland McGrathde328e62008-05-20 04:56:13 +00001031 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
1032 }
1033 return 0;
1034}
1035
1036int
1037sys_timerfd_settime(struct tcb *tcp)
1038{
1039 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001040 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001041 tprints(", ");
Roland McGrathde328e62008-05-20 04:56:13 +00001042 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001043 tprints(", ");
Roland McGrathde328e62008-05-20 04:56:13 +00001044 printitv(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001045 tprints(", ");
Roland McGrathde328e62008-05-20 04:56:13 +00001046 printitv(tcp, tcp->u_arg[3]);
1047 }
1048 return 0;
1049}
1050
1051int
1052sys_timerfd_gettime(struct tcb *tcp)
1053{
1054 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +03001055 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001056 tprints(", ");
Roland McGrathde328e62008-05-20 04:56:13 +00001057 printitv(tcp, tcp->u_arg[1]);
1058 }
1059 return 0;
1060}