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, "{...}");
210 sys_time(struct tcb *tcp)
214 printnum(tcp, tcp->u_arg[0], "%ld");
221 sys_stime(struct tcb *tcp)
224 printnum(tcp, tcp->u_arg[0], "%ld");
230 sys_gettimeofday(struct tcb *tcp)
234 tprintf("%#lx, %#lx",
235 tcp->u_arg[0], tcp->u_arg[1]);
238 printtv(tcp, tcp->u_arg[0]);
241 printtv(tcp, tcp->u_arg[1]);
250 sys_osf_gettimeofday(struct tcb *tcp)
254 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
257 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
260 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
268 sys_settimeofday(struct tcb *tcp)
271 printtv(tcp, tcp->u_arg[0]);
274 printtv(tcp, tcp->u_arg[1]);
282 sys_osf_settimeofday(struct tcb *tcp)
285 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
288 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
296 sys_adjtime(struct tcb *tcp)
299 printtv(tcp, tcp->u_arg[0]);
303 tprintf("%#lx", tcp->u_arg[1]);
305 printtv(tcp, tcp->u_arg[1]);
311 sys_nanosleep(struct tcb *tcp)
314 print_timespec(tcp, tcp->u_arg[0]);
317 if (!tcp->u_arg[1] || is_restart_error(tcp))
318 print_timespec(tcp, tcp->u_arg[1]);
320 tprintf("%#lx", tcp->u_arg[1]);
325 static const struct xlat which[] = {
326 { ITIMER_REAL, "ITIMER_REAL" },
327 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
328 { ITIMER_PROF, "ITIMER_PROF" },
333 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
337 else if (!verbose(tcp))
338 tprintf("%#lx", addr);
342 if (bitness == BITNESS_32
343 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
344 || personality_wordsize[current_personality] == 4
349 struct timeval32 it_interval, it_value;
352 if ((rc = umove(tcp, addr, &itv)) >= 0) {
353 tprintf("{it_interval=");
354 tprint_timeval32(tcp, &itv.it_interval);
355 tprintf(", it_value=");
356 tprint_timeval32(tcp, &itv.it_value);
360 struct itimerval itv;
362 if ((rc = umove(tcp, addr, &itv)) >= 0) {
363 tprintf("{it_interval=");
364 tprint_timeval(tcp, &itv.it_interval);
365 tprintf(", it_value=");
366 tprint_timeval(tcp, &itv.it_value);
375 #define printitv(tcp, addr) \
376 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
379 sys_getitimer(struct tcb *tcp)
382 printxval(which, tcp->u_arg[0], "ITIMER_???");
386 tprintf("%#lx", tcp->u_arg[1]);
388 printitv(tcp, tcp->u_arg[1]);
396 sys_osf_getitimer(struct tcb *tcp)
399 printxval(which, tcp->u_arg[0], "ITIMER_???");
403 tprintf("%#lx", tcp->u_arg[1]);
405 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
412 sys_setitimer(struct tcb *tcp)
415 printxval(which, tcp->u_arg[0], "ITIMER_???");
417 printitv(tcp, tcp->u_arg[1]);
421 tprintf("%#lx", tcp->u_arg[2]);
423 printitv(tcp, tcp->u_arg[2]);
430 sys_osf_setitimer(struct tcb *tcp)
433 printxval(which, tcp->u_arg[0], "ITIMER_???");
435 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
439 tprintf("%#lx", tcp->u_arg[2]);
441 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
449 static const struct xlat adjtimex_modes[] = {
452 { ADJ_OFFSET, "ADJ_OFFSET" },
455 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
458 { ADJ_MAXERROR, "ADJ_MAXERROR" },
461 { ADJ_ESTERROR, "ADJ_ESTERROR" },
464 { ADJ_STATUS, "ADJ_STATUS" },
467 { ADJ_TIMECONST, "ADJ_TIMECONST" },
470 { ADJ_TICK, "ADJ_TICK" },
472 #ifdef ADJ_OFFSET_SINGLESHOT
473 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
478 static const struct xlat adjtimex_status[] = {
480 { STA_PLL, "STA_PLL" },
483 { STA_PPSFREQ, "STA_PPSFREQ" },
486 { STA_PPSTIME, "STA_PPSTIME" },
489 { STA_FLL, "STA_FLL" },
492 { STA_INS, "STA_INS" },
495 { STA_DEL, "STA_DEL" },
498 { STA_UNSYNC, "STA_UNSYNC" },
501 { STA_FREQHOLD, "STA_FREQHOLD" },
504 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
507 { STA_PPSJITTER, "STA_PPSJITTER" },
510 { STA_PPSWANDER, "STA_PPSWANDER" },
513 { STA_PPSERROR, "STA_PPSERROR" },
516 { STA_CLOCKERR, "STA_CLOCKERR" },
521 static const struct xlat adjtimex_state[] = {
523 { TIME_OK, "TIME_OK" },
526 { TIME_INS, "TIME_INS" },
529 { TIME_DEL, "TIME_DEL" },
532 { TIME_OOP, "TIME_OOP" },
535 { TIME_WAIT, "TIME_WAIT" },
538 { TIME_ERROR, "TIME_ERROR" },
543 #if SUPPORTED_PERSONALITIES > 1
545 tprint_timex32(struct tcb *tcp, long addr)
557 struct timeval32 time;
569 if (umove(tcp, addr, &tx) < 0)
573 printflags(adjtimex_modes, tx.modes, "ADJ_???");
574 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
575 tx.offset, tx.freq, tx.maxerror);
576 tprintf("esterror=%u, status=", tx.esterror);
577 printflags(adjtimex_status, tx.status, "STA_???");
578 tprintf(", constant=%d, precision=%u, ",
579 tx.constant, tx.precision);
580 tprintf("tolerance=%d, time=", tx.tolerance);
581 tprint_timeval32(tcp, &tx.time);
582 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
583 tx.tick, tx.ppsfreq, tx.jitter);
584 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
585 tx.shift, tx.stabil, tx.jitcnt);
586 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
587 tx.calcnt, tx.errcnt, tx.stbcnt);
591 #endif /* SUPPORTED_PERSONALITIES > 1 */
594 tprint_timex(struct tcb *tcp, long addr)
598 #if SUPPORTED_PERSONALITIES > 1
599 if (personality_wordsize[current_personality] == 4)
600 return tprint_timex32(tcp, addr);
602 if (umove(tcp, addr, &tx) < 0)
605 #if LINUX_VERSION_CODE < 66332
606 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
607 tx.mode, tx.offset, tx.frequency);
608 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
609 tx.maxerror, tx.esterror, tx.status);
610 tprintf("time_constant=%ld, precision=%lu, ",
611 tx.time_constant, tx.precision);
612 tprintf("tolerance=%ld, time=", tx.tolerance);
613 tprint_timeval(tcp, &tx.time);
616 printflags(adjtimex_modes, tx.modes, "ADJ_???");
617 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
618 tx.offset, tx.freq, tx.maxerror);
619 tprintf("esterror=%lu, status=", tx.esterror);
620 printflags(adjtimex_status, tx.status, "STA_???");
621 tprintf(", constant=%ld, precision=%lu, ",
622 tx.constant, tx.precision);
623 tprintf("tolerance=%ld, time=", tx.tolerance);
624 tprint_timeval(tcp, &tx.time);
625 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
626 tx.tick, tx.ppsfreq, tx.jitter);
627 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
628 tx.shift, tx.stabil, tx.jitcnt);
629 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
630 tx.calcnt, tx.errcnt, tx.stbcnt);
637 sys_adjtimex(struct tcb *tcp)
640 if (tcp->u_arg[0] == 0)
642 else if (syserror(tcp) || !verbose(tcp))
643 tprintf("%#lx", tcp->u_arg[0]);
644 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
648 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
655 static const struct xlat clockflags[] = {
656 { TIMER_ABSTIME, "TIMER_ABSTIME" },
660 static const struct xlat clocknames[] = {
661 #ifdef CLOCK_REALTIME
662 { CLOCK_REALTIME, "CLOCK_REALTIME" },
664 #ifdef CLOCK_MONOTONIC
665 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
667 #ifdef CLOCK_PROCESS_CPUTIME_ID
668 { CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID" },
670 #ifdef CLOCK_THREAD_CPUTIME_ID
671 { CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID" },
673 #ifdef CLOCK_MONOTONIC_RAW
674 { CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW" },
676 #ifdef CLOCK_REALTIME_COARSE
677 { CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE" },
679 #ifdef CLOCK_MONOTONIC_COARSE
680 { CLOCK_MONOTONIC_COARSE, "CLOCK_MONOTONIC_COARSE" },
686 sys_clock_settime(struct tcb *tcp)
689 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
691 printtv(tcp, tcp->u_arg[1]);
697 sys_clock_gettime(struct tcb *tcp)
700 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
704 tprintf("%#lx", tcp->u_arg[1]);
706 printtv(tcp, tcp->u_arg[1]);
712 sys_clock_nanosleep(struct tcb *tcp)
715 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
717 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
719 printtv(tcp, tcp->u_arg[2]);
723 tprintf("%#lx", tcp->u_arg[3]);
725 printtv(tcp, tcp->u_arg[3]);
730 #ifndef SIGEV_THREAD_ID
731 # define SIGEV_THREAD_ID 4
733 static const struct xlat sigev_value[] = {
734 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
735 { SIGEV_NONE+1, "SIGEV_NONE" },
736 { SIGEV_THREAD+1, "SIGEV_THREAD" },
737 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
741 #if SUPPORTED_PERSONALITIES > 1
743 printsigevent32(struct tcb *tcp, long arg)
753 int function, attribute;
758 if (umove(tcp, arg, &sev) < 0)
761 tprintf("{%#x, ", sev.sigev_value);
762 if (sev.sigev_notify == SIGEV_SIGNAL)
763 tprintf("%s, ", signame(sev.sigev_signo));
765 tprintf("%u, ", sev.sigev_signo);
766 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
768 if (sev.sigev_notify == SIGEV_THREAD_ID)
769 tprintf("{%d}", sev.un.tid);
770 else if (sev.sigev_notify == SIGEV_THREAD)
771 tprintf("{%#x, %#x}",
772 sev.un.thread.function,
773 sev.un.thread.attribute);
782 printsigevent(struct tcb *tcp, long arg)
786 #if SUPPORTED_PERSONALITIES > 1
787 if (personality_wordsize[current_personality] == 4)
789 printsigevent32(tcp, arg);
793 if (umove(tcp, arg, &sev) < 0)
796 tprintf("{%p, ", sev.sigev_value.sival_ptr);
797 if (sev.sigev_notify == SIGEV_SIGNAL)
798 tprintf("%s, ", signame(sev.sigev_signo));
800 tprintf("%u, ", sev.sigev_signo);
801 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
803 if (sev.sigev_notify == SIGEV_THREAD_ID)
804 /* _pad[0] is the _tid field which might not be
805 present in the userlevel definition of the
807 tprintf("{%d}", sev._sigev_un._pad[0]);
808 else if (sev.sigev_notify == SIGEV_THREAD)
809 tprintf("{%p, %p}", sev.sigev_notify_function,
810 sev.sigev_notify_attributes);
818 sys_timer_create(struct tcb *tcp)
821 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
823 printsigevent(tcp, tcp->u_arg[1]);
828 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
829 tprintf("%#lx", tcp->u_arg[2]);
831 tprintf("{%d}", timer_id);
837 sys_timer_settime(struct tcb *tcp)
840 tprintf("%#lx, ", tcp->u_arg[0]);
841 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
843 printitv(tcp, tcp->u_arg[2]);
847 tprintf("%#lx", tcp->u_arg[3]);
849 printitv(tcp, tcp->u_arg[3]);
855 sys_timer_gettime(struct tcb *tcp)
858 tprintf("%#lx, ", tcp->u_arg[0]);
861 tprintf("%#lx", tcp->u_arg[1]);
863 printitv(tcp, tcp->u_arg[1]);
869 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
871 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
872 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
873 rt->tm_sec, rt->tm_min, rt->tm_hour,
874 rt->tm_mday, rt->tm_mon, rt->tm_year);
876 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
877 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
883 rtc_ioctl(struct tcb *tcp, long code, long arg)
890 if (umove(tcp, arg, &rt) < 0)
891 tprintf(", %#lx", arg);
902 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
903 tprintf(", %#lx", arg);
913 tprintf(", %lu", arg);
918 tprintf(", %lu", arg);
922 struct rtc_wkalrm wk;
923 if (umove(tcp, arg, &wk) < 0)
924 tprintf(", %#lx", arg);
926 tprintf(", {enabled=%d, pending=%d, ",
927 wk.enabled, wk.pending);
928 print_rtc(tcp, &wk.time);
935 struct rtc_wkalrm wk;
936 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
937 tprintf(", %#lx", arg);
939 tprintf(", {enabled=%d, pending=%d, ",
940 wk.enabled, wk.pending);
941 print_rtc(tcp, &wk.time);
948 tprintf(", %#lx", arg);
954 #ifndef TFD_TIMER_ABSTIME
955 #define TFD_TIMER_ABSTIME (1 << 0)
958 static const struct xlat timerfdflags[] = {
959 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
964 sys_timerfd(struct tcb *tcp)
967 /* It does not matter that the kernel uses itimerspec. */
968 tprintf("%ld, ", tcp->u_arg[0]);
969 printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
971 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
973 printitv(tcp, tcp->u_arg[3]);
979 sys_timerfd_create(struct tcb *tcp)
982 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
984 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
990 sys_timerfd_settime(struct tcb *tcp)
993 printfd(tcp, tcp->u_arg[0]);
995 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
997 printitv(tcp, tcp->u_arg[2]);
999 printitv(tcp, tcp->u_arg[3]);
1005 sys_timerfd_gettime(struct tcb *tcp)
1007 if (entering(tcp)) {
1008 printfd(tcp, tcp->u_arg[0]);
1010 printitv(tcp, tcp->u_arg[1]);