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.
34 #include <linux/version.h>
35 #include <sys/timex.h>
36 #include <linux/ioctl.h>
37 #include <linux/rtc.h>
40 #define UTIME_NOW ((1l << 30) - 1l)
43 #define UTIME_OMIT ((1l << 30) - 2l)
48 u_int32_t tv_sec, tv_usec;
52 tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
54 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
58 tprint_timeval(struct tcb *tcp, const struct timeval *tv)
61 (unsigned long) tv->tv_sec, (unsigned long) tv->tv_usec);
65 printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
67 char buf[TIMEVAL_TEXT_BUFSIZE];
68 sprinttv(buf, tcp, addr, bitness, special);
73 sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
78 return stpcpy(buf, "NULL");
81 return buf + sprintf(buf, "%#lx", addr);
83 if (bitness == BITNESS_32
84 #if SUPPORTED_PERSONALITIES > 1
85 || personality_wordsize[current_personality] == 4
91 rc = umove(tcp, addr, &tv);
93 if (special && tv.tv_sec == 0) {
94 if (tv.tv_usec == UTIME_NOW)
95 return stpcpy(buf, "UTIME_NOW");
96 if (tv.tv_usec == UTIME_OMIT)
97 return stpcpy(buf, "UTIME_OMIT");
99 return buf + sprintf(buf, "{%u, %u}",
100 tv.tv_sec, tv.tv_usec);
105 rc = umove(tcp, addr, &tv);
107 if (special && tv.tv_sec == 0) {
108 if (tv.tv_usec == UTIME_NOW)
109 return stpcpy(buf, "UTIME_NOW");
110 if (tv.tv_usec == UTIME_OMIT)
111 return stpcpy(buf, "UTIME_OMIT");
113 return buf + sprintf(buf, "{%lu, %lu}",
114 (unsigned long) tv.tv_sec,
115 (unsigned long) tv.tv_usec);
119 return stpcpy(buf, "{...}");
123 print_timespec(struct tcb *tcp, long addr)
125 char buf[TIMESPEC_TEXT_BUFSIZE];
126 sprint_timespec(buf, tcp, addr);
131 sprint_timespec(char *buf, struct tcb *tcp, long addr)
135 else if (!verbose(tcp))
136 sprintf(buf, "%#lx", addr);
140 #if SUPPORTED_PERSONALITIES > 1
141 if (personality_wordsize[current_personality] == 4) {
144 rc = umove(tcp, addr, &tv);
146 sprintf(buf, "{%u, %u}",
147 tv.tv_sec, tv.tv_usec);
153 rc = umove(tcp, addr, &ts);
155 sprintf(buf, "{%lu, %lu}",
156 (unsigned long) ts.tv_sec,
157 (unsigned long) ts.tv_nsec);
160 strcpy(buf, "{...}");
165 sys_time(struct tcb *tcp)
168 printnum(tcp, tcp->u_arg[0], "%ld");
174 sys_stime(struct tcb *tcp)
177 printnum(tcp, tcp->u_arg[0], "%ld");
183 sys_gettimeofday(struct tcb *tcp)
187 tprintf("%#lx, %#lx",
188 tcp->u_arg[0], tcp->u_arg[1]);
191 printtv(tcp, tcp->u_arg[0]);
193 printtv(tcp, tcp->u_arg[1]);
201 sys_osf_gettimeofday(struct tcb *tcp)
205 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
208 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
210 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
217 sys_settimeofday(struct tcb *tcp)
220 printtv(tcp, tcp->u_arg[0]);
222 printtv(tcp, tcp->u_arg[1]);
229 sys_osf_settimeofday(struct tcb *tcp)
232 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
234 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
241 sys_adjtime(struct tcb *tcp)
244 printtv(tcp, tcp->u_arg[0]);
248 tprintf("%#lx", tcp->u_arg[1]);
250 printtv(tcp, tcp->u_arg[1]);
256 sys_nanosleep(struct tcb *tcp)
259 print_timespec(tcp, tcp->u_arg[0]);
262 /* Second (returned) timespec is only significant
263 * if syscall was interrupted. We print only its address
264 * on _success_, since kernel doesn't modify its value.
266 if (is_restart_error(tcp) || !tcp->u_arg[1])
267 /* Interrupted (or NULL) */
268 print_timespec(tcp, tcp->u_arg[1]);
271 tprintf("%#lx", tcp->u_arg[1]);
276 static const struct xlat which[] = {
277 { ITIMER_REAL, "ITIMER_REAL" },
278 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
279 { ITIMER_PROF, "ITIMER_PROF" },
284 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
288 else if (!verbose(tcp))
289 tprintf("%#lx", addr);
293 if (bitness == BITNESS_32
294 #if SUPPORTED_PERSONALITIES > 1
295 || personality_wordsize[current_personality] == 4
300 struct timeval32 it_interval, it_value;
303 rc = umove(tcp, addr, &itv);
305 tprints("{it_interval=");
306 tprint_timeval32(tcp, &itv.it_interval);
307 tprints(", it_value=");
308 tprint_timeval32(tcp, &itv.it_value);
312 struct itimerval itv;
314 rc = umove(tcp, addr, &itv);
316 tprints("{it_interval=");
317 tprint_timeval(tcp, &itv.it_interval);
318 tprints(", it_value=");
319 tprint_timeval(tcp, &itv.it_value);
328 #define printitv(tcp, addr) \
329 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
332 sys_getitimer(struct tcb *tcp)
335 printxval(which, tcp->u_arg[0], "ITIMER_???");
339 tprintf("%#lx", tcp->u_arg[1]);
341 printitv(tcp, tcp->u_arg[1]);
349 sys_osf_getitimer(struct tcb *tcp)
352 printxval(which, tcp->u_arg[0], "ITIMER_???");
356 tprintf("%#lx", tcp->u_arg[1]);
358 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
365 sys_setitimer(struct tcb *tcp)
368 printxval(which, tcp->u_arg[0], "ITIMER_???");
370 printitv(tcp, tcp->u_arg[1]);
374 tprintf("%#lx", tcp->u_arg[2]);
376 printitv(tcp, tcp->u_arg[2]);
383 sys_osf_setitimer(struct tcb *tcp)
386 printxval(which, tcp->u_arg[0], "ITIMER_???");
388 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
392 tprintf("%#lx", tcp->u_arg[2]);
394 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
401 static const struct xlat adjtimex_modes[] = {
404 { ADJ_OFFSET, "ADJ_OFFSET" },
407 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
410 { ADJ_MAXERROR, "ADJ_MAXERROR" },
413 { ADJ_ESTERROR, "ADJ_ESTERROR" },
416 { ADJ_STATUS, "ADJ_STATUS" },
419 { ADJ_TIMECONST, "ADJ_TIMECONST" },
422 { ADJ_TICK, "ADJ_TICK" },
424 #ifdef ADJ_OFFSET_SINGLESHOT
425 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
430 static const struct xlat adjtimex_status[] = {
432 { STA_PLL, "STA_PLL" },
435 { STA_PPSFREQ, "STA_PPSFREQ" },
438 { STA_PPSTIME, "STA_PPSTIME" },
441 { STA_FLL, "STA_FLL" },
444 { STA_INS, "STA_INS" },
447 { STA_DEL, "STA_DEL" },
450 { STA_UNSYNC, "STA_UNSYNC" },
453 { STA_FREQHOLD, "STA_FREQHOLD" },
456 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
459 { STA_PPSJITTER, "STA_PPSJITTER" },
462 { STA_PPSWANDER, "STA_PPSWANDER" },
465 { STA_PPSERROR, "STA_PPSERROR" },
468 { STA_CLOCKERR, "STA_CLOCKERR" },
473 static const struct xlat adjtimex_state[] = {
475 { TIME_OK, "TIME_OK" },
478 { TIME_INS, "TIME_INS" },
481 { TIME_DEL, "TIME_DEL" },
484 { TIME_OOP, "TIME_OOP" },
487 { TIME_WAIT, "TIME_WAIT" },
490 { TIME_ERROR, "TIME_ERROR" },
495 #if SUPPORTED_PERSONALITIES > 1
497 tprint_timex32(struct tcb *tcp, long addr)
509 struct timeval32 time;
521 if (umove(tcp, addr, &tx) < 0)
525 printflags(adjtimex_modes, tx.modes, "ADJ_???");
526 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
527 tx.offset, tx.freq, tx.maxerror);
528 tprintf("esterror=%u, status=", tx.esterror);
529 printflags(adjtimex_status, tx.status, "STA_???");
530 tprintf(", constant=%d, precision=%u, ",
531 tx.constant, tx.precision);
532 tprintf("tolerance=%d, time=", tx.tolerance);
533 tprint_timeval32(tcp, &tx.time);
534 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
535 tx.tick, tx.ppsfreq, tx.jitter);
536 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
537 tx.shift, tx.stabil, tx.jitcnt);
538 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
539 tx.calcnt, tx.errcnt, tx.stbcnt);
543 #endif /* SUPPORTED_PERSONALITIES > 1 */
546 tprint_timex(struct tcb *tcp, long addr)
550 #if SUPPORTED_PERSONALITIES > 1
551 if (personality_wordsize[current_personality] == 4)
552 return tprint_timex32(tcp, addr);
554 if (umove(tcp, addr, &tx) < 0)
557 #if LINUX_VERSION_CODE < 66332
558 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
559 tx.mode, tx.offset, tx.frequency);
560 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
561 tx.maxerror, tx.esterror, tx.status);
562 tprintf("time_constant=%ld, precision=%lu, ",
563 tx.time_constant, tx.precision);
564 tprintf("tolerance=%ld, time=", tx.tolerance);
565 tprint_timeval(tcp, &tx.time);
568 printflags(adjtimex_modes, tx.modes, "ADJ_???");
569 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
570 (long) tx.offset, (long) tx.freq, (long) tx.maxerror);
571 tprintf("esterror=%lu, status=", (long) tx.esterror);
572 printflags(adjtimex_status, tx.status, "STA_???");
573 tprintf(", constant=%ld, precision=%lu, ",
574 (long) tx.constant, (long) tx.precision);
575 tprintf("tolerance=%ld, time=", (long) tx.tolerance);
576 tprint_timeval(tcp, &tx.time);
577 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
578 (long) tx.tick, (long) tx.ppsfreq, (long) tx.jitter);
579 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
580 tx.shift, (long) tx.stabil, (long) tx.jitcnt);
581 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
582 (long) tx.calcnt, (long) tx.errcnt, (long) tx.stbcnt);
589 sys_adjtimex(struct tcb *tcp)
592 if (tcp->u_arg[0] == 0)
594 else if (syserror(tcp) || !verbose(tcp))
595 tprintf("%#lx", tcp->u_arg[0]);
596 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
600 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
607 static const struct xlat clockflags[] = {
608 { TIMER_ABSTIME, "TIMER_ABSTIME" },
612 static const struct xlat clocknames[] = {
613 #ifdef CLOCK_REALTIME
614 { CLOCK_REALTIME, "CLOCK_REALTIME" },
616 #ifdef CLOCK_MONOTONIC
617 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
619 #ifdef CLOCK_PROCESS_CPUTIME_ID
620 { CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID" },
622 #ifdef CLOCK_THREAD_CPUTIME_ID
623 { CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID" },
625 #ifdef CLOCK_MONOTONIC_RAW
626 { CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW" },
628 #ifdef CLOCK_REALTIME_COARSE
629 { CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE" },
631 #ifdef CLOCK_MONOTONIC_COARSE
632 { CLOCK_MONOTONIC_COARSE, "CLOCK_MONOTONIC_COARSE" },
638 sys_clock_settime(struct tcb *tcp)
641 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
643 printtv(tcp, tcp->u_arg[1]);
649 sys_clock_gettime(struct tcb *tcp)
652 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
656 tprintf("%#lx", tcp->u_arg[1]);
658 printtv(tcp, tcp->u_arg[1]);
664 sys_clock_nanosleep(struct tcb *tcp)
667 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
669 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
671 printtv(tcp, tcp->u_arg[2]);
675 tprintf("%#lx", tcp->u_arg[3]);
677 printtv(tcp, tcp->u_arg[3]);
682 #ifndef SIGEV_THREAD_ID
683 # define SIGEV_THREAD_ID 4
685 static const struct xlat sigev_value[] = {
686 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
687 { SIGEV_NONE+1, "SIGEV_NONE" },
688 { SIGEV_THREAD+1, "SIGEV_THREAD" },
689 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
693 #if SUPPORTED_PERSONALITIES > 1
695 printsigevent32(struct tcb *tcp, long arg)
705 int function, attribute;
710 if (umove(tcp, arg, &sev) < 0)
713 tprintf("{%#x, ", sev.sigev_value);
714 if (sev.sigev_notify == SIGEV_SIGNAL)
715 tprintf("%s, ", signame(sev.sigev_signo));
717 tprintf("%u, ", sev.sigev_signo);
718 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
720 if (sev.sigev_notify == SIGEV_THREAD_ID)
721 tprintf("{%d}", sev.un.tid);
722 else if (sev.sigev_notify == SIGEV_THREAD)
723 tprintf("{%#x, %#x}",
724 sev.un.thread.function,
725 sev.un.thread.attribute);
734 printsigevent(struct tcb *tcp, long arg)
738 #if SUPPORTED_PERSONALITIES > 1
739 if (personality_wordsize[current_personality] == 4) {
740 printsigevent32(tcp, arg);
744 if (umove(tcp, arg, &sev) < 0)
747 tprintf("{%p, ", sev.sigev_value.sival_ptr);
748 if (sev.sigev_notify == SIGEV_SIGNAL)
749 tprintf("%s, ", signame(sev.sigev_signo));
751 tprintf("%u, ", sev.sigev_signo);
752 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
754 if (sev.sigev_notify == SIGEV_THREAD_ID)
755 /* _pad[0] is the _tid field which might not be
756 present in the userlevel definition of the
758 tprintf("{%d}", sev._sigev_un._pad[0]);
759 else if (sev.sigev_notify == SIGEV_THREAD)
760 tprintf("{%p, %p}", sev.sigev_notify_function,
761 sev.sigev_notify_attributes);
769 sys_timer_create(struct tcb *tcp)
772 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
774 printsigevent(tcp, tcp->u_arg[1]);
779 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
780 tprintf("%#lx", tcp->u_arg[2]);
782 tprintf("{%d}", timer_id);
788 sys_timer_settime(struct tcb *tcp)
791 tprintf("%#lx, ", tcp->u_arg[0]);
792 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
794 printitv(tcp, tcp->u_arg[2]);
798 tprintf("%#lx", tcp->u_arg[3]);
800 printitv(tcp, tcp->u_arg[3]);
806 sys_timer_gettime(struct tcb *tcp)
809 tprintf("%#lx, ", tcp->u_arg[0]);
812 tprintf("%#lx", tcp->u_arg[1]);
814 printitv(tcp, tcp->u_arg[1]);
820 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
822 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
823 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
824 rt->tm_sec, rt->tm_min, rt->tm_hour,
825 rt->tm_mday, rt->tm_mon, rt->tm_year);
827 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
828 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
834 rtc_ioctl(struct tcb *tcp, long code, long arg)
841 if (umove(tcp, arg, &rt) < 0)
842 tprintf(", %#lx", arg);
853 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
854 tprintf(", %#lx", arg);
864 tprintf(", %lu", arg);
869 tprintf(", %lu", arg);
873 struct rtc_wkalrm wk;
874 if (umove(tcp, arg, &wk) < 0)
875 tprintf(", %#lx", arg);
877 tprintf(", {enabled=%d, pending=%d, ",
878 wk.enabled, wk.pending);
879 print_rtc(tcp, &wk.time);
886 struct rtc_wkalrm wk;
887 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
888 tprintf(", %#lx", arg);
890 tprintf(", {enabled=%d, pending=%d, ",
891 wk.enabled, wk.pending);
892 print_rtc(tcp, &wk.time);
899 tprintf(", %#lx", arg);
905 #ifndef TFD_TIMER_ABSTIME
906 #define TFD_TIMER_ABSTIME (1 << 0)
909 static const struct xlat timerfdflags[] = {
910 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
915 sys_timerfd(struct tcb *tcp)
918 /* It does not matter that the kernel uses itimerspec. */
919 tprintf("%ld, ", tcp->u_arg[0]);
920 printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
922 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
924 printitv(tcp, tcp->u_arg[3]);
930 sys_timerfd_create(struct tcb *tcp)
933 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
935 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
941 sys_timerfd_settime(struct tcb *tcp)
944 printfd(tcp, tcp->u_arg[0]);
946 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
948 printitv(tcp, tcp->u_arg[2]);
950 printitv(tcp, tcp->u_arg[3]);
956 sys_timerfd_gettime(struct tcb *tcp)
959 printfd(tcp, tcp->u_arg[0]);
961 printitv(tcp, tcp->u_arg[1]);