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 rc = umove(tcp, addr, &tv);
86 if (special && tv.tv_sec == 0 &&
87 tv.tv_usec == UTIME_NOW)
89 else if (special && tv.tv_sec == 0 &&
90 tv.tv_usec == UTIME_OMIT)
91 tprintf("UTIME_OMIT");
93 tprint_timeval32(tcp, &tv);
98 rc = umove(tcp, addr, &tv);
100 if (special && tv.tv_sec == 0 &&
101 tv.tv_usec == UTIME_NOW)
102 tprintf("UTIME_NOW");
103 else if (special && tv.tv_sec == 0 &&
104 tv.tv_usec == UTIME_OMIT)
105 tprintf("UTIME_OMIT");
107 tprint_timeval(tcp, &tv);
116 sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf)
121 return stpcpy(buf, "NULL");
124 buf += sprintf(buf, "%#lx", addr);
128 if (bitness == BITNESS_32
129 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
130 || personality_wordsize[current_personality] == 4
136 rc = umove(tcp, addr, &tv);
138 buf += sprintf(buf, "{%u, %u}",
139 tv.tv_sec, tv.tv_usec);
143 rc = umove(tcp, addr, &tv);
145 buf += sprintf(buf, "{%lu, %lu}",
146 (unsigned long) tv.tv_sec,
147 (unsigned long) tv.tv_usec);
150 buf = stpcpy(buf, "{...}");
155 void print_timespec(struct tcb *tcp, long addr)
159 else if (!verbose(tcp))
160 tprintf("%#lx", addr);
164 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
165 if (personality_wordsize[current_personality] == 4) {
168 rc = umove(tcp, addr, &tv);
171 tv.tv_sec, tv.tv_usec);
177 rc = umove(tcp, addr, &ts);
179 tprintf("{%lu, %lu}",
180 (unsigned long) ts.tv_sec,
181 (unsigned long) ts.tv_nsec);
188 void sprint_timespec(char *buf, struct tcb *tcp, long addr)
192 else if (!verbose(tcp))
193 sprintf(buf, "%#lx", addr);
197 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
198 if (personality_wordsize[current_personality] == 4) {
201 rc = umove(tcp, addr, &tv);
203 sprintf(buf, "{%u, %u}",
204 tv.tv_sec, tv.tv_usec);
210 rc = umove(tcp, addr, &ts);
212 sprintf(buf, "{%lu, %lu}",
213 (unsigned long) ts.tv_sec,
214 (unsigned long) ts.tv_nsec);
217 strcpy(buf, "{...}");
222 sys_time(struct tcb *tcp)
226 printnum(tcp, tcp->u_arg[0], "%ld");
233 sys_stime(struct tcb *tcp)
236 printnum(tcp, tcp->u_arg[0], "%ld");
242 sys_gettimeofday(struct tcb *tcp)
246 tprintf("%#lx, %#lx",
247 tcp->u_arg[0], tcp->u_arg[1]);
250 printtv(tcp, tcp->u_arg[0]);
253 printtv(tcp, tcp->u_arg[1]);
262 sys_osf_gettimeofday(struct tcb *tcp)
266 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
269 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
272 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
280 sys_settimeofday(struct tcb *tcp)
283 printtv(tcp, tcp->u_arg[0]);
286 printtv(tcp, tcp->u_arg[1]);
294 sys_osf_settimeofday(struct tcb *tcp)
297 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
300 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
308 sys_adjtime(struct tcb *tcp)
311 printtv(tcp, tcp->u_arg[0]);
315 tprintf("%#lx", tcp->u_arg[1]);
317 printtv(tcp, tcp->u_arg[1]);
323 sys_nanosleep(struct tcb *tcp)
326 print_timespec(tcp, tcp->u_arg[0]);
329 if (!tcp->u_arg[1] || is_restart_error(tcp))
330 print_timespec(tcp, tcp->u_arg[1]);
332 tprintf("%#lx", tcp->u_arg[1]);
337 static const struct xlat which[] = {
338 { ITIMER_REAL, "ITIMER_REAL" },
339 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
340 { ITIMER_PROF, "ITIMER_PROF" },
345 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
349 else if (!verbose(tcp))
350 tprintf("%#lx", addr);
354 if (bitness == BITNESS_32
355 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
356 || personality_wordsize[current_personality] == 4
361 struct timeval32 it_interval, it_value;
364 rc = umove(tcp, addr, &itv);
366 tprintf("{it_interval=");
367 tprint_timeval32(tcp, &itv.it_interval);
368 tprintf(", it_value=");
369 tprint_timeval32(tcp, &itv.it_value);
373 struct itimerval itv;
375 rc = umove(tcp, addr, &itv);
377 tprintf("{it_interval=");
378 tprint_timeval(tcp, &itv.it_interval);
379 tprintf(", it_value=");
380 tprint_timeval(tcp, &itv.it_value);
389 #define printitv(tcp, addr) \
390 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
393 sys_getitimer(struct tcb *tcp)
396 printxval(which, tcp->u_arg[0], "ITIMER_???");
400 tprintf("%#lx", tcp->u_arg[1]);
402 printitv(tcp, tcp->u_arg[1]);
410 sys_osf_getitimer(struct tcb *tcp)
413 printxval(which, tcp->u_arg[0], "ITIMER_???");
417 tprintf("%#lx", tcp->u_arg[1]);
419 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
426 sys_setitimer(struct tcb *tcp)
429 printxval(which, tcp->u_arg[0], "ITIMER_???");
431 printitv(tcp, tcp->u_arg[1]);
435 tprintf("%#lx", tcp->u_arg[2]);
437 printitv(tcp, tcp->u_arg[2]);
444 sys_osf_setitimer(struct tcb *tcp)
447 printxval(which, tcp->u_arg[0], "ITIMER_???");
449 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
453 tprintf("%#lx", tcp->u_arg[2]);
455 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
463 static const struct xlat adjtimex_modes[] = {
466 { ADJ_OFFSET, "ADJ_OFFSET" },
469 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
472 { ADJ_MAXERROR, "ADJ_MAXERROR" },
475 { ADJ_ESTERROR, "ADJ_ESTERROR" },
478 { ADJ_STATUS, "ADJ_STATUS" },
481 { ADJ_TIMECONST, "ADJ_TIMECONST" },
484 { ADJ_TICK, "ADJ_TICK" },
486 #ifdef ADJ_OFFSET_SINGLESHOT
487 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
492 static const struct xlat adjtimex_status[] = {
494 { STA_PLL, "STA_PLL" },
497 { STA_PPSFREQ, "STA_PPSFREQ" },
500 { STA_PPSTIME, "STA_PPSTIME" },
503 { STA_FLL, "STA_FLL" },
506 { STA_INS, "STA_INS" },
509 { STA_DEL, "STA_DEL" },
512 { STA_UNSYNC, "STA_UNSYNC" },
515 { STA_FREQHOLD, "STA_FREQHOLD" },
518 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
521 { STA_PPSJITTER, "STA_PPSJITTER" },
524 { STA_PPSWANDER, "STA_PPSWANDER" },
527 { STA_PPSERROR, "STA_PPSERROR" },
530 { STA_CLOCKERR, "STA_CLOCKERR" },
535 static const struct xlat adjtimex_state[] = {
537 { TIME_OK, "TIME_OK" },
540 { TIME_INS, "TIME_INS" },
543 { TIME_DEL, "TIME_DEL" },
546 { TIME_OOP, "TIME_OOP" },
549 { TIME_WAIT, "TIME_WAIT" },
552 { TIME_ERROR, "TIME_ERROR" },
557 #if SUPPORTED_PERSONALITIES > 1
559 tprint_timex32(struct tcb *tcp, long addr)
571 struct timeval32 time;
583 if (umove(tcp, addr, &tx) < 0)
587 printflags(adjtimex_modes, tx.modes, "ADJ_???");
588 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
589 tx.offset, tx.freq, tx.maxerror);
590 tprintf("esterror=%u, status=", tx.esterror);
591 printflags(adjtimex_status, tx.status, "STA_???");
592 tprintf(", constant=%d, precision=%u, ",
593 tx.constant, tx.precision);
594 tprintf("tolerance=%d, time=", tx.tolerance);
595 tprint_timeval32(tcp, &tx.time);
596 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
597 tx.tick, tx.ppsfreq, tx.jitter);
598 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
599 tx.shift, tx.stabil, tx.jitcnt);
600 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
601 tx.calcnt, tx.errcnt, tx.stbcnt);
605 #endif /* SUPPORTED_PERSONALITIES > 1 */
608 tprint_timex(struct tcb *tcp, long addr)
612 #if SUPPORTED_PERSONALITIES > 1
613 if (personality_wordsize[current_personality] == 4)
614 return tprint_timex32(tcp, addr);
616 if (umove(tcp, addr, &tx) < 0)
619 #if LINUX_VERSION_CODE < 66332
620 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
621 tx.mode, tx.offset, tx.frequency);
622 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
623 tx.maxerror, tx.esterror, tx.status);
624 tprintf("time_constant=%ld, precision=%lu, ",
625 tx.time_constant, tx.precision);
626 tprintf("tolerance=%ld, time=", tx.tolerance);
627 tprint_timeval(tcp, &tx.time);
630 printflags(adjtimex_modes, tx.modes, "ADJ_???");
631 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
632 tx.offset, tx.freq, tx.maxerror);
633 tprintf("esterror=%lu, status=", tx.esterror);
634 printflags(adjtimex_status, tx.status, "STA_???");
635 tprintf(", constant=%ld, precision=%lu, ",
636 tx.constant, tx.precision);
637 tprintf("tolerance=%ld, time=", tx.tolerance);
638 tprint_timeval(tcp, &tx.time);
639 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
640 tx.tick, tx.ppsfreq, tx.jitter);
641 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
642 tx.shift, tx.stabil, tx.jitcnt);
643 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
644 tx.calcnt, tx.errcnt, tx.stbcnt);
651 sys_adjtimex(struct tcb *tcp)
654 if (tcp->u_arg[0] == 0)
656 else if (syserror(tcp) || !verbose(tcp))
657 tprintf("%#lx", tcp->u_arg[0]);
658 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
662 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
669 static const struct xlat clockflags[] = {
670 { TIMER_ABSTIME, "TIMER_ABSTIME" },
674 static const struct xlat clocknames[] = {
675 #ifdef CLOCK_REALTIME
676 { CLOCK_REALTIME, "CLOCK_REALTIME" },
678 #ifdef CLOCK_MONOTONIC
679 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
681 #ifdef CLOCK_PROCESS_CPUTIME_ID
682 { CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID" },
684 #ifdef CLOCK_THREAD_CPUTIME_ID
685 { CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID" },
687 #ifdef CLOCK_MONOTONIC_RAW
688 { CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW" },
690 #ifdef CLOCK_REALTIME_COARSE
691 { CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE" },
693 #ifdef CLOCK_MONOTONIC_COARSE
694 { CLOCK_MONOTONIC_COARSE, "CLOCK_MONOTONIC_COARSE" },
700 sys_clock_settime(struct tcb *tcp)
703 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
705 printtv(tcp, tcp->u_arg[1]);
711 sys_clock_gettime(struct tcb *tcp)
714 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
718 tprintf("%#lx", tcp->u_arg[1]);
720 printtv(tcp, tcp->u_arg[1]);
726 sys_clock_nanosleep(struct tcb *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) {
802 printsigevent32(tcp, arg);
806 if (umove(tcp, arg, &sev) < 0)
809 tprintf("{%p, ", sev.sigev_value.sival_ptr);
810 if (sev.sigev_notify == SIGEV_SIGNAL)
811 tprintf("%s, ", signame(sev.sigev_signo));
813 tprintf("%u, ", sev.sigev_signo);
814 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
816 if (sev.sigev_notify == SIGEV_THREAD_ID)
817 /* _pad[0] is the _tid field which might not be
818 present in the userlevel definition of the
820 tprintf("{%d}", sev._sigev_un._pad[0]);
821 else if (sev.sigev_notify == SIGEV_THREAD)
822 tprintf("{%p, %p}", sev.sigev_notify_function,
823 sev.sigev_notify_attributes);
831 sys_timer_create(struct tcb *tcp)
834 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
836 printsigevent(tcp, tcp->u_arg[1]);
841 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
842 tprintf("%#lx", tcp->u_arg[2]);
844 tprintf("{%d}", timer_id);
850 sys_timer_settime(struct tcb *tcp)
853 tprintf("%#lx, ", tcp->u_arg[0]);
854 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
856 printitv(tcp, tcp->u_arg[2]);
860 tprintf("%#lx", tcp->u_arg[3]);
862 printitv(tcp, tcp->u_arg[3]);
868 sys_timer_gettime(struct tcb *tcp)
871 tprintf("%#lx, ", tcp->u_arg[0]);
874 tprintf("%#lx", tcp->u_arg[1]);
876 printitv(tcp, tcp->u_arg[1]);
882 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
884 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
885 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
886 rt->tm_sec, rt->tm_min, rt->tm_hour,
887 rt->tm_mday, rt->tm_mon, rt->tm_year);
889 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
890 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
896 rtc_ioctl(struct tcb *tcp, long code, long arg)
903 if (umove(tcp, arg, &rt) < 0)
904 tprintf(", %#lx", arg);
915 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
916 tprintf(", %#lx", arg);
926 tprintf(", %lu", arg);
931 tprintf(", %lu", arg);
935 struct rtc_wkalrm wk;
936 if (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 struct rtc_wkalrm wk;
949 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
950 tprintf(", %#lx", arg);
952 tprintf(", {enabled=%d, pending=%d, ",
953 wk.enabled, wk.pending);
954 print_rtc(tcp, &wk.time);
961 tprintf(", %#lx", arg);
967 #ifndef TFD_TIMER_ABSTIME
968 #define TFD_TIMER_ABSTIME (1 << 0)
971 static const struct xlat timerfdflags[] = {
972 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
977 sys_timerfd(struct tcb *tcp)
980 /* It does not matter that the kernel uses itimerspec. */
981 tprintf("%ld, ", tcp->u_arg[0]);
982 printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
984 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
986 printitv(tcp, tcp->u_arg[3]);
992 sys_timerfd_create(struct tcb *tcp)
995 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
997 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
1003 sys_timerfd_settime(struct tcb *tcp)
1005 if (entering(tcp)) {
1006 printfd(tcp, tcp->u_arg[0]);
1008 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
1010 printitv(tcp, tcp->u_arg[2]);
1012 printitv(tcp, tcp->u_arg[3]);
1018 sys_timerfd_gettime(struct tcb *tcp)
1020 if (entering(tcp)) {
1021 printfd(tcp, tcp->u_arg[0]);
1023 printitv(tcp, tcp->u_arg[1]);