blob: b6a2fab9f6c69fa4626c4b7be45c6f00d0d85204 [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
291 if ((rc = umove(tcp, addr, &itv)) >= 0)
292 tprintf("{it_interval=");
293 tprint_timeval32(tcp, &itv.it_interval);
294 tprintf(", it_value=");
295 tprint_timeval32(tcp, &itv.it_value);
296 tprintf("}");
297 } else
298 {
299 struct itimerval itv;
300
301 if ((rc = umove(tcp, addr, &itv)) >= 0)
302 tprintf("{it_interval=");
303 tprint_timeval(tcp, &itv.it_interval);
304 tprintf(", it_value=");
305 tprint_timeval(tcp, &itv.it_value);
306 tprintf("}");
307 }
308
309 if (rc < 0)
310 tprintf("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311 }
312}
313
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000314#define printitv(tcp, addr) \
315 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000316
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317int
318sys_getitimer(tcp)
319struct tcb *tcp;
320{
321 if (entering(tcp)) {
322 printxval(which, tcp->u_arg[0], "ITIMER_???");
323 tprintf(", ");
324 } else {
325 if (syserror(tcp))
326 tprintf("%#lx", tcp->u_arg[1]);
327 else
328 printitv(tcp, tcp->u_arg[1]);
329 }
330 return 0;
331}
332
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000333
334#ifdef ALPHA
335int
336sys_osf_getitimer(tcp)
337struct tcb *tcp;
338{
339 if (entering(tcp)) {
340 printxval(which, tcp->u_arg[0], "ITIMER_???");
341 tprintf(", ");
342 } else {
343 if (syserror(tcp))
344 tprintf("%#lx", tcp->u_arg[1]);
345 else
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000346 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000347 }
348 return 0;
349}
350#endif
351
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000352int
353sys_setitimer(tcp)
354struct tcb *tcp;
355{
356 if (entering(tcp)) {
357 printxval(which, tcp->u_arg[0], "ITIMER_???");
358 tprintf(", ");
359 printitv(tcp, tcp->u_arg[1]);
360 tprintf(", ");
361 } else {
362 if (syserror(tcp))
363 tprintf("%#lx", tcp->u_arg[2]);
364 else
365 printitv(tcp, tcp->u_arg[2]);
366 }
367 return 0;
368}
369
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000370#ifdef ALPHA
371int
372sys_osf_setitimer(tcp)
373struct tcb *tcp;
374{
375 if (entering(tcp)) {
376 printxval(which, tcp->u_arg[0], "ITIMER_???");
377 tprintf(", ");
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000378 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000379 tprintf(", ");
380 } else {
381 if (syserror(tcp))
382 tprintf("%#lx", tcp->u_arg[2]);
383 else
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000384 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000385 }
386 return 0;
387}
388#endif
389
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390#ifdef LINUX
391
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000392static const struct xlat adjtimex_modes[] = {
393 { 0, "0" },
394#ifdef ADJ_OFFSET
395 { ADJ_OFFSET, "ADJ_OFFSET" },
396#endif
397#ifdef ADJ_FREQUENCY
398 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
399#endif
400#ifdef ADJ_MAXERROR
401 { ADJ_MAXERROR, "ADJ_MAXERROR" },
402#endif
403#ifdef ADJ_ESTERROR
404 { ADJ_ESTERROR, "ADJ_ESTERROR" },
405#endif
406#ifdef ADJ_STATUS
407 { ADJ_STATUS, "ADJ_STATUS" },
408#endif
409#ifdef ADJ_TIMECONST
410 { ADJ_TIMECONST, "ADJ_TIMECONST" },
411#endif
412#ifdef ADJ_TICK
413 { ADJ_TICK, "ADJ_TICK" },
414#endif
415#ifdef ADJ_OFFSET_SINGLESHOT
416 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
417#endif
418 { 0, NULL }
419};
420
421static const struct xlat adjtimex_status[] = {
422#ifdef STA_PLL
423 { STA_PLL, "STA_PLL" },
424#endif
425#ifdef STA_PPSFREQ
426 { STA_PPSFREQ, "STA_PPSFREQ" },
427#endif
428#ifdef STA_PPSTIME
429 { STA_PPSTIME, "STA_PPSTIME" },
430#endif
431#ifdef STA_FLL
432 { STA_FLL, "STA_FLL" },
433#endif
434#ifdef STA_INS
435 { STA_INS, "STA_INS" },
436#endif
437#ifdef STA_DEL
438 { STA_DEL, "STA_DEL" },
439#endif
440#ifdef STA_UNSYNC
441 { STA_UNSYNC, "STA_UNSYNC" },
442#endif
443#ifdef STA_FREQHOLD
444 { STA_FREQHOLD, "STA_FREQHOLD" },
445#endif
446#ifdef STA_PPSSIGNAL
447 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
448#endif
449#ifdef STA_PPSJITTER
450 { STA_PPSJITTER, "STA_PPSJITTER" },
451#endif
452#ifdef STA_PPSWANDER
453 { STA_PPSWANDER, "STA_PPSWANDER" },
454#endif
455#ifdef STA_PPSERROR
456 { STA_PPSERROR, "STA_PPSERROR" },
457#endif
458#ifdef STA_CLOCKERR
459 { STA_CLOCKERR, "STA_CLOCKERR" },
460#endif
461 { 0, NULL }
462};
463
464static const struct xlat adjtimex_state[] = {
465#ifdef TIME_OK
466 { TIME_OK, "TIME_OK" },
467#endif
468#ifdef TIME_INS
469 { TIME_INS, "TIME_INS" },
470#endif
471#ifdef TIME_DEL
472 { TIME_DEL, "TIME_DEL" },
473#endif
474#ifdef TIME_OOP
475 { TIME_OOP, "TIME_OOP" },
476#endif
477#ifdef TIME_WAIT
478 { TIME_WAIT, "TIME_WAIT" },
479#endif
480#ifdef TIME_ERROR
481 { TIME_ERROR, "TIME_ERROR" },
482#endif
483 { 0, NULL }
484};
485
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000486#if SUPPORTED_PERSONALITIES > 1
487static int
488tprint_timex32(struct tcb *tcp, long addr)
489{
490 struct
491 {
492 unsigned int modes;
493 int offset;
494 int freq;
495 int maxerror;
496 int esterror;
497 int status;
498 int constant;
499 int precision;
500 int tolerance;
501 struct timeval32 time;
502 int tick;
503 int ppsfreq;
504 int jitter;
505 int shift;
506 int stabil;
507 int jitcnt;
508 int calcnt;
509 int errcnt;
510 int stbcnt;
511 } tx;
512
513 if (umove(tcp, addr, &tx) < 0)
514 return -1;
515
516 tprintf("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000517 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000518 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
519 tx.offset, tx.freq, tx.maxerror);
520 tprintf("esterror=%u, status=", tx.esterror);
521 printflags(adjtimex_status, tx.status, "STA_???");
522 tprintf(", constant=%d, precision=%u, ",
523 tx.constant, tx.precision);
524 tprintf("tolerance=%d, time=", tx.tolerance);
525 tprint_timeval32(tcp, &tx.time);
526 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
527 tx.tick, tx.ppsfreq, tx.jitter);
528 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
529 tx.shift, tx.stabil, tx.jitcnt);
530 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
531 tx.calcnt, tx.errcnt, tx.stbcnt);
532 tprintf("}");
533 return 0;
534}
535#endif /* SUPPORTED_PERSONALITIES > 1 */
536
537static int
538tprint_timex(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539{
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000540 struct timex tx;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000542#if SUPPORTED_PERSONALITIES > 1
543 if (personality_wordsize[current_personality] == 4)
544 return tprint_timex32(tcp, addr);
545#endif
546 if (umove(tcp, addr, &tx) < 0)
547 return -1;
548
549#if LINUX_VERSION_CODE < 66332
550 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
551 tx.mode, tx.offset, tx.frequency);
552 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
553 tx.maxerror, tx.esterror, tx.status);
554 tprintf("time_constant=%ld, precision=%lu, ",
555 tx.time_constant, tx.precision);
556 tprintf("tolerance=%ld, time=", tx.tolerance);
557 tprint_timeval(tcp, &tx.time);
558#else
559 tprintf("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000560 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000561 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
562 tx.offset, tx.freq, tx.maxerror);
563 tprintf("esterror=%lu, status=", tx.esterror);
564 printflags(adjtimex_status, tx.status, "STA_???");
565 tprintf(", constant=%ld, precision=%lu, ",
566 tx.constant, tx.precision);
567 tprintf("tolerance=%ld, time=", tx.tolerance);
568 tprint_timeval(tcp, &tx.time);
569 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
570 tx.tick, tx.ppsfreq, tx.jitter);
571 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
572 tx.shift, tx.stabil, tx.jitcnt);
573 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
574 tx.calcnt, tx.errcnt, tx.stbcnt);
575#endif
576 tprintf("}");
577 return 0;
578}
579
580int
581sys_adjtimex(struct tcb *tcp)
582{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000583 if (exiting(tcp)) {
584 if (tcp->u_arg[0] == 0)
585 tprintf("NULL");
586 else if (syserror(tcp) || !verbose(tcp))
587 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000588 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589 tprintf("{...}");
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000590 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
591 if (tcp->auxstr)
592 return RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593 }
594 return 0;
595}
Roland McGrath1e356792003-03-30 23:52:28 +0000596
Roland McGrathd9f816f2004-09-04 03:39:20 +0000597static const struct xlat clockflags[] = {
Roland McGrath1e356792003-03-30 23:52:28 +0000598 { TIMER_ABSTIME, "TIMER_ABSTIME" },
599 { 0, NULL }
600};
601
Roland McGrathd9f816f2004-09-04 03:39:20 +0000602static const struct xlat clocknames[] = {
Roland McGrath55a00f82004-08-31 08:26:39 +0000603#ifdef CLOCK_REALTIME
Roland McGrath54a4edd2004-08-31 06:52:45 +0000604 { CLOCK_REALTIME, "CLOCK_REALTIME" },
Roland McGrath55a00f82004-08-31 08:26:39 +0000605#endif
606#ifdef CLOCK_MONOTONIC
Roland McGrath54a4edd2004-08-31 06:52:45 +0000607 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
Roland McGrath55a00f82004-08-31 08:26:39 +0000608#endif
Roland McGrath54a4edd2004-08-31 06:52:45 +0000609 { 0, NULL }
610};
611
Roland McGrath1e356792003-03-30 23:52:28 +0000612int
613sys_clock_settime(tcp)
614struct tcb *tcp;
615{
616 if (entering(tcp)) {
Roland McGrath54a4edd2004-08-31 06:52:45 +0000617 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
618 tprintf(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000619 printtv(tcp, tcp->u_arg[1]);
620 }
621 return 0;
622}
623
624int
625sys_clock_gettime(tcp)
626struct tcb *tcp;
627{
628 if (entering(tcp)) {
Roland McGrath54a4edd2004-08-31 06:52:45 +0000629 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
630 tprintf(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000631 } else {
632 if (syserror(tcp))
633 tprintf("%#lx", tcp->u_arg[1]);
634 else
635 printtv(tcp, tcp->u_arg[1]);
636 }
637 return 0;
638}
639
640int
641sys_clock_nanosleep(tcp)
642struct tcb *tcp;
643{
644 if (entering(tcp)) {
Roland McGrath54a4edd2004-08-31 06:52:45 +0000645 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
646 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000647 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Roland McGrath1e356792003-03-30 23:52:28 +0000648 tprintf(", ");
649 printtv(tcp, tcp->u_arg[2]);
650 tprintf(", ");
651 } else {
652 if (syserror(tcp))
653 tprintf("%#lx", tcp->u_arg[3]);
654 else
655 printtv(tcp, tcp->u_arg[3]);
656 }
657 return 0;
658}
659
660#ifndef SIGEV_THREAD_ID
661# define SIGEV_THREAD_ID 4
662#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000663static const struct xlat sigev_value[] = {
Roland McGrath1e356792003-03-30 23:52:28 +0000664 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
665 { SIGEV_NONE+1, "SIGEV_NONE" },
666 { SIGEV_THREAD+1, "SIGEV_THREAD" },
667 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
668 { 0, NULL }
669};
670
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000671#if SUPPORTED_PERSONALITIES > 1
672static void
673printsigevent32(struct tcb *tcp, long arg)
674{
675 struct
676 {
677 int sigev_value;
678 int sigev_signo;
679 int sigev_notify;
680
681 union
682 {
683 int tid;
684 struct
685 {
686 int function, attribute;
687 } thread;
688 } un;
689 } sev;
690
691 if (umove(tcp, arg, &sev) < 0)
692 tprintf("{...}");
693 else
694 {
695 tprintf("{%#x, ", sev.sigev_value);
696 if (sev.sigev_notify == SIGEV_SIGNAL)
697 tprintf("%s, ", signame(sev.sigev_signo));
698 else
699 tprintf("%u, ", sev.sigev_signo);
700 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
701 tprintf(", ");
702 if (sev.sigev_notify == SIGEV_THREAD_ID)
703 tprintf("{%d}", sev.un.tid);
704 else if (sev.sigev_notify == SIGEV_THREAD)
705 tprintf("{%#x, %#x}",
706 sev.un.thread.function,
707 sev.un.thread.attribute);
708 else
709 tprintf("{...}");
710 tprintf("}");
711 }
712}
713#endif
714
Roland McGrath1e356792003-03-30 23:52:28 +0000715void
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000716printsigevent(struct tcb *tcp, long arg)
Roland McGrath1e356792003-03-30 23:52:28 +0000717{
718 struct sigevent sev;
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000719
720#if SUPPORTED_PERSONALITIES > 1
721 if (personality_wordsize[current_personality] == 4)
722 {
723 printsigevent32(tcp, arg);
724 return;
725 }
726#endif
Roland McGrath1e356792003-03-30 23:52:28 +0000727 if (umove (tcp, arg, &sev) < 0)
728 tprintf("{...}");
729 else {
Roland McGrath675d4a62004-09-11 08:12:45 +0000730 tprintf("{%p, ", sev.sigev_value.sival_ptr);
731 if (sev.sigev_notify == SIGEV_SIGNAL)
732 tprintf("%s, ", signame(sev.sigev_signo));
733 else
734 tprintf("%u, ", sev.sigev_signo);
Roland McGrath1e356792003-03-30 23:52:28 +0000735 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
736 tprintf(", ");
737 if (sev.sigev_notify == SIGEV_THREAD_ID)
738 /* _pad[0] is the _tid field which might not be
739 present in the userlevel definition of the
740 struct. */
741 tprintf("{%d}", sev._sigev_un._pad[0]);
Roland McGrathd4c85eb2004-04-16 21:48:44 +0000742 else if (sev.sigev_notify == SIGEV_THREAD)
743 tprintf("{%p, %p}", sev.sigev_notify_function,
744 sev.sigev_notify_attributes);
Roland McGrath1e356792003-03-30 23:52:28 +0000745 else
746 tprintf("{...}");
747 tprintf("}");
748 }
749}
750
751int
752sys_timer_create(tcp)
753struct tcb *tcp;
754{
755 if (entering(tcp)) {
Roland McGrath675d4a62004-09-11 08:12:45 +0000756 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
757 tprintf(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000758 printsigevent(tcp, tcp->u_arg[1]);
759 tprintf(", ");
760 } else {
Dmitry V. Levinac518d12006-12-13 17:03:02 +0000761 void *p;
762
763 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &p) < 0)
Roland McGrath1e356792003-03-30 23:52:28 +0000764 tprintf("%#lx", tcp->u_arg[2]);
Dmitry V. Levinac518d12006-12-13 17:03:02 +0000765 else
Roland McGrath1e356792003-03-30 23:52:28 +0000766 tprintf("{%p}", p);
Roland McGrath1e356792003-03-30 23:52:28 +0000767 }
768 return 0;
769}
770
771int
772sys_timer_settime(tcp)
773struct tcb *tcp;
774{
775 if (entering(tcp)) {
776 tprintf("%#lx, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000777 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Roland McGrath1e356792003-03-30 23:52:28 +0000778 tprintf(", ");
779 printitv(tcp, tcp->u_arg[2]);
780 tprintf(", ");
781 } else {
782 if (syserror(tcp))
783 tprintf("%#lx", tcp->u_arg[3]);
784 else
785 printitv(tcp, tcp->u_arg[3]);
786 }
787 return 0;
788}
789
790int
791sys_timer_gettime(tcp)
792struct tcb *tcp;
793{
794 if (entering(tcp)) {
795 tprintf("%#lx, ", tcp->u_arg[0]);
796 } else {
797 if (syserror(tcp))
798 tprintf("%#lx", tcp->u_arg[1]);
799 else
800 printitv(tcp, tcp->u_arg[1]);
801 }
802 return 0;
803}
Roland McGrathd83c50b2004-10-06 22:27:43 +0000804
805static void
806print_rtc(tcp, rt)
807struct tcb *tcp;
808const struct rtc_time *rt;
809{
810 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
811 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
812 rt->tm_sec, rt->tm_min, rt->tm_hour,
813 rt->tm_mday, rt->tm_mon, rt->tm_year);
814 if (!abbrev(tcp))
815 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
816 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
817 else
818 tprintf("...}");
819}
820
821int
822rtc_ioctl(tcp, code, arg)
823struct tcb *tcp;
824long code;
825long arg;
826{
827 switch (code) {
828 case RTC_ALM_SET:
829 case RTC_SET_TIME:
830 if (entering(tcp)) {
831 struct rtc_time rt;
832 if (umove(tcp, arg, &rt) < 0)
833 tprintf(", %#lx", arg);
834 else {
835 tprintf(", ");
836 print_rtc(tcp, &rt);
837 }
838 }
839 break;
840 case RTC_ALM_READ:
841 case RTC_RD_TIME:
842 if (exiting(tcp)) {
843 struct rtc_time rt;
844 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
845 tprintf(", %#lx", arg);
846 else {
847 tprintf(", ");
848 print_rtc(tcp, &rt);
849 }
850 }
851 break;
852 case RTC_IRQP_SET:
853 case RTC_EPOCH_SET:
854 if (entering(tcp))
855 tprintf(", %lu", arg);
856 break;
857 case RTC_IRQP_READ:
858 case RTC_EPOCH_READ:
859 if (exiting(tcp))
860 tprintf(", %lu", arg);
861 break;
862 case RTC_WKALM_SET:
863 if (entering(tcp)) {
864 struct rtc_wkalrm wk;
865 if (umove(tcp, arg, &wk) < 0)
866 tprintf(", %#lx", arg);
867 else {
868 tprintf(", {enabled=%d, pending=%d, ",
869 wk.enabled, wk.pending);
870 print_rtc(tcp, &wk.time);
871 tprintf("}");
872 }
873 }
874 break;
875 case RTC_WKALM_RD:
876 if (exiting(tcp)) {
877 struct rtc_wkalrm wk;
878 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
879 tprintf(", %#lx", arg);
880 else {
881 tprintf(", {enabled=%d, pending=%d, ",
882 wk.enabled, wk.pending);
883 print_rtc(tcp, &wk.time);
884 tprintf("}");
885 }
886 }
887 break;
888 default:
889 if (entering(tcp))
890 tprintf(", %#lx", arg);
891 break;
892 }
893 return 1;
894}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000895#endif /* LINUX */