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]);
200 sys_osf_gettimeofday(struct tcb *tcp)
204 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
207 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
209 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
216 sys_settimeofday(struct tcb *tcp)
219 printtv(tcp, tcp->u_arg[0]);
221 printtv(tcp, tcp->u_arg[1]);
228 sys_osf_settimeofday(struct tcb *tcp)
231 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
233 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
240 sys_adjtime(struct tcb *tcp)
243 printtv(tcp, tcp->u_arg[0]);
247 tprintf("%#lx", tcp->u_arg[1]);
249 printtv(tcp, tcp->u_arg[1]);
255 sys_nanosleep(struct tcb *tcp)
258 print_timespec(tcp, tcp->u_arg[0]);
261 /* Second (returned) timespec is only significant
262 * if syscall was interrupted. We print only its address
263 * on _success_, since kernel doesn't modify its value.
265 if (is_restart_error(tcp) || !tcp->u_arg[1])
266 /* Interrupted (or NULL) */
267 print_timespec(tcp, tcp->u_arg[1]);
270 tprintf("%#lx", tcp->u_arg[1]);
275 static const struct xlat which[] = {
276 { ITIMER_REAL, "ITIMER_REAL" },
277 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
278 { ITIMER_PROF, "ITIMER_PROF" },
283 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
287 else if (!verbose(tcp))
288 tprintf("%#lx", addr);
292 if (bitness == BITNESS_32
293 #if SUPPORTED_PERSONALITIES > 1
294 || personality_wordsize[current_personality] == 4
299 struct timeval32 it_interval, it_value;
302 rc = umove(tcp, addr, &itv);
304 tprints("{it_interval=");
305 tprint_timeval32(tcp, &itv.it_interval);
306 tprints(", it_value=");
307 tprint_timeval32(tcp, &itv.it_value);
311 struct itimerval itv;
313 rc = umove(tcp, addr, &itv);
315 tprints("{it_interval=");
316 tprint_timeval(tcp, &itv.it_interval);
317 tprints(", it_value=");
318 tprint_timeval(tcp, &itv.it_value);
327 #define printitv(tcp, addr) \
328 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
331 sys_getitimer(struct tcb *tcp)
334 printxval(which, tcp->u_arg[0], "ITIMER_???");
338 tprintf("%#lx", tcp->u_arg[1]);
340 printitv(tcp, tcp->u_arg[1]);
347 sys_osf_getitimer(struct tcb *tcp)
350 printxval(which, tcp->u_arg[0], "ITIMER_???");
354 tprintf("%#lx", tcp->u_arg[1]);
356 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
363 sys_setitimer(struct tcb *tcp)
366 printxval(which, tcp->u_arg[0], "ITIMER_???");
368 printitv(tcp, tcp->u_arg[1]);
372 tprintf("%#lx", tcp->u_arg[2]);
374 printitv(tcp, tcp->u_arg[2]);
381 sys_osf_setitimer(struct tcb *tcp)
384 printxval(which, tcp->u_arg[0], "ITIMER_???");
386 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
390 tprintf("%#lx", tcp->u_arg[2]);
392 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
398 static const struct xlat adjtimex_modes[] = {
401 { ADJ_OFFSET, "ADJ_OFFSET" },
404 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
407 { ADJ_MAXERROR, "ADJ_MAXERROR" },
410 { ADJ_ESTERROR, "ADJ_ESTERROR" },
413 { ADJ_STATUS, "ADJ_STATUS" },
416 { ADJ_TIMECONST, "ADJ_TIMECONST" },
419 { ADJ_TICK, "ADJ_TICK" },
421 #ifdef ADJ_OFFSET_SINGLESHOT
422 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
427 static const struct xlat adjtimex_status[] = {
429 { STA_PLL, "STA_PLL" },
432 { STA_PPSFREQ, "STA_PPSFREQ" },
435 { STA_PPSTIME, "STA_PPSTIME" },
438 { STA_FLL, "STA_FLL" },
441 { STA_INS, "STA_INS" },
444 { STA_DEL, "STA_DEL" },
447 { STA_UNSYNC, "STA_UNSYNC" },
450 { STA_FREQHOLD, "STA_FREQHOLD" },
453 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
456 { STA_PPSJITTER, "STA_PPSJITTER" },
459 { STA_PPSWANDER, "STA_PPSWANDER" },
462 { STA_PPSERROR, "STA_PPSERROR" },
465 { STA_CLOCKERR, "STA_CLOCKERR" },
470 static const struct xlat adjtimex_state[] = {
472 { TIME_OK, "TIME_OK" },
475 { TIME_INS, "TIME_INS" },
478 { TIME_DEL, "TIME_DEL" },
481 { TIME_OOP, "TIME_OOP" },
484 { TIME_WAIT, "TIME_WAIT" },
487 { TIME_ERROR, "TIME_ERROR" },
492 #if SUPPORTED_PERSONALITIES > 1
494 tprint_timex32(struct tcb *tcp, long addr)
506 struct timeval32 time;
518 if (umove(tcp, addr, &tx) < 0)
522 printflags(adjtimex_modes, tx.modes, "ADJ_???");
523 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
524 tx.offset, tx.freq, tx.maxerror);
525 tprintf("esterror=%u, status=", tx.esterror);
526 printflags(adjtimex_status, tx.status, "STA_???");
527 tprintf(", constant=%d, precision=%u, ",
528 tx.constant, tx.precision);
529 tprintf("tolerance=%d, time=", tx.tolerance);
530 tprint_timeval32(tcp, &tx.time);
531 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
532 tx.tick, tx.ppsfreq, tx.jitter);
533 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
534 tx.shift, tx.stabil, tx.jitcnt);
535 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
536 tx.calcnt, tx.errcnt, tx.stbcnt);
540 #endif /* SUPPORTED_PERSONALITIES > 1 */
543 tprint_timex(struct tcb *tcp, long addr)
547 #if SUPPORTED_PERSONALITIES > 1
548 if (personality_wordsize[current_personality] == 4)
549 return tprint_timex32(tcp, addr);
551 if (umove(tcp, addr, &tx) < 0)
554 #if LINUX_VERSION_CODE < 66332
555 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
556 tx.mode, tx.offset, tx.frequency);
557 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
558 tx.maxerror, tx.esterror, tx.status);
559 tprintf("time_constant=%ld, precision=%lu, ",
560 tx.time_constant, tx.precision);
561 tprintf("tolerance=%ld, time=", tx.tolerance);
562 tprint_timeval(tcp, &tx.time);
565 printflags(adjtimex_modes, tx.modes, "ADJ_???");
566 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
567 (long) tx.offset, (long) tx.freq, (long) tx.maxerror);
568 tprintf("esterror=%lu, status=", (long) tx.esterror);
569 printflags(adjtimex_status, tx.status, "STA_???");
570 tprintf(", constant=%ld, precision=%lu, ",
571 (long) tx.constant, (long) tx.precision);
572 tprintf("tolerance=%ld, time=", (long) tx.tolerance);
573 tprint_timeval(tcp, &tx.time);
574 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
575 (long) tx.tick, (long) tx.ppsfreq, (long) tx.jitter);
576 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
577 tx.shift, (long) tx.stabil, (long) tx.jitcnt);
578 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
579 (long) tx.calcnt, (long) tx.errcnt, (long) tx.stbcnt);
586 do_adjtimex(struct tcb *tcp, long addr)
590 else if (syserror(tcp) || !verbose(tcp))
591 tprintf("%#lx", addr);
592 else if (tprint_timex(tcp, addr) < 0)
596 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
603 sys_adjtimex(struct tcb *tcp)
606 return do_adjtimex(tcp, tcp->u_arg[0]);
610 static const struct xlat clockflags[] = {
611 { TIMER_ABSTIME, "TIMER_ABSTIME" },
615 static const struct xlat clocknames[] = {
616 #ifdef CLOCK_REALTIME
617 { CLOCK_REALTIME, "CLOCK_REALTIME" },
619 #ifdef CLOCK_MONOTONIC
620 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
622 #ifdef CLOCK_PROCESS_CPUTIME_ID
623 { CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID" },
625 #ifdef CLOCK_THREAD_CPUTIME_ID
626 { CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID" },
628 #ifdef CLOCK_MONOTONIC_RAW
629 { CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW" },
631 #ifdef CLOCK_REALTIME_COARSE
632 { CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE" },
634 #ifdef CLOCK_MONOTONIC_COARSE
635 { CLOCK_MONOTONIC_COARSE, "CLOCK_MONOTONIC_COARSE" },
641 sys_clock_settime(struct tcb *tcp)
644 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
646 printtv(tcp, tcp->u_arg[1]);
652 sys_clock_gettime(struct tcb *tcp)
655 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
659 tprintf("%#lx", tcp->u_arg[1]);
661 printtv(tcp, tcp->u_arg[1]);
667 sys_clock_nanosleep(struct tcb *tcp)
670 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
672 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
674 printtv(tcp, tcp->u_arg[2]);
678 tprintf("%#lx", tcp->u_arg[3]);
680 printtv(tcp, tcp->u_arg[3]);
686 sys_clock_adjtime(struct tcb *tcp)
689 return do_adjtimex(tcp, tcp->u_arg[1]);
690 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
695 #ifndef SIGEV_THREAD_ID
696 # define SIGEV_THREAD_ID 4
698 static const struct xlat sigev_value[] = {
699 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
700 { SIGEV_NONE+1, "SIGEV_NONE" },
701 { SIGEV_THREAD+1, "SIGEV_THREAD" },
702 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
706 #if SUPPORTED_PERSONALITIES > 1
708 printsigevent32(struct tcb *tcp, long arg)
718 int function, attribute;
723 if (umove(tcp, arg, &sev) < 0)
726 tprintf("{%#x, ", sev.sigev_value);
727 if (sev.sigev_notify == SIGEV_SIGNAL)
728 tprintf("%s, ", signame(sev.sigev_signo));
730 tprintf("%u, ", sev.sigev_signo);
731 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
733 if (sev.sigev_notify == SIGEV_THREAD_ID)
734 tprintf("{%d}", sev.un.tid);
735 else if (sev.sigev_notify == SIGEV_THREAD)
736 tprintf("{%#x, %#x}",
737 sev.un.thread.function,
738 sev.un.thread.attribute);
747 printsigevent(struct tcb *tcp, long arg)
751 #if SUPPORTED_PERSONALITIES > 1
752 if (personality_wordsize[current_personality] == 4) {
753 printsigevent32(tcp, arg);
757 if (umove(tcp, arg, &sev) < 0)
760 tprintf("{%p, ", sev.sigev_value.sival_ptr);
761 if (sev.sigev_notify == SIGEV_SIGNAL)
762 tprintf("%s, ", signame(sev.sigev_signo));
764 tprintf("%u, ", sev.sigev_signo);
765 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
767 if (sev.sigev_notify == SIGEV_THREAD_ID)
768 /* _pad[0] is the _tid field which might not be
769 present in the userlevel definition of the
771 tprintf("{%d}", sev._sigev_un._pad[0]);
772 else if (sev.sigev_notify == SIGEV_THREAD)
773 tprintf("{%p, %p}", sev.sigev_notify_function,
774 sev.sigev_notify_attributes);
782 sys_timer_create(struct tcb *tcp)
785 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
787 printsigevent(tcp, tcp->u_arg[1]);
792 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
793 tprintf("%#lx", tcp->u_arg[2]);
795 tprintf("{%d}", timer_id);
801 sys_timer_settime(struct tcb *tcp)
804 tprintf("%#lx, ", tcp->u_arg[0]);
805 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
807 printitv(tcp, tcp->u_arg[2]);
811 tprintf("%#lx", tcp->u_arg[3]);
813 printitv(tcp, tcp->u_arg[3]);
819 sys_timer_gettime(struct tcb *tcp)
822 tprintf("%#lx, ", tcp->u_arg[0]);
825 tprintf("%#lx", tcp->u_arg[1]);
827 printitv(tcp, tcp->u_arg[1]);
833 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
835 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
836 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
837 rt->tm_sec, rt->tm_min, rt->tm_hour,
838 rt->tm_mday, rt->tm_mon, rt->tm_year);
840 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
841 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
847 rtc_ioctl(struct tcb *tcp, long code, long arg)
854 if (umove(tcp, arg, &rt) < 0)
855 tprintf(", %#lx", arg);
866 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
867 tprintf(", %#lx", arg);
877 tprintf(", %lu", arg);
882 tprintf(", %lu", arg);
886 struct rtc_wkalrm wk;
887 if (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 struct rtc_wkalrm wk;
900 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
901 tprintf(", %#lx", arg);
903 tprintf(", {enabled=%d, pending=%d, ",
904 wk.enabled, wk.pending);
905 print_rtc(tcp, &wk.time);
912 tprintf(", %#lx", arg);
918 #ifndef TFD_TIMER_ABSTIME
919 #define TFD_TIMER_ABSTIME (1 << 0)
922 static const struct xlat timerfdflags[] = {
923 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
928 sys_timerfd(struct tcb *tcp)
931 /* It does not matter that the kernel uses itimerspec. */
932 tprintf("%ld, ", tcp->u_arg[0]);
933 printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
935 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
937 printitv(tcp, tcp->u_arg[3]);
943 sys_timerfd_create(struct tcb *tcp)
946 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
948 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
954 sys_timerfd_settime(struct tcb *tcp)
957 printfd(tcp, tcp->u_arg[0]);
959 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
961 printitv(tcp, tcp->u_arg[2]);
963 printitv(tcp, tcp->u_arg[3]);
969 sys_timerfd_gettime(struct tcb *tcp)
972 printfd(tcp, tcp->u_arg[0]);
974 printitv(tcp, tcp->u_arg[1]);