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)
69 char buf[TIMEVAL_TEXT_BUFSIZE];
70 sprinttv(buf, tcp, addr, bitness, special);
75 sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
80 return stpcpy(buf, "NULL");
83 return buf + sprintf(buf, "%#lx", addr);
85 if (bitness == BITNESS_32
86 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
87 || personality_wordsize[current_personality] == 4
93 rc = umove(tcp, addr, &tv);
95 if (special && tv.tv_sec == 0) {
96 if (tv.tv_usec == UTIME_NOW)
97 return stpcpy(buf, "UTIME_NOW");
98 if (tv.tv_usec == UTIME_OMIT)
99 return stpcpy(buf, "UTIME_OMIT");
101 return buf + sprintf(buf, "{%u, %u}",
102 tv.tv_sec, tv.tv_usec);
107 rc = umove(tcp, addr, &tv);
109 if (special && tv.tv_sec == 0) {
110 if (tv.tv_usec == UTIME_NOW)
111 return stpcpy(buf, "UTIME_NOW");
112 if (tv.tv_usec == UTIME_OMIT)
113 return stpcpy(buf, "UTIME_OMIT");
115 return buf + sprintf(buf, "{%lu, %lu}",
116 (unsigned long) tv.tv_sec,
117 (unsigned long) tv.tv_usec);
121 return stpcpy(buf, "{...}");
125 print_timespec(struct tcb *tcp, long addr)
127 char buf[TIMESPEC_TEXT_BUFSIZE];
128 sprint_timespec(buf, tcp, addr);
133 sprint_timespec(char *buf, struct tcb *tcp, long addr)
137 else if (!verbose(tcp))
138 sprintf(buf, "%#lx", addr);
142 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
143 if (personality_wordsize[current_personality] == 4) {
146 rc = umove(tcp, addr, &tv);
148 sprintf(buf, "{%u, %u}",
149 tv.tv_sec, tv.tv_usec);
155 rc = umove(tcp, addr, &ts);
157 sprintf(buf, "{%lu, %lu}",
158 (unsigned long) ts.tv_sec,
159 (unsigned long) ts.tv_nsec);
162 strcpy(buf, "{...}");
167 sys_time(struct tcb *tcp)
171 printnum(tcp, tcp->u_arg[0], "%ld");
178 sys_stime(struct tcb *tcp)
181 printnum(tcp, tcp->u_arg[0], "%ld");
187 sys_gettimeofday(struct tcb *tcp)
191 tprintf("%#lx, %#lx",
192 tcp->u_arg[0], tcp->u_arg[1]);
195 printtv(tcp, tcp->u_arg[0]);
198 printtv(tcp, tcp->u_arg[1]);
207 sys_osf_gettimeofday(struct tcb *tcp)
211 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
214 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
217 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
225 sys_settimeofday(struct tcb *tcp)
228 printtv(tcp, tcp->u_arg[0]);
231 printtv(tcp, tcp->u_arg[1]);
239 sys_osf_settimeofday(struct tcb *tcp)
242 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
245 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
253 sys_adjtime(struct tcb *tcp)
256 printtv(tcp, tcp->u_arg[0]);
260 tprintf("%#lx", tcp->u_arg[1]);
262 printtv(tcp, tcp->u_arg[1]);
268 sys_nanosleep(struct tcb *tcp)
271 print_timespec(tcp, tcp->u_arg[0]);
274 /* Second (returned) timespec is only significant
275 * if syscall was interrupted. We print only its address
276 * on _success_, since kernel doesn't modify its value.
278 if (is_restart_error(tcp) || !tcp->u_arg[1])
279 /* Interrupted (or NULL) */
280 print_timespec(tcp, tcp->u_arg[1]);
283 tprintf("%#lx", tcp->u_arg[1]);
288 static const struct xlat which[] = {
289 { ITIMER_REAL, "ITIMER_REAL" },
290 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
291 { ITIMER_PROF, "ITIMER_PROF" },
296 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
300 else if (!verbose(tcp))
301 tprintf("%#lx", addr);
305 if (bitness == BITNESS_32
306 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
307 || personality_wordsize[current_personality] == 4
312 struct timeval32 it_interval, it_value;
315 rc = umove(tcp, addr, &itv);
317 tprints("{it_interval=");
318 tprint_timeval32(tcp, &itv.it_interval);
319 tprints(", it_value=");
320 tprint_timeval32(tcp, &itv.it_value);
324 struct itimerval itv;
326 rc = umove(tcp, addr, &itv);
328 tprints("{it_interval=");
329 tprint_timeval(tcp, &itv.it_interval);
330 tprints(", it_value=");
331 tprint_timeval(tcp, &itv.it_value);
340 #define printitv(tcp, addr) \
341 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
344 sys_getitimer(struct tcb *tcp)
347 printxval(which, tcp->u_arg[0], "ITIMER_???");
351 tprintf("%#lx", tcp->u_arg[1]);
353 printitv(tcp, tcp->u_arg[1]);
361 sys_osf_getitimer(struct tcb *tcp)
364 printxval(which, tcp->u_arg[0], "ITIMER_???");
368 tprintf("%#lx", tcp->u_arg[1]);
370 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
377 sys_setitimer(struct tcb *tcp)
380 printxval(which, tcp->u_arg[0], "ITIMER_???");
382 printitv(tcp, tcp->u_arg[1]);
386 tprintf("%#lx", tcp->u_arg[2]);
388 printitv(tcp, tcp->u_arg[2]);
395 sys_osf_setitimer(struct tcb *tcp)
398 printxval(which, tcp->u_arg[0], "ITIMER_???");
400 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
404 tprintf("%#lx", tcp->u_arg[2]);
406 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
414 static const struct xlat adjtimex_modes[] = {
417 { ADJ_OFFSET, "ADJ_OFFSET" },
420 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
423 { ADJ_MAXERROR, "ADJ_MAXERROR" },
426 { ADJ_ESTERROR, "ADJ_ESTERROR" },
429 { ADJ_STATUS, "ADJ_STATUS" },
432 { ADJ_TIMECONST, "ADJ_TIMECONST" },
435 { ADJ_TICK, "ADJ_TICK" },
437 #ifdef ADJ_OFFSET_SINGLESHOT
438 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
443 static const struct xlat adjtimex_status[] = {
445 { STA_PLL, "STA_PLL" },
448 { STA_PPSFREQ, "STA_PPSFREQ" },
451 { STA_PPSTIME, "STA_PPSTIME" },
454 { STA_FLL, "STA_FLL" },
457 { STA_INS, "STA_INS" },
460 { STA_DEL, "STA_DEL" },
463 { STA_UNSYNC, "STA_UNSYNC" },
466 { STA_FREQHOLD, "STA_FREQHOLD" },
469 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
472 { STA_PPSJITTER, "STA_PPSJITTER" },
475 { STA_PPSWANDER, "STA_PPSWANDER" },
478 { STA_PPSERROR, "STA_PPSERROR" },
481 { STA_CLOCKERR, "STA_CLOCKERR" },
486 static const struct xlat adjtimex_state[] = {
488 { TIME_OK, "TIME_OK" },
491 { TIME_INS, "TIME_INS" },
494 { TIME_DEL, "TIME_DEL" },
497 { TIME_OOP, "TIME_OOP" },
500 { TIME_WAIT, "TIME_WAIT" },
503 { TIME_ERROR, "TIME_ERROR" },
508 #if SUPPORTED_PERSONALITIES > 1
510 tprint_timex32(struct tcb *tcp, long addr)
522 struct timeval32 time;
534 if (umove(tcp, addr, &tx) < 0)
538 printflags(adjtimex_modes, tx.modes, "ADJ_???");
539 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
540 tx.offset, tx.freq, tx.maxerror);
541 tprintf("esterror=%u, status=", tx.esterror);
542 printflags(adjtimex_status, tx.status, "STA_???");
543 tprintf(", constant=%d, precision=%u, ",
544 tx.constant, tx.precision);
545 tprintf("tolerance=%d, time=", tx.tolerance);
546 tprint_timeval32(tcp, &tx.time);
547 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
548 tx.tick, tx.ppsfreq, tx.jitter);
549 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
550 tx.shift, tx.stabil, tx.jitcnt);
551 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
552 tx.calcnt, tx.errcnt, tx.stbcnt);
556 #endif /* SUPPORTED_PERSONALITIES > 1 */
559 tprint_timex(struct tcb *tcp, long addr)
563 #if SUPPORTED_PERSONALITIES > 1
564 if (personality_wordsize[current_personality] == 4)
565 return tprint_timex32(tcp, addr);
567 if (umove(tcp, addr, &tx) < 0)
570 #if LINUX_VERSION_CODE < 66332
571 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
572 tx.mode, tx.offset, tx.frequency);
573 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
574 tx.maxerror, tx.esterror, tx.status);
575 tprintf("time_constant=%ld, precision=%lu, ",
576 tx.time_constant, tx.precision);
577 tprintf("tolerance=%ld, time=", tx.tolerance);
578 tprint_timeval(tcp, &tx.time);
581 printflags(adjtimex_modes, tx.modes, "ADJ_???");
582 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
583 tx.offset, tx.freq, tx.maxerror);
584 tprintf("esterror=%lu, status=", tx.esterror);
585 printflags(adjtimex_status, tx.status, "STA_???");
586 tprintf(", constant=%ld, precision=%lu, ",
587 tx.constant, tx.precision);
588 tprintf("tolerance=%ld, time=", tx.tolerance);
589 tprint_timeval(tcp, &tx.time);
590 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
591 tx.tick, tx.ppsfreq, tx.jitter);
592 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
593 tx.shift, tx.stabil, tx.jitcnt);
594 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
595 tx.calcnt, tx.errcnt, tx.stbcnt);
602 sys_adjtimex(struct tcb *tcp)
605 if (tcp->u_arg[0] == 0)
607 else if (syserror(tcp) || !verbose(tcp))
608 tprintf("%#lx", tcp->u_arg[0]);
609 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
613 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
620 static const struct xlat clockflags[] = {
621 { TIMER_ABSTIME, "TIMER_ABSTIME" },
625 static const struct xlat clocknames[] = {
626 #ifdef CLOCK_REALTIME
627 { CLOCK_REALTIME, "CLOCK_REALTIME" },
629 #ifdef CLOCK_MONOTONIC
630 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
632 #ifdef CLOCK_PROCESS_CPUTIME_ID
633 { CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID" },
635 #ifdef CLOCK_THREAD_CPUTIME_ID
636 { CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID" },
638 #ifdef CLOCK_MONOTONIC_RAW
639 { CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW" },
641 #ifdef CLOCK_REALTIME_COARSE
642 { CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE" },
644 #ifdef CLOCK_MONOTONIC_COARSE
645 { CLOCK_MONOTONIC_COARSE, "CLOCK_MONOTONIC_COARSE" },
651 sys_clock_settime(struct tcb *tcp)
654 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
656 printtv(tcp, tcp->u_arg[1]);
662 sys_clock_gettime(struct tcb *tcp)
665 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
669 tprintf("%#lx", tcp->u_arg[1]);
671 printtv(tcp, tcp->u_arg[1]);
677 sys_clock_nanosleep(struct tcb *tcp)
680 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
682 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
684 printtv(tcp, tcp->u_arg[2]);
688 tprintf("%#lx", tcp->u_arg[3]);
690 printtv(tcp, tcp->u_arg[3]);
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]);