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. On success, we print
260 * only its address, since kernel doesn't modify it,
261 * and printing the value may show uninitialized data.
263 switch (tcp->u_error) {
265 /* Not interrupted (slept entire interval) */
267 tprintf("%#lx", tcp->u_arg[1]);
270 /* Fall through: print_timespec(NULL) prints "NULL" */
274 case ERESTART_RESTARTBLOCK:
276 print_timespec(tcp, tcp->u_arg[1]);
282 static const struct xlat which[] = {
284 XLAT(ITIMER_VIRTUAL),
290 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
294 else if (!verbose(tcp))
295 tprintf("%#lx", addr);
299 if (bitness == BITNESS_32
300 #if SUPPORTED_PERSONALITIES > 1
301 || current_wordsize == 4
306 struct timeval32 it_interval, it_value;
309 rc = umove(tcp, addr, &itv);
311 tprints("{it_interval=");
312 tprint_timeval32(tcp, &itv.it_interval);
313 tprints(", it_value=");
314 tprint_timeval32(tcp, &itv.it_value);
318 struct itimerval itv;
320 rc = umove(tcp, addr, &itv);
322 tprints("{it_interval=");
323 tprint_timeval(tcp, &itv.it_interval);
324 tprints(", it_value=");
325 tprint_timeval(tcp, &itv.it_value);
334 #define printitv(tcp, addr) \
335 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
338 sys_getitimer(struct tcb *tcp)
341 printxval(which, tcp->u_arg[0], "ITIMER_???");
345 tprintf("%#lx", tcp->u_arg[1]);
347 printitv(tcp, tcp->u_arg[1]);
354 sys_osf_getitimer(struct tcb *tcp)
357 printxval(which, tcp->u_arg[0], "ITIMER_???");
361 tprintf("%#lx", tcp->u_arg[1]);
363 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
370 sys_setitimer(struct tcb *tcp)
373 printxval(which, tcp->u_arg[0], "ITIMER_???");
375 printitv(tcp, tcp->u_arg[1]);
379 tprintf("%#lx", tcp->u_arg[2]);
381 printitv(tcp, tcp->u_arg[2]);
388 sys_osf_setitimer(struct tcb *tcp)
391 printxval(which, tcp->u_arg[0], "ITIMER_???");
393 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
397 tprintf("%#lx", tcp->u_arg[2]);
399 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
405 static const struct xlat adjtimex_modes[] = {
440 #ifdef ADJ_OFFSET_SINGLESHOT
441 XLAT(ADJ_OFFSET_SINGLESHOT),
443 #ifdef ADJ_OFFSET_SS_READ
444 XLAT(ADJ_OFFSET_SS_READ),
449 static const struct xlat adjtimex_status[] = {
501 static const struct xlat adjtimex_state[] = {
523 #if SUPPORTED_PERSONALITIES > 1
525 tprint_timex32(struct tcb *tcp, long addr)
537 struct timeval32 time;
549 if (umove(tcp, addr, &tx) < 0)
553 printflags(adjtimex_modes, tx.modes, "ADJ_???");
554 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
555 tx.offset, tx.freq, tx.maxerror);
556 tprintf("esterror=%u, status=", tx.esterror);
557 printflags(adjtimex_status, tx.status, "STA_???");
558 tprintf(", constant=%d, precision=%u, ",
559 tx.constant, tx.precision);
560 tprintf("tolerance=%d, time=", tx.tolerance);
561 tprint_timeval32(tcp, &tx.time);
562 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
563 tx.tick, tx.ppsfreq, tx.jitter);
564 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
565 tx.shift, tx.stabil, tx.jitcnt);
566 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
567 tx.calcnt, tx.errcnt, tx.stbcnt);
571 #endif /* SUPPORTED_PERSONALITIES > 1 */
574 tprint_timex(struct tcb *tcp, long addr)
578 #if SUPPORTED_PERSONALITIES > 1
579 if (current_wordsize == 4)
580 return tprint_timex32(tcp, addr);
582 if (umove(tcp, addr, &tx) < 0)
585 #if LINUX_VERSION_CODE < 66332
586 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
587 tx.mode, tx.offset, tx.frequency);
588 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
589 tx.maxerror, tx.esterror, tx.status);
590 tprintf("time_constant=%ld, precision=%lu, ",
591 tx.time_constant, tx.precision);
592 tprintf("tolerance=%ld, time=", tx.tolerance);
593 tprint_timeval(tcp, &tx.time);
596 printflags(adjtimex_modes, tx.modes, "ADJ_???");
597 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
598 (long) tx.offset, (long) tx.freq, (long) tx.maxerror);
599 tprintf("esterror=%lu, status=", (long) tx.esterror);
600 printflags(adjtimex_status, tx.status, "STA_???");
601 tprintf(", constant=%ld, precision=%lu, ",
602 (long) tx.constant, (long) tx.precision);
603 tprintf("tolerance=%ld, time=", (long) tx.tolerance);
604 tprint_timeval(tcp, &tx.time);
605 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
606 (long) tx.tick, (long) tx.ppsfreq, (long) tx.jitter);
607 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
608 tx.shift, (long) tx.stabil, (long) tx.jitcnt);
609 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
610 (long) tx.calcnt, (long) tx.errcnt, (long) tx.stbcnt);
617 do_adjtimex(struct tcb *tcp, long addr)
621 else if (syserror(tcp) || !verbose(tcp))
622 tprintf("%#lx", addr);
623 else if (tprint_timex(tcp, addr) < 0)
627 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
634 sys_adjtimex(struct tcb *tcp)
637 return do_adjtimex(tcp, tcp->u_arg[0]);
641 static const struct xlat clockflags[] = {
646 static const struct xlat clocknames[] = {
647 #ifdef CLOCK_REALTIME
648 XLAT(CLOCK_REALTIME),
650 #ifdef CLOCK_MONOTONIC
651 XLAT(CLOCK_MONOTONIC),
653 #ifdef CLOCK_PROCESS_CPUTIME_ID
654 XLAT(CLOCK_PROCESS_CPUTIME_ID),
656 #ifdef CLOCK_THREAD_CPUTIME_ID
657 XLAT(CLOCK_THREAD_CPUTIME_ID),
659 #ifdef CLOCK_MONOTONIC_RAW
660 XLAT(CLOCK_MONOTONIC_RAW),
662 #ifdef CLOCK_REALTIME_COARSE
663 XLAT(CLOCK_REALTIME_COARSE),
665 #ifdef CLOCK_MONOTONIC_COARSE
666 XLAT(CLOCK_MONOTONIC_COARSE),
672 static const struct xlat cpuclocknames[] = {
675 XLAT(CPUCLOCK_SCHED),
681 printclockname(int clockid)
685 if ((clockid & CLOCKFD_MASK) == CLOCKFD)
686 tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
688 if(CPUCLOCK_PERTHREAD(clockid))
689 tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
691 tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
692 printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
698 printxval(clocknames, clockid, "CLOCK_???");
702 sys_clock_settime(struct tcb *tcp)
705 printclockname(tcp->u_arg[0]);
707 printtv(tcp, tcp->u_arg[1]);
713 sys_clock_gettime(struct tcb *tcp)
716 printclockname(tcp->u_arg[0]);
720 tprintf("%#lx", tcp->u_arg[1]);
722 printtv(tcp, tcp->u_arg[1]);
728 sys_clock_nanosleep(struct tcb *tcp)
731 printclockname(tcp->u_arg[0]);
733 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
735 printtv(tcp, tcp->u_arg[2]);
739 tprintf("%#lx", tcp->u_arg[3]);
741 printtv(tcp, tcp->u_arg[3]);
747 sys_clock_adjtime(struct tcb *tcp)
750 return do_adjtimex(tcp, tcp->u_arg[1]);
751 printclockname(tcp->u_arg[0]);
756 #ifndef SIGEV_THREAD_ID
757 # define SIGEV_THREAD_ID 4
759 static const struct xlat sigev_value[] = {
763 XLAT(SIGEV_THREAD_ID),
767 #if SUPPORTED_PERSONALITIES > 1
769 printsigevent32(struct tcb *tcp, long arg)
779 int function, attribute;
784 if (umove(tcp, arg, &sev) < 0)
787 tprintf("{%#x, ", sev.sigev_value);
788 if (sev.sigev_notify == SIGEV_SIGNAL)
789 tprintf("%s, ", signame(sev.sigev_signo));
791 tprintf("%u, ", sev.sigev_signo);
792 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
794 if (sev.sigev_notify == SIGEV_THREAD_ID)
795 tprintf("{%d}", sev.un.tid);
796 else if (sev.sigev_notify == SIGEV_THREAD)
797 tprintf("{%#x, %#x}",
798 sev.un.thread.function,
799 sev.un.thread.attribute);
808 printsigevent(struct tcb *tcp, long arg)
812 #if SUPPORTED_PERSONALITIES > 1
813 if (current_wordsize == 4) {
814 printsigevent32(tcp, arg);
818 if (umove(tcp, arg, &sev) < 0)
821 tprintf("{%p, ", sev.sigev_value.sival_ptr);
822 if (sev.sigev_notify == SIGEV_SIGNAL)
823 tprintf("%s, ", signame(sev.sigev_signo));
825 tprintf("%u, ", sev.sigev_signo);
826 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
828 if (sev.sigev_notify == SIGEV_THREAD_ID)
829 #if defined(HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD)
830 /* _pad[0] is the _tid field which might not be
831 present in the userlevel definition of the
833 tprintf("{%d}", sev._sigev_un._pad[0]);
834 #elif defined(HAVE_STRUCT_SIGEVENT___PAD)
835 tprintf("{%d}", sev.__pad[0]);
837 # warning unfamiliar struct sigevent => incomplete SIGEV_THREAD_ID decoding
840 else if (sev.sigev_notify == SIGEV_THREAD)
841 tprintf("{%p, %p}", sev.sigev_notify_function,
842 sev.sigev_notify_attributes);
850 sys_timer_create(struct tcb *tcp)
853 printclockname(tcp->u_arg[0]);
855 printsigevent(tcp, tcp->u_arg[1]);
860 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
861 tprintf("%#lx", tcp->u_arg[2]);
863 tprintf("{%d}", timer_id);
869 sys_timer_settime(struct tcb *tcp)
872 tprintf("%#lx, ", tcp->u_arg[0]);
873 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
875 printitv(tcp, tcp->u_arg[2]);
879 tprintf("%#lx", tcp->u_arg[3]);
881 printitv(tcp, tcp->u_arg[3]);
887 sys_timer_gettime(struct tcb *tcp)
890 tprintf("%#lx, ", tcp->u_arg[0]);
893 tprintf("%#lx", tcp->u_arg[1]);
895 printitv(tcp, tcp->u_arg[1]);
901 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
903 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
904 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
905 rt->tm_sec, rt->tm_min, rt->tm_hour,
906 rt->tm_mday, rt->tm_mon, rt->tm_year);
908 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
909 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
915 rtc_ioctl(struct tcb *tcp, long code, long arg)
922 if (umove(tcp, arg, &rt) < 0)
923 tprintf(", %#lx", arg);
934 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
935 tprintf(", %#lx", arg);
945 tprintf(", %lu", arg);
950 tprintf(", %lu", arg);
954 struct rtc_wkalrm wk;
955 if (umove(tcp, arg, &wk) < 0)
956 tprintf(", %#lx", arg);
958 tprintf(", {enabled=%d, pending=%d, ",
959 wk.enabled, wk.pending);
960 print_rtc(tcp, &wk.time);
967 struct rtc_wkalrm wk;
968 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
969 tprintf(", %#lx", arg);
971 tprintf(", {enabled=%d, pending=%d, ",
972 wk.enabled, wk.pending);
973 print_rtc(tcp, &wk.time);
980 tprintf(", %#lx", arg);
986 #ifndef TFD_TIMER_ABSTIME
987 #define TFD_TIMER_ABSTIME (1 << 0)
990 static const struct xlat timerfdflags[] = {
991 XLAT(TFD_TIMER_ABSTIME),
996 sys_timerfd(struct tcb *tcp)
999 /* It does not matter that the kernel uses itimerspec. */
1000 tprintf("%ld, ", tcp->u_arg[0]);
1001 printclockname(tcp->u_arg[0]);
1003 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
1005 printitv(tcp, tcp->u_arg[3]);
1011 sys_timerfd_create(struct tcb *tcp)
1013 if (entering(tcp)) {
1014 printclockname(tcp->u_arg[0]);
1016 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
1022 sys_timerfd_settime(struct tcb *tcp)
1024 if (entering(tcp)) {
1025 printfd(tcp, tcp->u_arg[0]);
1027 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
1029 printitv(tcp, tcp->u_arg[2]);
1031 printitv(tcp, tcp->u_arg[3]);
1037 sys_timerfd_gettime(struct tcb *tcp)
1039 if (entering(tcp)) {
1040 printfd(tcp, tcp->u_arg[0]);
1042 printitv(tcp, tcp->u_arg[1]);