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>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
35 #include <linux/version.h>
36 #include <sys/timex.h>
37 #include <linux/ioctl.h>
38 #include <linux/rtc.h>
43 u_int32_t tv_sec, tv_usec;
47 tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
49 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
53 tprint_timeval(struct tcb *tcp, const struct timeval *tv)
56 (unsigned long) tv->tv_sec, (unsigned long) tv->tv_usec);
60 printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
64 else if (!verbose(tcp))
65 tprintf("%#lx", addr);
70 if (bitness == BITNESS_32
71 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
72 || personality_wordsize[current_personality] == 4
78 if ((rc = umove(tcp, addr, &tv)) >= 0)
79 tprint_timeval32(tcp, &tv);
84 if ((rc = umove(tcp, addr, &tv)) >= 0)
85 tprint_timeval(tcp, &tv);
94 sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf)
98 else if (!verbose(tcp))
99 sprintf(buf, "%#lx", addr);
104 if (bitness == BITNESS_32
105 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
106 || personality_wordsize[current_personality] == 4
112 if ((rc = umove(tcp, addr, &tv)) >= 0)
113 sprintf(buf, "{%u, %u}",
114 tv.tv_sec, tv.tv_usec);
119 if ((rc = umove(tcp, addr, &tv)) >= 0)
120 sprintf(buf, "{%lu, %lu}",
121 (unsigned long) tv.tv_sec,
122 (unsigned long) tv.tv_usec);
126 strcpy(buf, "{...}");
136 printnum(tcp, tcp->u_arg[0], "%ld");
147 printnum(tcp, tcp->u_arg[0], "%ld");
153 sys_gettimeofday(tcp)
158 tprintf("%#lx, %#lx",
159 tcp->u_arg[0], tcp->u_arg[1]);
162 printtv(tcp, tcp->u_arg[0]);
165 printtv(tcp, tcp->u_arg[1]);
174 sys_osf_gettimeofday(tcp)
179 tprintf("%#lx, %#lx",
180 tcp->u_arg[0], tcp->u_arg[1]);
183 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32);
186 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
194 sys_settimeofday(tcp)
198 printtv(tcp, tcp->u_arg[0]);
201 printtv(tcp, tcp->u_arg[1]);
209 sys_osf_settimeofday(tcp)
213 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32);
216 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
228 printtv(tcp, tcp->u_arg[0]);
232 tprintf("%#lx", tcp->u_arg[1]);
234 printtv(tcp, tcp->u_arg[1]);
239 static const struct xlat which[] = {
240 { ITIMER_REAL, "ITIMER_REAL" },
241 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
242 { ITIMER_PROF, "ITIMER_PROF" },
247 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
251 else if (!verbose(tcp))
252 tprintf("%#lx", addr);
257 if (bitness == BITNESS_32
258 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
259 || personality_wordsize[current_personality] == 4
265 struct timeval32 it_interval, it_value;
268 if ((rc = umove(tcp, addr, &itv)) >= 0)
269 tprintf("{it_interval=");
270 tprint_timeval32(tcp, &itv.it_interval);
271 tprintf(", it_value=");
272 tprint_timeval32(tcp, &itv.it_value);
276 struct itimerval itv;
278 if ((rc = umove(tcp, addr, &itv)) >= 0)
279 tprintf("{it_interval=");
280 tprint_timeval(tcp, &itv.it_interval);
281 tprintf(", it_value=");
282 tprint_timeval(tcp, &itv.it_value);
291 #define printitv(tcp, addr) \
292 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
299 printxval(which, tcp->u_arg[0], "ITIMER_???");
303 tprintf("%#lx", tcp->u_arg[1]);
305 printitv(tcp, tcp->u_arg[1]);
313 sys_osf_getitimer(tcp)
317 printxval(which, tcp->u_arg[0], "ITIMER_???");
321 tprintf("%#lx", tcp->u_arg[1]);
323 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
334 printxval(which, tcp->u_arg[0], "ITIMER_???");
336 printitv(tcp, tcp->u_arg[1]);
340 tprintf("%#lx", tcp->u_arg[2]);
342 printitv(tcp, tcp->u_arg[2]);
349 sys_osf_setitimer(tcp)
353 printxval(which, tcp->u_arg[0], "ITIMER_???");
355 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
359 tprintf("%#lx", tcp->u_arg[2]);
361 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
369 static const struct xlat adjtimex_modes[] = {
372 { ADJ_OFFSET, "ADJ_OFFSET" },
375 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
378 { ADJ_MAXERROR, "ADJ_MAXERROR" },
381 { ADJ_ESTERROR, "ADJ_ESTERROR" },
384 { ADJ_STATUS, "ADJ_STATUS" },
387 { ADJ_TIMECONST, "ADJ_TIMECONST" },
390 { ADJ_TICK, "ADJ_TICK" },
392 #ifdef ADJ_OFFSET_SINGLESHOT
393 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
398 static const struct xlat adjtimex_status[] = {
400 { STA_PLL, "STA_PLL" },
403 { STA_PPSFREQ, "STA_PPSFREQ" },
406 { STA_PPSTIME, "STA_PPSTIME" },
409 { STA_FLL, "STA_FLL" },
412 { STA_INS, "STA_INS" },
415 { STA_DEL, "STA_DEL" },
418 { STA_UNSYNC, "STA_UNSYNC" },
421 { STA_FREQHOLD, "STA_FREQHOLD" },
424 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
427 { STA_PPSJITTER, "STA_PPSJITTER" },
430 { STA_PPSWANDER, "STA_PPSWANDER" },
433 { STA_PPSERROR, "STA_PPSERROR" },
436 { STA_CLOCKERR, "STA_CLOCKERR" },
441 static const struct xlat adjtimex_state[] = {
443 { TIME_OK, "TIME_OK" },
446 { TIME_INS, "TIME_INS" },
449 { TIME_DEL, "TIME_DEL" },
452 { TIME_OOP, "TIME_OOP" },
455 { TIME_WAIT, "TIME_WAIT" },
458 { TIME_ERROR, "TIME_ERROR" },
463 #if SUPPORTED_PERSONALITIES > 1
465 tprint_timex32(struct tcb *tcp, long addr)
478 struct timeval32 time;
490 if (umove(tcp, addr, &tx) < 0)
494 printflags(adjtimex_modes, tx.modes, "ADJ_???");
495 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
496 tx.offset, tx.freq, tx.maxerror);
497 tprintf("esterror=%u, status=", tx.esterror);
498 printflags(adjtimex_status, tx.status, "STA_???");
499 tprintf(", constant=%d, precision=%u, ",
500 tx.constant, tx.precision);
501 tprintf("tolerance=%d, time=", tx.tolerance);
502 tprint_timeval32(tcp, &tx.time);
503 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
504 tx.tick, tx.ppsfreq, tx.jitter);
505 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
506 tx.shift, tx.stabil, tx.jitcnt);
507 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
508 tx.calcnt, tx.errcnt, tx.stbcnt);
512 #endif /* SUPPORTED_PERSONALITIES > 1 */
515 tprint_timex(struct tcb *tcp, long addr)
519 #if SUPPORTED_PERSONALITIES > 1
520 if (personality_wordsize[current_personality] == 4)
521 return tprint_timex32(tcp, addr);
523 if (umove(tcp, addr, &tx) < 0)
526 #if LINUX_VERSION_CODE < 66332
527 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
528 tx.mode, tx.offset, tx.frequency);
529 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
530 tx.maxerror, tx.esterror, tx.status);
531 tprintf("time_constant=%ld, precision=%lu, ",
532 tx.time_constant, tx.precision);
533 tprintf("tolerance=%ld, time=", tx.tolerance);
534 tprint_timeval(tcp, &tx.time);
537 printflags(adjtimex_modes, tx.modes, "ADJ_???");
538 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
539 tx.offset, tx.freq, tx.maxerror);
540 tprintf("esterror=%lu, status=", tx.esterror);
541 printflags(adjtimex_status, tx.status, "STA_???");
542 tprintf(", constant=%ld, precision=%lu, ",
543 tx.constant, tx.precision);
544 tprintf("tolerance=%ld, time=", tx.tolerance);
545 tprint_timeval(tcp, &tx.time);
546 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
547 tx.tick, tx.ppsfreq, tx.jitter);
548 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
549 tx.shift, tx.stabil, tx.jitcnt);
550 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
551 tx.calcnt, tx.errcnt, tx.stbcnt);
558 sys_adjtimex(struct tcb *tcp)
561 if (tcp->u_arg[0] == 0)
563 else if (syserror(tcp) || !verbose(tcp))
564 tprintf("%#lx", tcp->u_arg[0]);
565 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
567 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
574 static const struct xlat clockflags[] = {
575 { TIMER_ABSTIME, "TIMER_ABSTIME" },
579 static const struct xlat clocknames[] = {
580 #ifdef CLOCK_REALTIME
581 { CLOCK_REALTIME, "CLOCK_REALTIME" },
583 #ifdef CLOCK_MONOTONIC
584 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
590 sys_clock_settime(tcp)
594 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
596 printtv(tcp, tcp->u_arg[1]);
602 sys_clock_gettime(tcp)
606 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
610 tprintf("%#lx", tcp->u_arg[1]);
612 printtv(tcp, tcp->u_arg[1]);
618 sys_clock_nanosleep(tcp)
622 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
624 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
626 printtv(tcp, tcp->u_arg[2]);
630 tprintf("%#lx", tcp->u_arg[3]);
632 printtv(tcp, tcp->u_arg[3]);
637 #ifndef SIGEV_THREAD_ID
638 # define SIGEV_THREAD_ID 4
640 static const struct xlat sigev_value[] = {
641 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
642 { SIGEV_NONE+1, "SIGEV_NONE" },
643 { SIGEV_THREAD+1, "SIGEV_THREAD" },
644 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
648 #if SUPPORTED_PERSONALITIES > 1
650 printsigevent32(struct tcb *tcp, long arg)
663 int function, attribute;
668 if (umove(tcp, arg, &sev) < 0)
672 tprintf("{%#x, ", sev.sigev_value);
673 if (sev.sigev_notify == SIGEV_SIGNAL)
674 tprintf("%s, ", signame(sev.sigev_signo));
676 tprintf("%u, ", sev.sigev_signo);
677 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
679 if (sev.sigev_notify == SIGEV_THREAD_ID)
680 tprintf("{%d}", sev.un.tid);
681 else if (sev.sigev_notify == SIGEV_THREAD)
682 tprintf("{%#x, %#x}",
683 sev.un.thread.function,
684 sev.un.thread.attribute);
693 printsigevent(struct tcb *tcp, long arg)
697 #if SUPPORTED_PERSONALITIES > 1
698 if (personality_wordsize[current_personality] == 4)
700 printsigevent32(tcp, arg);
704 if (umove (tcp, arg, &sev) < 0)
707 tprintf("{%p, ", sev.sigev_value.sival_ptr);
708 if (sev.sigev_notify == SIGEV_SIGNAL)
709 tprintf("%s, ", signame(sev.sigev_signo));
711 tprintf("%u, ", sev.sigev_signo);
712 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
714 if (sev.sigev_notify == SIGEV_THREAD_ID)
715 /* _pad[0] is the _tid field which might not be
716 present in the userlevel definition of the
718 tprintf("{%d}", sev._sigev_un._pad[0]);
719 else if (sev.sigev_notify == SIGEV_THREAD)
720 tprintf("{%p, %p}", sev.sigev_notify_function,
721 sev.sigev_notify_attributes);
729 sys_timer_create(tcp)
733 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
735 printsigevent(tcp, tcp->u_arg[1]);
740 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &p) < 0)
741 tprintf("%#lx", tcp->u_arg[2]);
749 sys_timer_settime(tcp)
753 tprintf("%#lx, ", tcp->u_arg[0]);
754 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
756 printitv(tcp, tcp->u_arg[2]);
760 tprintf("%#lx", tcp->u_arg[3]);
762 printitv(tcp, tcp->u_arg[3]);
768 sys_timer_gettime(tcp)
772 tprintf("%#lx, ", tcp->u_arg[0]);
775 tprintf("%#lx", tcp->u_arg[1]);
777 printitv(tcp, tcp->u_arg[1]);
785 const struct rtc_time *rt;
787 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
788 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
789 rt->tm_sec, rt->tm_min, rt->tm_hour,
790 rt->tm_mday, rt->tm_mon, rt->tm_year);
792 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
793 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
799 rtc_ioctl(tcp, code, arg)
809 if (umove(tcp, arg, &rt) < 0)
810 tprintf(", %#lx", arg);
821 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
822 tprintf(", %#lx", arg);
832 tprintf(", %lu", arg);
837 tprintf(", %lu", arg);
841 struct rtc_wkalrm wk;
842 if (umove(tcp, arg, &wk) < 0)
843 tprintf(", %#lx", arg);
845 tprintf(", {enabled=%d, pending=%d, ",
846 wk.enabled, wk.pending);
847 print_rtc(tcp, &wk.time);
854 struct rtc_wkalrm wk;
855 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
856 tprintf(", %#lx", arg);
858 tprintf(", {enabled=%d, pending=%d, ",
859 wk.enabled, wk.pending);
860 print_rtc(tcp, &wk.time);
867 tprintf(", %#lx", arg);