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 tprints("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 tprints("UTIME_NOW");
103 else if (special && tv.tv_sec == 0 &&
104 tv.tv_usec == UTIME_OMIT)
105 tprints("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 return buf + sprintf(buf, "%#lx", addr);
126 if (bitness == BITNESS_32
127 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
128 || personality_wordsize[current_personality] == 4
134 rc = umove(tcp, addr, &tv);
136 return buf + sprintf(buf, "{%u, %u}",
137 tv.tv_sec, tv.tv_usec);
141 rc = umove(tcp, addr, &tv);
143 return buf + sprintf(buf, "{%lu, %lu}",
144 (unsigned long) tv.tv_sec,
145 (unsigned long) tv.tv_usec);
148 return stpcpy(buf, "{...}");
151 void print_timespec(struct tcb *tcp, long addr)
155 else if (!verbose(tcp))
156 tprintf("%#lx", addr);
160 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
161 if (personality_wordsize[current_personality] == 4) {
164 rc = umove(tcp, addr, &tv);
167 tv.tv_sec, tv.tv_usec);
173 rc = umove(tcp, addr, &ts);
175 tprintf("{%lu, %lu}",
176 (unsigned long) ts.tv_sec,
177 (unsigned long) ts.tv_nsec);
184 void sprint_timespec(char *buf, struct tcb *tcp, long addr)
188 else if (!verbose(tcp))
189 sprintf(buf, "%#lx", addr);
193 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
194 if (personality_wordsize[current_personality] == 4) {
197 rc = umove(tcp, addr, &tv);
199 sprintf(buf, "{%u, %u}",
200 tv.tv_sec, tv.tv_usec);
206 rc = umove(tcp, addr, &ts);
208 sprintf(buf, "{%lu, %lu}",
209 (unsigned long) ts.tv_sec,
210 (unsigned long) ts.tv_nsec);
213 strcpy(buf, "{...}");
218 sys_time(struct tcb *tcp)
222 printnum(tcp, tcp->u_arg[0], "%ld");
229 sys_stime(struct tcb *tcp)
232 printnum(tcp, tcp->u_arg[0], "%ld");
238 sys_gettimeofday(struct tcb *tcp)
242 tprintf("%#lx, %#lx",
243 tcp->u_arg[0], tcp->u_arg[1]);
246 printtv(tcp, tcp->u_arg[0]);
249 printtv(tcp, tcp->u_arg[1]);
258 sys_osf_gettimeofday(struct tcb *tcp)
262 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
265 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
268 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
276 sys_settimeofday(struct tcb *tcp)
279 printtv(tcp, tcp->u_arg[0]);
282 printtv(tcp, tcp->u_arg[1]);
290 sys_osf_settimeofday(struct tcb *tcp)
293 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
296 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
304 sys_adjtime(struct tcb *tcp)
307 printtv(tcp, tcp->u_arg[0]);
311 tprintf("%#lx", tcp->u_arg[1]);
313 printtv(tcp, tcp->u_arg[1]);
319 sys_nanosleep(struct tcb *tcp)
322 print_timespec(tcp, tcp->u_arg[0]);
325 if (!tcp->u_arg[1] || is_restart_error(tcp))
326 print_timespec(tcp, tcp->u_arg[1]);
328 tprintf("%#lx", tcp->u_arg[1]);
333 static const struct xlat which[] = {
334 { ITIMER_REAL, "ITIMER_REAL" },
335 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
336 { ITIMER_PROF, "ITIMER_PROF" },
341 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
345 else if (!verbose(tcp))
346 tprintf("%#lx", addr);
350 if (bitness == BITNESS_32
351 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
352 || personality_wordsize[current_personality] == 4
357 struct timeval32 it_interval, it_value;
360 rc = umove(tcp, addr, &itv);
362 tprints("{it_interval=");
363 tprint_timeval32(tcp, &itv.it_interval);
364 tprints(", it_value=");
365 tprint_timeval32(tcp, &itv.it_value);
369 struct itimerval itv;
371 rc = umove(tcp, addr, &itv);
373 tprints("{it_interval=");
374 tprint_timeval(tcp, &itv.it_interval);
375 tprints(", it_value=");
376 tprint_timeval(tcp, &itv.it_value);
385 #define printitv(tcp, addr) \
386 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
389 sys_getitimer(struct tcb *tcp)
392 printxval(which, tcp->u_arg[0], "ITIMER_???");
396 tprintf("%#lx", tcp->u_arg[1]);
398 printitv(tcp, tcp->u_arg[1]);
406 sys_osf_getitimer(struct tcb *tcp)
409 printxval(which, tcp->u_arg[0], "ITIMER_???");
413 tprintf("%#lx", tcp->u_arg[1]);
415 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
422 sys_setitimer(struct tcb *tcp)
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(struct tcb *tcp)
443 printxval(which, tcp->u_arg[0], "ITIMER_???");
445 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
449 tprintf("%#lx", tcp->u_arg[2]);
451 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
459 static const struct xlat adjtimex_modes[] = {
462 { ADJ_OFFSET, "ADJ_OFFSET" },
465 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
468 { ADJ_MAXERROR, "ADJ_MAXERROR" },
471 { ADJ_ESTERROR, "ADJ_ESTERROR" },
474 { ADJ_STATUS, "ADJ_STATUS" },
477 { ADJ_TIMECONST, "ADJ_TIMECONST" },
480 { ADJ_TICK, "ADJ_TICK" },
482 #ifdef ADJ_OFFSET_SINGLESHOT
483 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
488 static const struct xlat adjtimex_status[] = {
490 { STA_PLL, "STA_PLL" },
493 { STA_PPSFREQ, "STA_PPSFREQ" },
496 { STA_PPSTIME, "STA_PPSTIME" },
499 { STA_FLL, "STA_FLL" },
502 { STA_INS, "STA_INS" },
505 { STA_DEL, "STA_DEL" },
508 { STA_UNSYNC, "STA_UNSYNC" },
511 { STA_FREQHOLD, "STA_FREQHOLD" },
514 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
517 { STA_PPSJITTER, "STA_PPSJITTER" },
520 { STA_PPSWANDER, "STA_PPSWANDER" },
523 { STA_PPSERROR, "STA_PPSERROR" },
526 { STA_CLOCKERR, "STA_CLOCKERR" },
531 static const struct xlat adjtimex_state[] = {
533 { TIME_OK, "TIME_OK" },
536 { TIME_INS, "TIME_INS" },
539 { TIME_DEL, "TIME_DEL" },
542 { TIME_OOP, "TIME_OOP" },
545 { TIME_WAIT, "TIME_WAIT" },
548 { TIME_ERROR, "TIME_ERROR" },
553 #if SUPPORTED_PERSONALITIES > 1
555 tprint_timex32(struct tcb *tcp, long addr)
567 struct timeval32 time;
579 if (umove(tcp, addr, &tx) < 0)
583 printflags(adjtimex_modes, tx.modes, "ADJ_???");
584 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
585 tx.offset, tx.freq, tx.maxerror);
586 tprintf("esterror=%u, status=", tx.esterror);
587 printflags(adjtimex_status, tx.status, "STA_???");
588 tprintf(", constant=%d, precision=%u, ",
589 tx.constant, tx.precision);
590 tprintf("tolerance=%d, time=", tx.tolerance);
591 tprint_timeval32(tcp, &tx.time);
592 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
593 tx.tick, tx.ppsfreq, tx.jitter);
594 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
595 tx.shift, tx.stabil, tx.jitcnt);
596 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
597 tx.calcnt, tx.errcnt, tx.stbcnt);
601 #endif /* SUPPORTED_PERSONALITIES > 1 */
604 tprint_timex(struct tcb *tcp, long addr)
608 #if SUPPORTED_PERSONALITIES > 1
609 if (personality_wordsize[current_personality] == 4)
610 return tprint_timex32(tcp, addr);
612 if (umove(tcp, addr, &tx) < 0)
615 #if LINUX_VERSION_CODE < 66332
616 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
617 tx.mode, tx.offset, tx.frequency);
618 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
619 tx.maxerror, tx.esterror, tx.status);
620 tprintf("time_constant=%ld, precision=%lu, ",
621 tx.time_constant, tx.precision);
622 tprintf("tolerance=%ld, time=", tx.tolerance);
623 tprint_timeval(tcp, &tx.time);
626 printflags(adjtimex_modes, tx.modes, "ADJ_???");
627 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
628 tx.offset, tx.freq, tx.maxerror);
629 tprintf("esterror=%lu, status=", tx.esterror);
630 printflags(adjtimex_status, tx.status, "STA_???");
631 tprintf(", constant=%ld, precision=%lu, ",
632 tx.constant, tx.precision);
633 tprintf("tolerance=%ld, time=", tx.tolerance);
634 tprint_timeval(tcp, &tx.time);
635 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
636 tx.tick, tx.ppsfreq, tx.jitter);
637 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
638 tx.shift, tx.stabil, tx.jitcnt);
639 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
640 tx.calcnt, tx.errcnt, tx.stbcnt);
647 sys_adjtimex(struct tcb *tcp)
650 if (tcp->u_arg[0] == 0)
652 else if (syserror(tcp) || !verbose(tcp))
653 tprintf("%#lx", tcp->u_arg[0]);
654 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
658 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
665 static const struct xlat clockflags[] = {
666 { TIMER_ABSTIME, "TIMER_ABSTIME" },
670 static const struct xlat clocknames[] = {
671 #ifdef CLOCK_REALTIME
672 { CLOCK_REALTIME, "CLOCK_REALTIME" },
674 #ifdef CLOCK_MONOTONIC
675 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
677 #ifdef CLOCK_PROCESS_CPUTIME_ID
678 { CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID" },
680 #ifdef CLOCK_THREAD_CPUTIME_ID
681 { CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID" },
683 #ifdef CLOCK_MONOTONIC_RAW
684 { CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW" },
686 #ifdef CLOCK_REALTIME_COARSE
687 { CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE" },
689 #ifdef CLOCK_MONOTONIC_COARSE
690 { CLOCK_MONOTONIC_COARSE, "CLOCK_MONOTONIC_COARSE" },
696 sys_clock_settime(struct tcb *tcp)
699 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
701 printtv(tcp, tcp->u_arg[1]);
707 sys_clock_gettime(struct tcb *tcp)
710 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
714 tprintf("%#lx", tcp->u_arg[1]);
716 printtv(tcp, tcp->u_arg[1]);
722 sys_clock_nanosleep(struct tcb *tcp)
725 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
727 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
729 printtv(tcp, tcp->u_arg[2]);
733 tprintf("%#lx", tcp->u_arg[3]);
735 printtv(tcp, tcp->u_arg[3]);
740 #ifndef SIGEV_THREAD_ID
741 # define SIGEV_THREAD_ID 4
743 static const struct xlat sigev_value[] = {
744 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
745 { SIGEV_NONE+1, "SIGEV_NONE" },
746 { SIGEV_THREAD+1, "SIGEV_THREAD" },
747 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
751 #if SUPPORTED_PERSONALITIES > 1
753 printsigevent32(struct tcb *tcp, long arg)
763 int function, attribute;
768 if (umove(tcp, arg, &sev) < 0)
771 tprintf("{%#x, ", sev.sigev_value);
772 if (sev.sigev_notify == SIGEV_SIGNAL)
773 tprintf("%s, ", signame(sev.sigev_signo));
775 tprintf("%u, ", sev.sigev_signo);
776 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
778 if (sev.sigev_notify == SIGEV_THREAD_ID)
779 tprintf("{%d}", sev.un.tid);
780 else if (sev.sigev_notify == SIGEV_THREAD)
781 tprintf("{%#x, %#x}",
782 sev.un.thread.function,
783 sev.un.thread.attribute);
792 printsigevent(struct tcb *tcp, long arg)
796 #if SUPPORTED_PERSONALITIES > 1
797 if (personality_wordsize[current_personality] == 4) {
798 printsigevent32(tcp, arg);
802 if (umove(tcp, arg, &sev) < 0)
805 tprintf("{%p, ", sev.sigev_value.sival_ptr);
806 if (sev.sigev_notify == SIGEV_SIGNAL)
807 tprintf("%s, ", signame(sev.sigev_signo));
809 tprintf("%u, ", sev.sigev_signo);
810 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
812 if (sev.sigev_notify == SIGEV_THREAD_ID)
813 /* _pad[0] is the _tid field which might not be
814 present in the userlevel definition of the
816 tprintf("{%d}", sev._sigev_un._pad[0]);
817 else if (sev.sigev_notify == SIGEV_THREAD)
818 tprintf("{%p, %p}", sev.sigev_notify_function,
819 sev.sigev_notify_attributes);
827 sys_timer_create(struct tcb *tcp)
830 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
832 printsigevent(tcp, tcp->u_arg[1]);
837 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
838 tprintf("%#lx", tcp->u_arg[2]);
840 tprintf("{%d}", timer_id);
846 sys_timer_settime(struct tcb *tcp)
849 tprintf("%#lx, ", tcp->u_arg[0]);
850 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
852 printitv(tcp, tcp->u_arg[2]);
856 tprintf("%#lx", tcp->u_arg[3]);
858 printitv(tcp, tcp->u_arg[3]);
864 sys_timer_gettime(struct tcb *tcp)
867 tprintf("%#lx, ", tcp->u_arg[0]);
870 tprintf("%#lx", tcp->u_arg[1]);
872 printitv(tcp, tcp->u_arg[1]);
878 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
880 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
881 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
882 rt->tm_sec, rt->tm_min, rt->tm_hour,
883 rt->tm_mday, rt->tm_mon, rt->tm_year);
885 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
886 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
892 rtc_ioctl(struct tcb *tcp, long code, long arg)
899 if (umove(tcp, arg, &rt) < 0)
900 tprintf(", %#lx", arg);
911 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
912 tprintf(", %#lx", arg);
922 tprintf(", %lu", arg);
927 tprintf(", %lu", arg);
931 struct rtc_wkalrm wk;
932 if (umove(tcp, arg, &wk) < 0)
933 tprintf(", %#lx", arg);
935 tprintf(", {enabled=%d, pending=%d, ",
936 wk.enabled, wk.pending);
937 print_rtc(tcp, &wk.time);
944 struct rtc_wkalrm wk;
945 if (syserror(tcp) || 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 tprintf(", %#lx", arg);
963 #ifndef TFD_TIMER_ABSTIME
964 #define TFD_TIMER_ABSTIME (1 << 0)
967 static const struct xlat timerfdflags[] = {
968 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
973 sys_timerfd(struct tcb *tcp)
976 /* It does not matter that the kernel uses itimerspec. */
977 tprintf("%ld, ", tcp->u_arg[0]);
978 printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
980 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
982 printitv(tcp, tcp->u_arg[3]);
988 sys_timerfd_create(struct tcb *tcp)
991 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
993 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
999 sys_timerfd_settime(struct tcb *tcp)
1001 if (entering(tcp)) {
1002 printfd(tcp, tcp->u_arg[0]);
1004 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
1006 printitv(tcp, tcp->u_arg[2]);
1008 printitv(tcp, tcp->u_arg[3]);
1014 sys_timerfd_gettime(struct tcb *tcp)
1016 if (entering(tcp)) {
1017 printfd(tcp, tcp->u_arg[0]);
1019 printitv(tcp, tcp->u_arg[1]);