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.
31 #include <linux/version.h>
32 #include <sys/timex.h>
33 #include <linux/ioctl.h>
34 #include <linux/rtc.h>
37 #define UTIME_NOW ((1l << 30) - 1l)
40 #define UTIME_OMIT ((1l << 30) - 2l)
45 u_int32_t tv_sec, tv_usec;
49 tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
51 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
55 tprint_timeval(struct tcb *tcp, const struct timeval *tv)
58 (unsigned long) tv->tv_sec, (unsigned long) tv->tv_usec);
62 printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
64 char buf[TIMEVAL_TEXT_BUFSIZE];
65 sprinttv(buf, tcp, addr, bitness, special);
70 sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
75 return stpcpy(buf, "NULL");
78 return buf + sprintf(buf, "%#lx", addr);
80 if (bitness == BITNESS_32
81 #if SUPPORTED_PERSONALITIES > 1
82 || current_wordsize == 4
88 rc = umove(tcp, addr, &tv);
90 if (special && tv.tv_sec == 0) {
91 if (tv.tv_usec == UTIME_NOW)
92 return stpcpy(buf, "UTIME_NOW");
93 if (tv.tv_usec == UTIME_OMIT)
94 return stpcpy(buf, "UTIME_OMIT");
96 return buf + sprintf(buf, "{%u, %u}",
97 tv.tv_sec, tv.tv_usec);
102 rc = umove(tcp, addr, &tv);
104 if (special && tv.tv_sec == 0) {
105 if (tv.tv_usec == UTIME_NOW)
106 return stpcpy(buf, "UTIME_NOW");
107 if (tv.tv_usec == UTIME_OMIT)
108 return stpcpy(buf, "UTIME_OMIT");
110 return buf + sprintf(buf, "{%lu, %lu}",
111 (unsigned long) tv.tv_sec,
112 (unsigned long) tv.tv_usec);
116 return stpcpy(buf, "{...}");
120 print_timespec(struct tcb *tcp, long addr)
122 char buf[TIMESPEC_TEXT_BUFSIZE];
123 sprint_timespec(buf, tcp, addr);
128 sprint_timespec(char *buf, struct tcb *tcp, long addr)
132 else if (!verbose(tcp))
133 sprintf(buf, "%#lx", addr);
137 #if SUPPORTED_PERSONALITIES > 1
138 if (current_wordsize == 4) {
141 rc = umove(tcp, addr, &tv);
143 sprintf(buf, "{%u, %u}",
144 tv.tv_sec, tv.tv_usec);
150 rc = umove(tcp, addr, &ts);
152 sprintf(buf, "{%lu, %lu}",
153 (unsigned long) ts.tv_sec,
154 (unsigned long) ts.tv_nsec);
157 strcpy(buf, "{...}");
162 sys_time(struct tcb *tcp)
165 printnum(tcp, tcp->u_arg[0], "%ld");
171 sys_stime(struct tcb *tcp)
174 printnum(tcp, tcp->u_arg[0], "%ld");
180 sys_gettimeofday(struct tcb *tcp)
184 tprintf("%#lx, %#lx",
185 tcp->u_arg[0], tcp->u_arg[1]);
188 printtv(tcp, tcp->u_arg[0]);
190 printtv(tcp, tcp->u_arg[1]);
197 sys_osf_gettimeofday(struct tcb *tcp)
201 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
204 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
206 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
213 sys_settimeofday(struct tcb *tcp)
216 printtv(tcp, tcp->u_arg[0]);
218 printtv(tcp, tcp->u_arg[1]);
225 sys_osf_settimeofday(struct tcb *tcp)
228 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
230 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
237 sys_adjtime(struct tcb *tcp)
240 printtv(tcp, tcp->u_arg[0]);
244 tprintf("%#lx", tcp->u_arg[1]);
246 printtv(tcp, tcp->u_arg[1]);
252 sys_nanosleep(struct tcb *tcp)
255 print_timespec(tcp, tcp->u_arg[0]);
258 /* Second (returned) timespec is only significant
259 * if syscall was interrupted. We print only its address
260 * on _success_, since kernel doesn't modify its value.
262 if (is_restart_error(tcp) || !tcp->u_arg[1])
263 /* Interrupted (or NULL) */
264 print_timespec(tcp, tcp->u_arg[1]);
267 tprintf("%#lx", tcp->u_arg[1]);
272 static const struct xlat which[] = {
273 { ITIMER_REAL, "ITIMER_REAL" },
274 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
275 { ITIMER_PROF, "ITIMER_PROF" },
280 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
284 else if (!verbose(tcp))
285 tprintf("%#lx", addr);
289 if (bitness == BITNESS_32
290 #if SUPPORTED_PERSONALITIES > 1
291 || current_wordsize == 4
296 struct timeval32 it_interval, it_value;
299 rc = umove(tcp, addr, &itv);
301 tprints("{it_interval=");
302 tprint_timeval32(tcp, &itv.it_interval);
303 tprints(", it_value=");
304 tprint_timeval32(tcp, &itv.it_value);
308 struct itimerval itv;
310 rc = umove(tcp, addr, &itv);
312 tprints("{it_interval=");
313 tprint_timeval(tcp, &itv.it_interval);
314 tprints(", it_value=");
315 tprint_timeval(tcp, &itv.it_value);
324 #define printitv(tcp, addr) \
325 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
328 sys_getitimer(struct tcb *tcp)
331 printxval(which, tcp->u_arg[0], "ITIMER_???");
335 tprintf("%#lx", tcp->u_arg[1]);
337 printitv(tcp, tcp->u_arg[1]);
344 sys_osf_getitimer(struct tcb *tcp)
347 printxval(which, tcp->u_arg[0], "ITIMER_???");
351 tprintf("%#lx", tcp->u_arg[1]);
353 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
360 sys_setitimer(struct tcb *tcp)
363 printxval(which, tcp->u_arg[0], "ITIMER_???");
365 printitv(tcp, tcp->u_arg[1]);
369 tprintf("%#lx", tcp->u_arg[2]);
371 printitv(tcp, tcp->u_arg[2]);
378 sys_osf_setitimer(struct tcb *tcp)
381 printxval(which, tcp->u_arg[0], "ITIMER_???");
383 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
387 tprintf("%#lx", tcp->u_arg[2]);
389 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
395 static const struct xlat adjtimex_modes[] = {
398 { ADJ_OFFSET, "ADJ_OFFSET" },
401 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
404 { ADJ_MAXERROR, "ADJ_MAXERROR" },
407 { ADJ_ESTERROR, "ADJ_ESTERROR" },
410 { ADJ_STATUS, "ADJ_STATUS" },
413 { ADJ_TIMECONST, "ADJ_TIMECONST" },
416 { ADJ_TICK, "ADJ_TICK" },
418 #ifdef ADJ_OFFSET_SINGLESHOT
419 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
424 static const struct xlat adjtimex_status[] = {
426 { STA_PLL, "STA_PLL" },
429 { STA_PPSFREQ, "STA_PPSFREQ" },
432 { STA_PPSTIME, "STA_PPSTIME" },
435 { STA_FLL, "STA_FLL" },
438 { STA_INS, "STA_INS" },
441 { STA_DEL, "STA_DEL" },
444 { STA_UNSYNC, "STA_UNSYNC" },
447 { STA_FREQHOLD, "STA_FREQHOLD" },
450 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
453 { STA_PPSJITTER, "STA_PPSJITTER" },
456 { STA_PPSWANDER, "STA_PPSWANDER" },
459 { STA_PPSERROR, "STA_PPSERROR" },
462 { STA_CLOCKERR, "STA_CLOCKERR" },
467 static const struct xlat adjtimex_state[] = {
469 { TIME_OK, "TIME_OK" },
472 { TIME_INS, "TIME_INS" },
475 { TIME_DEL, "TIME_DEL" },
478 { TIME_OOP, "TIME_OOP" },
481 { TIME_WAIT, "TIME_WAIT" },
484 { TIME_ERROR, "TIME_ERROR" },
489 #if SUPPORTED_PERSONALITIES > 1
491 tprint_timex32(struct tcb *tcp, long addr)
503 struct timeval32 time;
515 if (umove(tcp, addr, &tx) < 0)
519 printflags(adjtimex_modes, tx.modes, "ADJ_???");
520 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
521 tx.offset, tx.freq, tx.maxerror);
522 tprintf("esterror=%u, status=", tx.esterror);
523 printflags(adjtimex_status, tx.status, "STA_???");
524 tprintf(", constant=%d, precision=%u, ",
525 tx.constant, tx.precision);
526 tprintf("tolerance=%d, time=", tx.tolerance);
527 tprint_timeval32(tcp, &tx.time);
528 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
529 tx.tick, tx.ppsfreq, tx.jitter);
530 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
531 tx.shift, tx.stabil, tx.jitcnt);
532 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
533 tx.calcnt, tx.errcnt, tx.stbcnt);
537 #endif /* SUPPORTED_PERSONALITIES > 1 */
540 tprint_timex(struct tcb *tcp, long addr)
544 #if SUPPORTED_PERSONALITIES > 1
545 if (current_wordsize == 4)
546 return tprint_timex32(tcp, addr);
548 if (umove(tcp, addr, &tx) < 0)
551 #if LINUX_VERSION_CODE < 66332
552 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
553 tx.mode, tx.offset, tx.frequency);
554 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
555 tx.maxerror, tx.esterror, tx.status);
556 tprintf("time_constant=%ld, precision=%lu, ",
557 tx.time_constant, tx.precision);
558 tprintf("tolerance=%ld, time=", tx.tolerance);
559 tprint_timeval(tcp, &tx.time);
562 printflags(adjtimex_modes, tx.modes, "ADJ_???");
563 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
564 (long) tx.offset, (long) tx.freq, (long) tx.maxerror);
565 tprintf("esterror=%lu, status=", (long) tx.esterror);
566 printflags(adjtimex_status, tx.status, "STA_???");
567 tprintf(", constant=%ld, precision=%lu, ",
568 (long) tx.constant, (long) tx.precision);
569 tprintf("tolerance=%ld, time=", (long) tx.tolerance);
570 tprint_timeval(tcp, &tx.time);
571 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
572 (long) tx.tick, (long) tx.ppsfreq, (long) tx.jitter);
573 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
574 tx.shift, (long) tx.stabil, (long) tx.jitcnt);
575 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
576 (long) tx.calcnt, (long) tx.errcnt, (long) tx.stbcnt);
583 do_adjtimex(struct tcb *tcp, long addr)
587 else if (syserror(tcp) || !verbose(tcp))
588 tprintf("%#lx", addr);
589 else if (tprint_timex(tcp, addr) < 0)
593 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
600 sys_adjtimex(struct tcb *tcp)
603 return do_adjtimex(tcp, tcp->u_arg[0]);
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]);
683 sys_clock_adjtime(struct tcb *tcp)
686 return do_adjtimex(tcp, tcp->u_arg[1]);
687 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
692 #ifndef SIGEV_THREAD_ID
693 # define SIGEV_THREAD_ID 4
695 static const struct xlat sigev_value[] = {
696 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
697 { SIGEV_NONE+1, "SIGEV_NONE" },
698 { SIGEV_THREAD+1, "SIGEV_THREAD" },
699 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
703 #if SUPPORTED_PERSONALITIES > 1
705 printsigevent32(struct tcb *tcp, long arg)
715 int function, attribute;
720 if (umove(tcp, arg, &sev) < 0)
723 tprintf("{%#x, ", sev.sigev_value);
724 if (sev.sigev_notify == SIGEV_SIGNAL)
725 tprintf("%s, ", signame(sev.sigev_signo));
727 tprintf("%u, ", sev.sigev_signo);
728 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
730 if (sev.sigev_notify == SIGEV_THREAD_ID)
731 tprintf("{%d}", sev.un.tid);
732 else if (sev.sigev_notify == SIGEV_THREAD)
733 tprintf("{%#x, %#x}",
734 sev.un.thread.function,
735 sev.un.thread.attribute);
744 printsigevent(struct tcb *tcp, long arg)
748 #if SUPPORTED_PERSONALITIES > 1
749 if (current_wordsize == 4) {
750 printsigevent32(tcp, arg);
754 if (umove(tcp, arg, &sev) < 0)
757 tprintf("{%p, ", sev.sigev_value.sival_ptr);
758 if (sev.sigev_notify == SIGEV_SIGNAL)
759 tprintf("%s, ", signame(sev.sigev_signo));
761 tprintf("%u, ", sev.sigev_signo);
762 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
764 if (sev.sigev_notify == SIGEV_THREAD_ID)
765 /* _pad[0] is the _tid field which might not be
766 present in the userlevel definition of the
768 tprintf("{%d}", sev._sigev_un._pad[0]);
769 else if (sev.sigev_notify == SIGEV_THREAD)
770 tprintf("{%p, %p}", sev.sigev_notify_function,
771 sev.sigev_notify_attributes);
779 sys_timer_create(struct tcb *tcp)
782 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
784 printsigevent(tcp, tcp->u_arg[1]);
789 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
790 tprintf("%#lx", tcp->u_arg[2]);
792 tprintf("{%d}", timer_id);
798 sys_timer_settime(struct tcb *tcp)
801 tprintf("%#lx, ", tcp->u_arg[0]);
802 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
804 printitv(tcp, tcp->u_arg[2]);
808 tprintf("%#lx", tcp->u_arg[3]);
810 printitv(tcp, tcp->u_arg[3]);
816 sys_timer_gettime(struct tcb *tcp)
819 tprintf("%#lx, ", tcp->u_arg[0]);
822 tprintf("%#lx", tcp->u_arg[1]);
824 printitv(tcp, tcp->u_arg[1]);
830 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
832 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
833 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
834 rt->tm_sec, rt->tm_min, rt->tm_hour,
835 rt->tm_mday, rt->tm_mon, rt->tm_year);
837 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
838 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
844 rtc_ioctl(struct tcb *tcp, long code, long arg)
851 if (umove(tcp, arg, &rt) < 0)
852 tprintf(", %#lx", arg);
863 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
864 tprintf(", %#lx", arg);
874 tprintf(", %lu", arg);
879 tprintf(", %lu", arg);
883 struct rtc_wkalrm wk;
884 if (umove(tcp, arg, &wk) < 0)
885 tprintf(", %#lx", arg);
887 tprintf(", {enabled=%d, pending=%d, ",
888 wk.enabled, wk.pending);
889 print_rtc(tcp, &wk.time);
896 struct rtc_wkalrm wk;
897 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
898 tprintf(", %#lx", arg);
900 tprintf(", {enabled=%d, pending=%d, ",
901 wk.enabled, wk.pending);
902 print_rtc(tcp, &wk.time);
909 tprintf(", %#lx", arg);
915 #ifndef TFD_TIMER_ABSTIME
916 #define TFD_TIMER_ABSTIME (1 << 0)
919 static const struct xlat timerfdflags[] = {
920 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
925 sys_timerfd(struct tcb *tcp)
928 /* It does not matter that the kernel uses itimerspec. */
929 tprintf("%ld, ", tcp->u_arg[0]);
930 printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
932 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
934 printitv(tcp, tcp->u_arg[3]);
940 sys_timerfd_create(struct tcb *tcp)
943 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
945 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
951 sys_timerfd_settime(struct tcb *tcp)
954 printfd(tcp, tcp->u_arg[0]);
956 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
958 printitv(tcp, tcp->u_arg[2]);
960 printitv(tcp, tcp->u_arg[3]);
966 sys_timerfd_gettime(struct tcb *tcp)
969 printfd(tcp, tcp->u_arg[0]);
971 printitv(tcp, tcp->u_arg[1]);