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>
41 #define UTIME_NOW ((1l << 30) - 1l)
44 #define UTIME_OMIT ((1l << 30) - 2l)
50 u_int32_t tv_sec, tv_usec;
54 tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
56 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
60 tprint_timeval(struct tcb *tcp, const struct timeval *tv)
63 (unsigned long) tv->tv_sec, (unsigned long) tv->tv_usec);
67 printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
71 else if (!verbose(tcp))
72 tprintf("%#lx", addr);
76 if (bitness == BITNESS_32
77 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
78 || personality_wordsize[current_personality] == 4
84 if ((rc = umove(tcp, addr, &tv)) >= 0) {
85 if (special && tv.tv_sec == 0 &&
86 tv.tv_usec == UTIME_NOW)
88 else if (special && tv.tv_sec == 0 &&
89 tv.tv_usec == UTIME_OMIT)
90 tprintf("UTIME_OMIT");
92 tprint_timeval32(tcp, &tv);
97 if ((rc = umove(tcp, addr, &tv)) >= 0) {
98 if (special && tv.tv_sec == 0 &&
99 tv.tv_usec == UTIME_NOW)
100 tprintf("UTIME_NOW");
101 else if (special && tv.tv_sec == 0 &&
102 tv.tv_usec == UTIME_OMIT)
103 tprintf("UTIME_OMIT");
105 tprint_timeval(tcp, &tv);
114 sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf)
118 else if (!verbose(tcp))
119 sprintf(buf, "%#lx", addr);
123 if (bitness == BITNESS_32
124 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
125 || personality_wordsize[current_personality] == 4
131 if ((rc = umove(tcp, addr, &tv)) >= 0)
132 sprintf(buf, "{%u, %u}",
133 tv.tv_sec, tv.tv_usec);
137 if ((rc = umove(tcp, addr, &tv)) >= 0)
138 sprintf(buf, "{%lu, %lu}",
139 (unsigned long) tv.tv_sec,
140 (unsigned long) tv.tv_usec);
143 strcpy(buf, "{...}");
147 void print_timespec(struct tcb *tcp, long addr)
151 else if (!verbose(tcp))
152 tprintf("%#lx", addr);
156 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
157 if (personality_wordsize[current_personality] == 4) {
160 if ((rc = umove(tcp, addr, &tv)) >= 0)
162 tv.tv_sec, tv.tv_usec);
168 if ((rc = umove(tcp, addr, &ts)) >= 0)
169 tprintf("{%lu, %lu}",
170 (unsigned long) ts.tv_sec,
171 (unsigned long) ts.tv_nsec);
178 void sprint_timespec(char *buf, struct tcb *tcp, long addr)
182 else if (!verbose(tcp))
183 sprintf(buf, "%#lx", addr);
187 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
188 if (personality_wordsize[current_personality] == 4) {
191 if ((rc = umove(tcp, addr, &tv)) >= 0)
192 sprintf(buf, "{%u, %u}",
193 tv.tv_sec, tv.tv_usec);
199 if ((rc = umove(tcp, addr, &ts)) >= 0)
200 sprintf(buf, "{%lu, %lu}",
201 (unsigned long) ts.tv_sec,
202 (unsigned long) ts.tv_nsec);
205 strcpy(buf, "{...}");
215 printnum(tcp, tcp->u_arg[0], "%ld");
226 printnum(tcp, tcp->u_arg[0], "%ld");
232 sys_gettimeofday(tcp)
237 tprintf("%#lx, %#lx",
238 tcp->u_arg[0], tcp->u_arg[1]);
241 printtv(tcp, tcp->u_arg[0]);
244 printtv(tcp, tcp->u_arg[1]);
253 sys_osf_gettimeofday(tcp)
258 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
261 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
264 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
272 sys_settimeofday(tcp)
276 printtv(tcp, tcp->u_arg[0]);
279 printtv(tcp, tcp->u_arg[1]);
287 sys_osf_settimeofday(tcp)
291 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
294 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
306 printtv(tcp, tcp->u_arg[0]);
310 tprintf("%#lx", tcp->u_arg[1]);
312 printtv(tcp, tcp->u_arg[1]);
318 sys_nanosleep(struct tcb *tcp)
321 print_timespec(tcp, tcp->u_arg[0]);
324 if (!tcp->u_arg[1] || is_restart_error(tcp))
325 print_timespec(tcp, tcp->u_arg[1]);
327 tprintf("%#lx", tcp->u_arg[1]);
332 static const struct xlat which[] = {
333 { ITIMER_REAL, "ITIMER_REAL" },
334 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
335 { ITIMER_PROF, "ITIMER_PROF" },
340 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
344 else if (!verbose(tcp))
345 tprintf("%#lx", addr);
349 if (bitness == BITNESS_32
350 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
351 || personality_wordsize[current_personality] == 4
356 struct timeval32 it_interval, it_value;
359 if ((rc = umove(tcp, addr, &itv)) >= 0) {
360 tprintf("{it_interval=");
361 tprint_timeval32(tcp, &itv.it_interval);
362 tprintf(", it_value=");
363 tprint_timeval32(tcp, &itv.it_value);
367 struct itimerval itv;
369 if ((rc = umove(tcp, addr, &itv)) >= 0) {
370 tprintf("{it_interval=");
371 tprint_timeval(tcp, &itv.it_interval);
372 tprintf(", it_value=");
373 tprint_timeval(tcp, &itv.it_value);
382 #define printitv(tcp, addr) \
383 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
390 printxval(which, tcp->u_arg[0], "ITIMER_???");
394 tprintf("%#lx", tcp->u_arg[1]);
396 printitv(tcp, tcp->u_arg[1]);
404 sys_osf_getitimer(tcp)
408 printxval(which, tcp->u_arg[0], "ITIMER_???");
412 tprintf("%#lx", tcp->u_arg[1]);
414 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
425 printxval(which, tcp->u_arg[0], "ITIMER_???");
427 printitv(tcp, tcp->u_arg[1]);
431 tprintf("%#lx", tcp->u_arg[2]);
433 printitv(tcp, tcp->u_arg[2]);
440 sys_osf_setitimer(tcp)
444 printxval(which, tcp->u_arg[0], "ITIMER_???");
446 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
450 tprintf("%#lx", tcp->u_arg[2]);
452 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
460 static const struct xlat adjtimex_modes[] = {
463 { ADJ_OFFSET, "ADJ_OFFSET" },
466 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
469 { ADJ_MAXERROR, "ADJ_MAXERROR" },
472 { ADJ_ESTERROR, "ADJ_ESTERROR" },
475 { ADJ_STATUS, "ADJ_STATUS" },
478 { ADJ_TIMECONST, "ADJ_TIMECONST" },
481 { ADJ_TICK, "ADJ_TICK" },
483 #ifdef ADJ_OFFSET_SINGLESHOT
484 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
489 static const struct xlat adjtimex_status[] = {
491 { STA_PLL, "STA_PLL" },
494 { STA_PPSFREQ, "STA_PPSFREQ" },
497 { STA_PPSTIME, "STA_PPSTIME" },
500 { STA_FLL, "STA_FLL" },
503 { STA_INS, "STA_INS" },
506 { STA_DEL, "STA_DEL" },
509 { STA_UNSYNC, "STA_UNSYNC" },
512 { STA_FREQHOLD, "STA_FREQHOLD" },
515 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
518 { STA_PPSJITTER, "STA_PPSJITTER" },
521 { STA_PPSWANDER, "STA_PPSWANDER" },
524 { STA_PPSERROR, "STA_PPSERROR" },
527 { STA_CLOCKERR, "STA_CLOCKERR" },
532 static const struct xlat adjtimex_state[] = {
534 { TIME_OK, "TIME_OK" },
537 { TIME_INS, "TIME_INS" },
540 { TIME_DEL, "TIME_DEL" },
543 { TIME_OOP, "TIME_OOP" },
546 { TIME_WAIT, "TIME_WAIT" },
549 { TIME_ERROR, "TIME_ERROR" },
554 #if SUPPORTED_PERSONALITIES > 1
556 tprint_timex32(struct tcb *tcp, long addr)
568 struct timeval32 time;
580 if (umove(tcp, addr, &tx) < 0)
584 printflags(adjtimex_modes, tx.modes, "ADJ_???");
585 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
586 tx.offset, tx.freq, tx.maxerror);
587 tprintf("esterror=%u, status=", tx.esterror);
588 printflags(adjtimex_status, tx.status, "STA_???");
589 tprintf(", constant=%d, precision=%u, ",
590 tx.constant, tx.precision);
591 tprintf("tolerance=%d, time=", tx.tolerance);
592 tprint_timeval32(tcp, &tx.time);
593 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
594 tx.tick, tx.ppsfreq, tx.jitter);
595 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
596 tx.shift, tx.stabil, tx.jitcnt);
597 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
598 tx.calcnt, tx.errcnt, tx.stbcnt);
602 #endif /* SUPPORTED_PERSONALITIES > 1 */
605 tprint_timex(struct tcb *tcp, long addr)
609 #if SUPPORTED_PERSONALITIES > 1
610 if (personality_wordsize[current_personality] == 4)
611 return tprint_timex32(tcp, addr);
613 if (umove(tcp, addr, &tx) < 0)
616 #if LINUX_VERSION_CODE < 66332
617 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
618 tx.mode, tx.offset, tx.frequency);
619 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
620 tx.maxerror, tx.esterror, tx.status);
621 tprintf("time_constant=%ld, precision=%lu, ",
622 tx.time_constant, tx.precision);
623 tprintf("tolerance=%ld, time=", tx.tolerance);
624 tprint_timeval(tcp, &tx.time);
627 printflags(adjtimex_modes, tx.modes, "ADJ_???");
628 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
629 tx.offset, tx.freq, tx.maxerror);
630 tprintf("esterror=%lu, status=", tx.esterror);
631 printflags(adjtimex_status, tx.status, "STA_???");
632 tprintf(", constant=%ld, precision=%lu, ",
633 tx.constant, tx.precision);
634 tprintf("tolerance=%ld, time=", tx.tolerance);
635 tprint_timeval(tcp, &tx.time);
636 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
637 tx.tick, tx.ppsfreq, tx.jitter);
638 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
639 tx.shift, tx.stabil, tx.jitcnt);
640 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
641 tx.calcnt, tx.errcnt, tx.stbcnt);
648 sys_adjtimex(struct tcb *tcp)
651 if (tcp->u_arg[0] == 0)
653 else if (syserror(tcp) || !verbose(tcp))
654 tprintf("%#lx", tcp->u_arg[0]);
655 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
659 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
666 static const struct xlat clockflags[] = {
667 { TIMER_ABSTIME, "TIMER_ABSTIME" },
671 static const struct xlat clocknames[] = {
672 #ifdef CLOCK_REALTIME
673 { CLOCK_REALTIME, "CLOCK_REALTIME" },
675 #ifdef CLOCK_MONOTONIC
676 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
678 #ifdef CLOCK_PROCESS_CPUTIME_ID
679 { CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID" },
681 #ifdef CLOCK_THREAD_CPUTIME_ID
682 { CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID" },
684 #ifdef CLOCK_MONOTONIC_RAW
685 { CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW" },
687 #ifdef CLOCK_REALTIME_COARSE
688 { CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE" },
690 #ifdef CLOCK_MONOTONIC_COARSE
691 { CLOCK_MONOTONIC_COARSE, "CLOCK_MONOTONIC_COARSE" },
697 sys_clock_settime(tcp)
701 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
703 printtv(tcp, tcp->u_arg[1]);
709 sys_clock_gettime(tcp)
713 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
717 tprintf("%#lx", tcp->u_arg[1]);
719 printtv(tcp, tcp->u_arg[1]);
725 sys_clock_nanosleep(tcp)
729 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
731 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
733 printtv(tcp, tcp->u_arg[2]);
737 tprintf("%#lx", tcp->u_arg[3]);
739 printtv(tcp, tcp->u_arg[3]);
744 #ifndef SIGEV_THREAD_ID
745 # define SIGEV_THREAD_ID 4
747 static const struct xlat sigev_value[] = {
748 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
749 { SIGEV_NONE+1, "SIGEV_NONE" },
750 { SIGEV_THREAD+1, "SIGEV_THREAD" },
751 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
755 #if SUPPORTED_PERSONALITIES > 1
757 printsigevent32(struct tcb *tcp, long arg)
767 int function, attribute;
772 if (umove(tcp, arg, &sev) < 0)
775 tprintf("{%#x, ", sev.sigev_value);
776 if (sev.sigev_notify == SIGEV_SIGNAL)
777 tprintf("%s, ", signame(sev.sigev_signo));
779 tprintf("%u, ", sev.sigev_signo);
780 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
782 if (sev.sigev_notify == SIGEV_THREAD_ID)
783 tprintf("{%d}", sev.un.tid);
784 else if (sev.sigev_notify == SIGEV_THREAD)
785 tprintf("{%#x, %#x}",
786 sev.un.thread.function,
787 sev.un.thread.attribute);
796 printsigevent(struct tcb *tcp, long arg)
800 #if SUPPORTED_PERSONALITIES > 1
801 if (personality_wordsize[current_personality] == 4)
803 printsigevent32(tcp, arg);
807 if (umove (tcp, arg, &sev) < 0)
810 tprintf("{%p, ", sev.sigev_value.sival_ptr);
811 if (sev.sigev_notify == SIGEV_SIGNAL)
812 tprintf("%s, ", signame(sev.sigev_signo));
814 tprintf("%u, ", sev.sigev_signo);
815 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
817 if (sev.sigev_notify == SIGEV_THREAD_ID)
818 /* _pad[0] is the _tid field which might not be
819 present in the userlevel definition of the
821 tprintf("{%d}", sev._sigev_un._pad[0]);
822 else if (sev.sigev_notify == SIGEV_THREAD)
823 tprintf("{%p, %p}", sev.sigev_notify_function,
824 sev.sigev_notify_attributes);
832 sys_timer_create(tcp)
836 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
838 printsigevent(tcp, tcp->u_arg[1]);
843 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &p) < 0)
844 tprintf("%#lx", tcp->u_arg[2]);
852 sys_timer_settime(tcp)
856 tprintf("%#lx, ", tcp->u_arg[0]);
857 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
859 printitv(tcp, tcp->u_arg[2]);
863 tprintf("%#lx", tcp->u_arg[3]);
865 printitv(tcp, tcp->u_arg[3]);
871 sys_timer_gettime(tcp)
875 tprintf("%#lx, ", tcp->u_arg[0]);
878 tprintf("%#lx", tcp->u_arg[1]);
880 printitv(tcp, tcp->u_arg[1]);
888 const struct rtc_time *rt;
890 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
891 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
892 rt->tm_sec, rt->tm_min, rt->tm_hour,
893 rt->tm_mday, rt->tm_mon, rt->tm_year);
895 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
896 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
902 rtc_ioctl(tcp, code, arg)
912 if (umove(tcp, arg, &rt) < 0)
913 tprintf(", %#lx", arg);
924 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
925 tprintf(", %#lx", arg);
935 tprintf(", %lu", arg);
940 tprintf(", %lu", arg);
944 struct rtc_wkalrm wk;
945 if (umove(tcp, arg, &wk) < 0)
946 tprintf(", %#lx", arg);
948 tprintf(", {enabled=%d, pending=%d, ",
949 wk.enabled, wk.pending);
950 print_rtc(tcp, &wk.time);
957 struct rtc_wkalrm wk;
958 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
959 tprintf(", %#lx", arg);
961 tprintf(", {enabled=%d, pending=%d, ",
962 wk.enabled, wk.pending);
963 print_rtc(tcp, &wk.time);
970 tprintf(", %#lx", arg);
976 #ifndef TFD_TIMER_ABSTIME
977 #define TFD_TIMER_ABSTIME (1 << 0)
980 static const struct xlat timerfdflags[] = {
981 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
990 /* It does not matter that the kernel uses itimerspec. */
991 tprintf("%ld, ", tcp->u_arg[0]);
992 printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
994 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
996 printitv(tcp, tcp->u_arg[3]);
1002 sys_timerfd_create(struct tcb *tcp)
1004 if (entering(tcp)) {
1005 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
1007 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
1013 sys_timerfd_settime(struct tcb *tcp)
1015 if (entering(tcp)) {
1016 printfd(tcp, tcp->u_arg[0]);
1018 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
1020 printitv(tcp, tcp->u_arg[2]);
1022 printitv(tcp, tcp->u_arg[3]);
1028 sys_timerfd_gettime(struct tcb *tcp)
1030 if (entering(tcp)) {
1031 printfd(tcp, tcp->u_arg[0]);
1033 printitv(tcp, tcp->u_arg[1]);