blob: ce309b68c4ef5fd231708ccfd5d167436b4f6e1a [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.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#ifdef LINUX
35#include <linux/version.h>
Wichert Akkermand856b992000-10-13 12:47:12 +000036#include <sys/timex.h>
Roland McGrathd83c50b2004-10-06 22:27:43 +000037#include <linux/ioctl.h>
38#include <linux/rtc.h>
Roland McGrath6afc5652007-07-24 01:57:11 +000039
40#ifndef UTIME_NOW
41#define UTIME_NOW ((1l << 30) - 1l)
42#endif
43#ifndef UTIME_OMIT
44#define UTIME_OMIT ((1l << 30) - 2l)
45#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046#endif /* LINUX */
47
Dmitry V. Levina7945a32006-12-13 17:10:11 +000048struct timeval32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049{
Dmitry V. Levina7945a32006-12-13 17:10:11 +000050 u_int32_t tv_sec, tv_usec;
51};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +000053static void
54tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
55{
56 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
57}
58
59static void
60tprint_timeval(struct tcb *tcp, const struct timeval *tv)
61{
62 tprintf("{%lu, %lu}",
63 (unsigned long) tv->tv_sec, (unsigned long) tv->tv_usec);
64}
65
Dmitry V. Levina7945a32006-12-13 17:10:11 +000066void
Roland McGrath6afc5652007-07-24 01:57:11 +000067printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
Dmitry V. Levina7945a32006-12-13 17:10:11 +000068{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000069 if (addr == 0)
70 tprintf("NULL");
71 else if (!verbose(tcp))
72 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073 else
Dmitry V. Levina7945a32006-12-13 17:10:11 +000074 {
75 int rc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076
Dmitry V. Levina7945a32006-12-13 17:10:11 +000077 if (bitness == BITNESS_32
78#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
79 || personality_wordsize[current_personality] == 4
80#endif
81 )
82 {
83 struct timeval32 tv;
84
Roland McGrath6afc5652007-07-24 01:57:11 +000085 if ((rc = umove(tcp, addr, &tv)) >= 0) {
Roland McGrath41383392007-07-24 01:58:52 +000086 if (special && tv.tv_sec == 0 &&
87 tv.tv_usec == UTIME_NOW)
Roland McGrath6afc5652007-07-24 01:57:11 +000088 tprintf("UTIME_NOW");
Roland McGrath41383392007-07-24 01:58:52 +000089 else if (special && tv.tv_sec == 0 &&
90 tv.tv_usec == UTIME_OMIT)
Roland McGrath6afc5652007-07-24 01:57:11 +000091 tprintf("UTIME_OMIT");
92 else
93 tprint_timeval32(tcp, &tv);
94 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +000095 } else
96 {
97 struct timeval tv;
98
Roland McGrath6afc5652007-07-24 01:57:11 +000099 if ((rc = umove(tcp, addr, &tv)) >= 0) {
Roland McGrath41383392007-07-24 01:58:52 +0000100 if (special && tv.tv_sec == 0 &&
101 tv.tv_usec == UTIME_NOW)
Roland McGrath6afc5652007-07-24 01:57:11 +0000102 tprintf("UTIME_NOW");
Roland McGrath41383392007-07-24 01:58:52 +0000103 else if (special && tv.tv_sec == 0 &&
104 tv.tv_usec == UTIME_OMIT)
Roland McGrath6afc5652007-07-24 01:57:11 +0000105 tprintf("UTIME_OMIT");
106 else
107 tprint_timeval(tcp, &tv);
108 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000109 }
110
111 if (rc < 0)
112 tprintf("{...}");
113 }
114}
Wichert Akkerman221f54f1999-11-18 17:26:45 +0000115
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000116void
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000117sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000118{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000119 if (addr == 0)
120 strcpy(buf, "NULL");
121 else if (!verbose(tcp))
122 sprintf(buf, "%#lx", addr);
123 else
124 {
125 int rc;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000126
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000127 if (bitness == BITNESS_32
128#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
129 || personality_wordsize[current_personality] == 4
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000130#endif
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000131 )
132 {
133 struct timeval32 tv;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000134
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000135 if ((rc = umove(tcp, addr, &tv)) >= 0)
136 sprintf(buf, "{%u, %u}",
137 tv.tv_sec, tv.tv_usec);
138 } else
139 {
140 struct timeval tv;
141
142 if ((rc = umove(tcp, addr, &tv)) >= 0)
143 sprintf(buf, "{%lu, %lu}",
144 (unsigned long) tv.tv_sec,
145 (unsigned long) tv.tv_usec);
146 }
147
148 if (rc < 0)
149 strcpy(buf, "{...}");
150 }
151}
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000152
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153int
154sys_time(tcp)
155struct tcb *tcp;
156{
157 if (exiting(tcp)) {
158#ifndef SVR4
159 printnum(tcp, tcp->u_arg[0], "%ld");
160#endif /* SVR4 */
161 }
162 return 0;
163}
164
165int
166sys_stime(tcp)
167struct tcb *tcp;
168{
169 if (exiting(tcp)) {
170 printnum(tcp, tcp->u_arg[0], "%ld");
171 }
172 return 0;
173}
174
175int
176sys_gettimeofday(tcp)
177struct tcb *tcp;
178{
179 if (exiting(tcp)) {
180 if (syserror(tcp)) {
181 tprintf("%#lx, %#lx",
182 tcp->u_arg[0], tcp->u_arg[1]);
183 return 0;
184 }
185 printtv(tcp, tcp->u_arg[0]);
186#ifndef SVR4
187 tprintf(", ");
188 printtv(tcp, tcp->u_arg[1]);
189#endif /* !SVR4 */
190 }
191 return 0;
192}
193
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000194
195#ifdef ALPHA
196int
197sys_osf_gettimeofday(tcp)
198struct tcb *tcp;
199{
200 if (exiting(tcp)) {
201 if (syserror(tcp)) {
202 tprintf("%#lx, %#lx",
203 tcp->u_arg[0], tcp->u_arg[1]);
204 return 0;
205 }
Roland McGrath6afc5652007-07-24 01:57:11 +0000206 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000207#ifndef SVR4
208 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000209 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000210#endif /* !SVR4 */
211 }
212 return 0;
213}
214#endif
215
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216int
217sys_settimeofday(tcp)
218struct tcb *tcp;
219{
220 if (entering(tcp)) {
221 printtv(tcp, tcp->u_arg[0]);
222#ifndef SVR4
223 tprintf(", ");
224 printtv(tcp, tcp->u_arg[1]);
225#endif /* !SVR4 */
226 }
227 return 0;
228}
229
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000230#ifdef ALPHA
231int
232sys_osf_settimeofday(tcp)
233struct tcb *tcp;
234{
235 if (entering(tcp)) {
Roland McGrath6afc5652007-07-24 01:57:11 +0000236 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000237#ifndef SVR4
238 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000239 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000240#endif /* !SVR4 */
241 }
242 return 0;
243}
244#endif
245
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000246int
247sys_adjtime(tcp)
248struct tcb *tcp;
249{
250 if (entering(tcp)) {
251 printtv(tcp, tcp->u_arg[0]);
252 tprintf(", ");
253 } else {
254 if (syserror(tcp))
255 tprintf("%#lx", tcp->u_arg[1]);
256 else
257 printtv(tcp, tcp->u_arg[1]);
258 }
259 return 0;
260}
261
Roland McGrathd9f816f2004-09-04 03:39:20 +0000262static const struct xlat which[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000263 { ITIMER_REAL, "ITIMER_REAL" },
264 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
265 { ITIMER_PROF, "ITIMER_PROF" },
266 { 0, NULL },
267};
268
269static void
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000270printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000271{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272 if (addr == 0)
273 tprintf("NULL");
274 else if (!verbose(tcp))
275 tprintf("%#lx", addr);
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000276 else
277 {
278 int rc;
279
280 if (bitness == BITNESS_32
281#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
282 || personality_wordsize[current_personality] == 4
283#endif
284 )
285 {
286 struct
287 {
288 struct timeval32 it_interval, it_value;
289 } itv;
290
Roland McGrathe4662342007-08-02 01:25:34 +0000291 if ((rc = umove(tcp, addr, &itv)) >= 0) {
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000292 tprintf("{it_interval=");
293 tprint_timeval32(tcp, &itv.it_interval);
294 tprintf(", it_value=");
295 tprint_timeval32(tcp, &itv.it_value);
296 tprintf("}");
Roland McGrathe4662342007-08-02 01:25:34 +0000297 }
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000298 } else
299 {
300 struct itimerval itv;
301
Roland McGrathe4662342007-08-02 01:25:34 +0000302 if ((rc = umove(tcp, addr, &itv)) >= 0) {
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000303 tprintf("{it_interval=");
304 tprint_timeval(tcp, &itv.it_interval);
305 tprintf(", it_value=");
306 tprint_timeval(tcp, &itv.it_value);
307 tprintf("}");
Roland McGrathe4662342007-08-02 01:25:34 +0000308 }
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000309 }
310
311 if (rc < 0)
312 tprintf("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000313 }
314}
315
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000316#define printitv(tcp, addr) \
317 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000318
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319int
320sys_getitimer(tcp)
321struct tcb *tcp;
322{
323 if (entering(tcp)) {
324 printxval(which, tcp->u_arg[0], "ITIMER_???");
325 tprintf(", ");
326 } else {
327 if (syserror(tcp))
328 tprintf("%#lx", tcp->u_arg[1]);
329 else
330 printitv(tcp, tcp->u_arg[1]);
331 }
332 return 0;
333}
334
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000335
336#ifdef ALPHA
337int
338sys_osf_getitimer(tcp)
339struct tcb *tcp;
340{
341 if (entering(tcp)) {
342 printxval(which, tcp->u_arg[0], "ITIMER_???");
343 tprintf(", ");
344 } else {
345 if (syserror(tcp))
346 tprintf("%#lx", tcp->u_arg[1]);
347 else
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000348 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000349 }
350 return 0;
351}
352#endif
353
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000354int
355sys_setitimer(tcp)
356struct tcb *tcp;
357{
358 if (entering(tcp)) {
359 printxval(which, tcp->u_arg[0], "ITIMER_???");
360 tprintf(", ");
361 printitv(tcp, tcp->u_arg[1]);
362 tprintf(", ");
363 } else {
364 if (syserror(tcp))
365 tprintf("%#lx", tcp->u_arg[2]);
366 else
367 printitv(tcp, tcp->u_arg[2]);
368 }
369 return 0;
370}
371
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000372#ifdef ALPHA
373int
374sys_osf_setitimer(tcp)
375struct tcb *tcp;
376{
377 if (entering(tcp)) {
378 printxval(which, tcp->u_arg[0], "ITIMER_???");
379 tprintf(", ");
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000380 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000381 tprintf(", ");
382 } else {
383 if (syserror(tcp))
384 tprintf("%#lx", tcp->u_arg[2]);
385 else
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000386 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000387 }
388 return 0;
389}
390#endif
391
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392#ifdef LINUX
393
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000394static const struct xlat adjtimex_modes[] = {
395 { 0, "0" },
396#ifdef ADJ_OFFSET
397 { ADJ_OFFSET, "ADJ_OFFSET" },
398#endif
399#ifdef ADJ_FREQUENCY
400 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
401#endif
402#ifdef ADJ_MAXERROR
403 { ADJ_MAXERROR, "ADJ_MAXERROR" },
404#endif
405#ifdef ADJ_ESTERROR
406 { ADJ_ESTERROR, "ADJ_ESTERROR" },
407#endif
408#ifdef ADJ_STATUS
409 { ADJ_STATUS, "ADJ_STATUS" },
410#endif
411#ifdef ADJ_TIMECONST
412 { ADJ_TIMECONST, "ADJ_TIMECONST" },
413#endif
414#ifdef ADJ_TICK
415 { ADJ_TICK, "ADJ_TICK" },
416#endif
417#ifdef ADJ_OFFSET_SINGLESHOT
418 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
419#endif
420 { 0, NULL }
421};
422
423static const struct xlat adjtimex_status[] = {
424#ifdef STA_PLL
425 { STA_PLL, "STA_PLL" },
426#endif
427#ifdef STA_PPSFREQ
428 { STA_PPSFREQ, "STA_PPSFREQ" },
429#endif
430#ifdef STA_PPSTIME
431 { STA_PPSTIME, "STA_PPSTIME" },
432#endif
433#ifdef STA_FLL
434 { STA_FLL, "STA_FLL" },
435#endif
436#ifdef STA_INS
437 { STA_INS, "STA_INS" },
438#endif
439#ifdef STA_DEL
440 { STA_DEL, "STA_DEL" },
441#endif
442#ifdef STA_UNSYNC
443 { STA_UNSYNC, "STA_UNSYNC" },
444#endif
445#ifdef STA_FREQHOLD
446 { STA_FREQHOLD, "STA_FREQHOLD" },
447#endif
448#ifdef STA_PPSSIGNAL
449 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
450#endif
451#ifdef STA_PPSJITTER
452 { STA_PPSJITTER, "STA_PPSJITTER" },
453#endif
454#ifdef STA_PPSWANDER
455 { STA_PPSWANDER, "STA_PPSWANDER" },
456#endif
457#ifdef STA_PPSERROR
458 { STA_PPSERROR, "STA_PPSERROR" },
459#endif
460#ifdef STA_CLOCKERR
461 { STA_CLOCKERR, "STA_CLOCKERR" },
462#endif
463 { 0, NULL }
464};
465
466static const struct xlat adjtimex_state[] = {
467#ifdef TIME_OK
468 { TIME_OK, "TIME_OK" },
469#endif
470#ifdef TIME_INS
471 { TIME_INS, "TIME_INS" },
472#endif
473#ifdef TIME_DEL
474 { TIME_DEL, "TIME_DEL" },
475#endif
476#ifdef TIME_OOP
477 { TIME_OOP, "TIME_OOP" },
478#endif
479#ifdef TIME_WAIT
480 { TIME_WAIT, "TIME_WAIT" },
481#endif
482#ifdef TIME_ERROR
483 { TIME_ERROR, "TIME_ERROR" },
484#endif
485 { 0, NULL }
486};
487
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000488#if SUPPORTED_PERSONALITIES > 1
489static int
490tprint_timex32(struct tcb *tcp, long addr)
491{
492 struct
493 {
494 unsigned int modes;
495 int offset;
496 int freq;
497 int maxerror;
498 int esterror;
499 int status;
500 int constant;
501 int precision;
502 int tolerance;
503 struct timeval32 time;
504 int tick;
505 int ppsfreq;
506 int jitter;
507 int shift;
508 int stabil;
509 int jitcnt;
510 int calcnt;
511 int errcnt;
512 int stbcnt;
513 } tx;
514
515 if (umove(tcp, addr, &tx) < 0)
516 return -1;
517
518 tprintf("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000519 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000520 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
521 tx.offset, tx.freq, tx.maxerror);
522 tprintf("esterror=%u, status=", tx.esterror);
523 printflags(adjtimex_status, tx.status, "STA_???");
524 tprintf(", constant=%d, precision=%u, ",
525 tx.constant, tx.precision);
526 tprintf("tolerance=%d, time=", tx.tolerance);
527 tprint_timeval32(tcp, &tx.time);
528 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
529 tx.tick, tx.ppsfreq, tx.jitter);
530 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
531 tx.shift, tx.stabil, tx.jitcnt);
532 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
533 tx.calcnt, tx.errcnt, tx.stbcnt);
534 tprintf("}");
535 return 0;
536}
537#endif /* SUPPORTED_PERSONALITIES > 1 */
538
539static int
540tprint_timex(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541{
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000542 struct timex tx;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000544#if SUPPORTED_PERSONALITIES > 1
545 if (personality_wordsize[current_personality] == 4)
546 return tprint_timex32(tcp, addr);
547#endif
548 if (umove(tcp, addr, &tx) < 0)
549 return -1;
550
551#if LINUX_VERSION_CODE < 66332
552 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
553 tx.mode, tx.offset, tx.frequency);
554 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
555 tx.maxerror, tx.esterror, tx.status);
556 tprintf("time_constant=%ld, precision=%lu, ",
557 tx.time_constant, tx.precision);
558 tprintf("tolerance=%ld, time=", tx.tolerance);
559 tprint_timeval(tcp, &tx.time);
560#else
561 tprintf("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000562 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000563 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
564 tx.offset, tx.freq, tx.maxerror);
565 tprintf("esterror=%lu, status=", tx.esterror);
566 printflags(adjtimex_status, tx.status, "STA_???");
567 tprintf(", constant=%ld, precision=%lu, ",
568 tx.constant, tx.precision);
569 tprintf("tolerance=%ld, time=", tx.tolerance);
570 tprint_timeval(tcp, &tx.time);
571 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
572 tx.tick, tx.ppsfreq, tx.jitter);
573 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
574 tx.shift, tx.stabil, tx.jitcnt);
575 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
576 tx.calcnt, tx.errcnt, tx.stbcnt);
577#endif
578 tprintf("}");
579 return 0;
580}
581
582int
583sys_adjtimex(struct tcb *tcp)
584{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000585 if (exiting(tcp)) {
586 if (tcp->u_arg[0] == 0)
587 tprintf("NULL");
588 else if (syserror(tcp) || !verbose(tcp))
589 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000590 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591 tprintf("{...}");
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000592 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
593 if (tcp->auxstr)
594 return RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595 }
596 return 0;
597}
Roland McGrath1e356792003-03-30 23:52:28 +0000598
Roland McGrathd9f816f2004-09-04 03:39:20 +0000599static const struct xlat clockflags[] = {
Roland McGrath1e356792003-03-30 23:52:28 +0000600 { TIMER_ABSTIME, "TIMER_ABSTIME" },
601 { 0, NULL }
602};
603
Roland McGrathd9f816f2004-09-04 03:39:20 +0000604static const struct xlat clocknames[] = {
Roland McGrath55a00f82004-08-31 08:26:39 +0000605#ifdef CLOCK_REALTIME
Roland McGrath54a4edd2004-08-31 06:52:45 +0000606 { CLOCK_REALTIME, "CLOCK_REALTIME" },
Roland McGrath55a00f82004-08-31 08:26:39 +0000607#endif
608#ifdef CLOCK_MONOTONIC
Roland McGrath54a4edd2004-08-31 06:52:45 +0000609 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
Roland McGrath55a00f82004-08-31 08:26:39 +0000610#endif
Roland McGrath54a4edd2004-08-31 06:52:45 +0000611 { 0, NULL }
612};
613
Roland McGrath1e356792003-03-30 23:52:28 +0000614int
615sys_clock_settime(tcp)
616struct tcb *tcp;
617{
618 if (entering(tcp)) {
Roland McGrath54a4edd2004-08-31 06:52:45 +0000619 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
620 tprintf(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000621 printtv(tcp, tcp->u_arg[1]);
622 }
623 return 0;
624}
625
626int
627sys_clock_gettime(tcp)
628struct tcb *tcp;
629{
630 if (entering(tcp)) {
Roland McGrath54a4edd2004-08-31 06:52:45 +0000631 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
632 tprintf(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000633 } else {
634 if (syserror(tcp))
635 tprintf("%#lx", tcp->u_arg[1]);
636 else
637 printtv(tcp, tcp->u_arg[1]);
638 }
639 return 0;
640}
641
642int
643sys_clock_nanosleep(tcp)
644struct tcb *tcp;
645{
646 if (entering(tcp)) {
Roland McGrath54a4edd2004-08-31 06:52:45 +0000647 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
648 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000649 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Roland McGrath1e356792003-03-30 23:52:28 +0000650 tprintf(", ");
651 printtv(tcp, tcp->u_arg[2]);
652 tprintf(", ");
653 } else {
654 if (syserror(tcp))
655 tprintf("%#lx", tcp->u_arg[3]);
656 else
657 printtv(tcp, tcp->u_arg[3]);
658 }
659 return 0;
660}
661
662#ifndef SIGEV_THREAD_ID
663# define SIGEV_THREAD_ID 4
664#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000665static const struct xlat sigev_value[] = {
Roland McGrath1e356792003-03-30 23:52:28 +0000666 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
667 { SIGEV_NONE+1, "SIGEV_NONE" },
668 { SIGEV_THREAD+1, "SIGEV_THREAD" },
669 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
670 { 0, NULL }
671};
672
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000673#if SUPPORTED_PERSONALITIES > 1
674static void
675printsigevent32(struct tcb *tcp, long arg)
676{
677 struct
678 {
679 int sigev_value;
680 int sigev_signo;
681 int sigev_notify;
682
683 union
684 {
685 int tid;
686 struct
687 {
688 int function, attribute;
689 } thread;
690 } un;
691 } sev;
692
693 if (umove(tcp, arg, &sev) < 0)
694 tprintf("{...}");
695 else
696 {
697 tprintf("{%#x, ", sev.sigev_value);
698 if (sev.sigev_notify == SIGEV_SIGNAL)
699 tprintf("%s, ", signame(sev.sigev_signo));
700 else
701 tprintf("%u, ", sev.sigev_signo);
702 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
703 tprintf(", ");
704 if (sev.sigev_notify == SIGEV_THREAD_ID)
705 tprintf("{%d}", sev.un.tid);
706 else if (sev.sigev_notify == SIGEV_THREAD)
707 tprintf("{%#x, %#x}",
708 sev.un.thread.function,
709 sev.un.thread.attribute);
710 else
711 tprintf("{...}");
712 tprintf("}");
713 }
714}
715#endif
716
Roland McGrath1e356792003-03-30 23:52:28 +0000717void
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000718printsigevent(struct tcb *tcp, long arg)
Roland McGrath1e356792003-03-30 23:52:28 +0000719{
720 struct sigevent sev;
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000721
722#if SUPPORTED_PERSONALITIES > 1
723 if (personality_wordsize[current_personality] == 4)
724 {
725 printsigevent32(tcp, arg);
726 return;
727 }
728#endif
Roland McGrath1e356792003-03-30 23:52:28 +0000729 if (umove (tcp, arg, &sev) < 0)
730 tprintf("{...}");
731 else {
Roland McGrath675d4a62004-09-11 08:12:45 +0000732 tprintf("{%p, ", sev.sigev_value.sival_ptr);
733 if (sev.sigev_notify == SIGEV_SIGNAL)
734 tprintf("%s, ", signame(sev.sigev_signo));
735 else
736 tprintf("%u, ", sev.sigev_signo);
Roland McGrath1e356792003-03-30 23:52:28 +0000737 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
738 tprintf(", ");
739 if (sev.sigev_notify == SIGEV_THREAD_ID)
740 /* _pad[0] is the _tid field which might not be
741 present in the userlevel definition of the
742 struct. */
743 tprintf("{%d}", sev._sigev_un._pad[0]);
Roland McGrathd4c85eb2004-04-16 21:48:44 +0000744 else if (sev.sigev_notify == SIGEV_THREAD)
745 tprintf("{%p, %p}", sev.sigev_notify_function,
746 sev.sigev_notify_attributes);
Roland McGrath1e356792003-03-30 23:52:28 +0000747 else
748 tprintf("{...}");
749 tprintf("}");
750 }
751}
752
753int
754sys_timer_create(tcp)
755struct tcb *tcp;
756{
757 if (entering(tcp)) {
Roland McGrath675d4a62004-09-11 08:12:45 +0000758 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
759 tprintf(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000760 printsigevent(tcp, tcp->u_arg[1]);
761 tprintf(", ");
762 } else {
Dmitry V. Levinac518d12006-12-13 17:03:02 +0000763 void *p;
764
765 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &p) < 0)
Roland McGrath1e356792003-03-30 23:52:28 +0000766 tprintf("%#lx", tcp->u_arg[2]);
Dmitry V. Levinac518d12006-12-13 17:03:02 +0000767 else
Roland McGrath1e356792003-03-30 23:52:28 +0000768 tprintf("{%p}", p);
Roland McGrath1e356792003-03-30 23:52:28 +0000769 }
770 return 0;
771}
772
773int
774sys_timer_settime(tcp)
775struct tcb *tcp;
776{
777 if (entering(tcp)) {
778 tprintf("%#lx, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000779 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Roland McGrath1e356792003-03-30 23:52:28 +0000780 tprintf(", ");
781 printitv(tcp, tcp->u_arg[2]);
782 tprintf(", ");
783 } else {
784 if (syserror(tcp))
785 tprintf("%#lx", tcp->u_arg[3]);
786 else
787 printitv(tcp, tcp->u_arg[3]);
788 }
789 return 0;
790}
791
792int
793sys_timer_gettime(tcp)
794struct tcb *tcp;
795{
796 if (entering(tcp)) {
797 tprintf("%#lx, ", tcp->u_arg[0]);
798 } else {
799 if (syserror(tcp))
800 tprintf("%#lx", tcp->u_arg[1]);
801 else
802 printitv(tcp, tcp->u_arg[1]);
803 }
804 return 0;
805}
Roland McGrathd83c50b2004-10-06 22:27:43 +0000806
807static void
808print_rtc(tcp, rt)
809struct tcb *tcp;
810const struct rtc_time *rt;
811{
812 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
813 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
814 rt->tm_sec, rt->tm_min, rt->tm_hour,
815 rt->tm_mday, rt->tm_mon, rt->tm_year);
816 if (!abbrev(tcp))
817 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
818 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
819 else
820 tprintf("...}");
821}
822
823int
824rtc_ioctl(tcp, code, arg)
825struct tcb *tcp;
826long code;
827long arg;
828{
829 switch (code) {
830 case RTC_ALM_SET:
831 case RTC_SET_TIME:
832 if (entering(tcp)) {
833 struct rtc_time rt;
834 if (umove(tcp, arg, &rt) < 0)
835 tprintf(", %#lx", arg);
836 else {
837 tprintf(", ");
838 print_rtc(tcp, &rt);
839 }
840 }
841 break;
842 case RTC_ALM_READ:
843 case RTC_RD_TIME:
844 if (exiting(tcp)) {
845 struct rtc_time rt;
846 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
847 tprintf(", %#lx", arg);
848 else {
849 tprintf(", ");
850 print_rtc(tcp, &rt);
851 }
852 }
853 break;
854 case RTC_IRQP_SET:
855 case RTC_EPOCH_SET:
856 if (entering(tcp))
857 tprintf(", %lu", arg);
858 break;
859 case RTC_IRQP_READ:
860 case RTC_EPOCH_READ:
861 if (exiting(tcp))
862 tprintf(", %lu", arg);
863 break;
864 case RTC_WKALM_SET:
865 if (entering(tcp)) {
866 struct rtc_wkalrm wk;
867 if (umove(tcp, arg, &wk) < 0)
868 tprintf(", %#lx", arg);
869 else {
870 tprintf(", {enabled=%d, pending=%d, ",
871 wk.enabled, wk.pending);
872 print_rtc(tcp, &wk.time);
873 tprintf("}");
874 }
875 }
876 break;
877 case RTC_WKALM_RD:
878 if (exiting(tcp)) {
879 struct rtc_wkalrm wk;
880 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
881 tprintf(", %#lx", arg);
882 else {
883 tprintf(", {enabled=%d, pending=%d, ",
884 wk.enabled, wk.pending);
885 print_rtc(tcp, &wk.time);
886 tprintf("}");
887 }
888 }
889 break;
890 default:
891 if (entering(tcp))
892 tprintf(", %#lx", arg);
893 break;
894 }
895 return 1;
896}
Roland McGrathe4662342007-08-02 01:25:34 +0000897
898#ifndef TFD_TIMER_ABSTIME
899#define TFD_TIMER_ABSTIME (1 << 0)
900#endif
901
902static const struct xlat timerfdflags[] = {
903 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
904 { 0, NULL }
905};
906
907int
908sys_timerfd(tcp)
909struct tcb *tcp;
910{
911 if (entering(tcp)) {
912 /* It does not matter that the kernel uses itimerspec. */
913 tprintf("%ld, ", tcp->u_arg[0]);
914 printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
915 tprintf(", ");
916 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
917 tprintf(", ");
918 printitv(tcp, tcp->u_arg[3]);
919 }
920 return 0;
921}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000922#endif /* LINUX */