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.
32 #include <linux/version.h>
33 #include <sys/timex.h>
34 #include <linux/ioctl.h>
35 #include <linux/rtc.h>
38 #define UTIME_NOW ((1l << 30) - 1l)
41 #define UTIME_OMIT ((1l << 30) - 2l)
44 #if SUPPORTED_PERSONALITIES > 1
45 # if defined X86_64 || defined X32
46 # define current_time_t_is_compat (current_personality == 1)
48 # define current_time_t_is_compat (current_wordsize == 4)
51 # define current_time_t_is_compat 0
56 u_int32_t tv_sec, tv_usec;
60 tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
62 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
66 tprint_timeval(struct tcb *tcp, const struct timeval *tv)
68 tprintf("{%ju, %ju}", (uintmax_t) tv->tv_sec, (uintmax_t) tv->tv_usec);
72 printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
74 char buf[TIMEVAL_TEXT_BUFSIZE];
75 sprinttv(buf, tcp, addr, bitness, special);
80 do_sprinttv(char *buf, const uintmax_t sec, const uintmax_t usec,
86 return stpcpy(buf, "UTIME_NOW");
88 return stpcpy(buf, "UTIME_OMIT");
91 return buf + sprintf(buf, "{%ju, %ju}", sec, usec);
95 sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
98 return stpcpy(buf, "NULL");
101 return buf + sprintf(buf, "%#lx", addr);
103 if (bitness == BITNESS_32 || current_time_t_is_compat)
107 if (umove(tcp, addr, &tv) >= 0)
108 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
112 if (umove(tcp, addr, &tv) >= 0)
113 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
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_time_t_is_compat) {
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, "{%ju, %ju}",
153 (uintmax_t) ts.tv_sec,
154 (uintmax_t) ts.tv_nsec);
157 strcpy(buf, "{...}");
162 sys_time(struct tcb *tcp)
165 printnum_long(tcp, tcp->u_arg[0], "%ld");
171 sys_gettimeofday(struct tcb *tcp)
175 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
178 printtv(tcp, tcp->u_arg[0]);
180 printtv(tcp, tcp->u_arg[1]);
187 sys_osf_gettimeofday(struct tcb *tcp)
191 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
194 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
196 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
203 sys_settimeofday(struct tcb *tcp)
206 printtv(tcp, tcp->u_arg[0]);
208 printtv(tcp, tcp->u_arg[1]);
215 sys_osf_settimeofday(struct tcb *tcp)
218 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
220 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
227 sys_adjtime(struct tcb *tcp)
230 printtv(tcp, tcp->u_arg[0]);
234 tprintf("%#lx", tcp->u_arg[1]);
236 printtv(tcp, tcp->u_arg[1]);
242 sys_nanosleep(struct tcb *tcp)
245 print_timespec(tcp, tcp->u_arg[0]);
248 /* Second (returned) timespec is only significant
249 * if syscall was interrupted. On success, we print
250 * only its address, since kernel doesn't modify it,
251 * and printing the value may show uninitialized data.
253 switch (tcp->u_error) {
255 /* Not interrupted (slept entire interval) */
257 tprintf("%#lx", tcp->u_arg[1]);
260 /* Fall through: print_timespec(NULL) prints "NULL" */
264 case ERESTART_RESTARTBLOCK:
266 print_timespec(tcp, tcp->u_arg[1]);
272 #include "xlat/itimer_which.h"
275 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
279 else if (!verbose(tcp))
280 tprintf("%#lx", addr);
284 if (bitness == BITNESS_32 || current_time_t_is_compat) {
286 struct timeval32 it_interval, it_value;
289 rc = umove(tcp, addr, &itv);
291 tprints("{it_interval=");
292 tprint_timeval32(tcp, &itv.it_interval);
293 tprints(", it_value=");
294 tprint_timeval32(tcp, &itv.it_value);
298 struct itimerval itv;
300 rc = umove(tcp, addr, &itv);
302 tprints("{it_interval=");
303 tprint_timeval(tcp, &itv.it_interval);
304 tprints(", it_value=");
305 tprint_timeval(tcp, &itv.it_value);
314 #define printitv(tcp, addr) \
315 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
318 sys_getitimer(struct tcb *tcp)
321 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
325 tprintf("%#lx", tcp->u_arg[1]);
327 printitv(tcp, tcp->u_arg[1]);
334 sys_osf_getitimer(struct tcb *tcp)
337 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
341 tprintf("%#lx", tcp->u_arg[1]);
343 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
350 sys_setitimer(struct tcb *tcp)
353 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
355 printitv(tcp, tcp->u_arg[1]);
359 tprintf("%#lx", tcp->u_arg[2]);
361 printitv(tcp, tcp->u_arg[2]);
368 sys_osf_setitimer(struct tcb *tcp)
371 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
373 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
377 tprintf("%#lx", tcp->u_arg[2]);
379 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
385 #include "xlat/adjtimex_modes.h"
386 #include "xlat/adjtimex_status.h"
387 #include "xlat/adjtimex_state.h"
389 #if SUPPORTED_PERSONALITIES > 1
391 tprint_timex32(struct tcb *tcp, long addr)
403 struct timeval32 time;
415 if (umove(tcp, addr, &tx) < 0)
419 printflags(adjtimex_modes, tx.modes, "ADJ_???");
420 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
421 tx.offset, tx.freq, tx.maxerror);
422 tprintf("esterror=%u, status=", tx.esterror);
423 printflags(adjtimex_status, tx.status, "STA_???");
424 tprintf(", constant=%d, precision=%u, ",
425 tx.constant, tx.precision);
426 tprintf("tolerance=%d, time=", tx.tolerance);
427 tprint_timeval32(tcp, &tx.time);
428 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
429 tx.tick, tx.ppsfreq, tx.jitter);
430 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
431 tx.shift, tx.stabil, tx.jitcnt);
432 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
433 tx.calcnt, tx.errcnt, tx.stbcnt);
437 #endif /* SUPPORTED_PERSONALITIES > 1 */
440 tprint_timex(struct tcb *tcp, long addr)
444 #if SUPPORTED_PERSONALITIES > 1
445 if (current_time_t_is_compat)
446 return tprint_timex32(tcp, addr);
448 if (umove(tcp, addr, &tx) < 0)
451 #if LINUX_VERSION_CODE < 66332
452 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
453 tx.mode, tx.offset, tx.frequency);
454 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
455 tx.maxerror, tx.esterror, tx.status);
456 tprintf("time_constant=%ld, precision=%lu, ",
457 tx.time_constant, tx.precision);
458 tprintf("tolerance=%ld, time=", tx.tolerance);
459 tprint_timeval(tcp, &tx.time);
462 printflags(adjtimex_modes, tx.modes, "ADJ_???");
463 tprintf(", offset=%jd, freq=%jd, maxerror=%ju, esterror=%ju, status=",
464 (intmax_t) tx.offset, (intmax_t) tx.freq,
465 (uintmax_t) tx.maxerror, (uintmax_t) tx.esterror);
466 printflags(adjtimex_status, tx.status, "STA_???");
467 tprintf(", constant=%jd, precision=%ju, tolerance=%jd, time=",
468 (intmax_t) tx.constant, (uintmax_t) tx.precision,
469 (intmax_t) tx.tolerance);
470 tprint_timeval(tcp, &tx.time);
471 tprintf(", tick=%jd, ppsfreq=%jd, jitter=%jd",
472 (intmax_t) tx.tick, (intmax_t) tx.ppsfreq, (intmax_t) tx.jitter);
473 tprintf(", shift=%d, stabil=%jd, jitcnt=%jd",
474 tx.shift, (intmax_t) tx.stabil, (intmax_t) tx.jitcnt);
475 tprintf(", calcnt=%jd, errcnt=%jd, stbcnt=%jd",
476 (intmax_t) tx.calcnt, (intmax_t) tx.errcnt, (intmax_t) tx.stbcnt);
483 do_adjtimex(struct tcb *tcp, long addr)
487 else if (syserror(tcp) || !verbose(tcp))
488 tprintf("%#lx", addr);
489 else if (tprint_timex(tcp, addr) < 0)
493 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
500 sys_adjtimex(struct tcb *tcp)
503 return do_adjtimex(tcp, tcp->u_arg[0]);
507 #include "xlat/clockflags.h"
508 #include "xlat/clocknames.h"
511 printclockname(int clockid)
514 # include "xlat/cpuclocknames.h"
517 if ((clockid & CLOCKFD_MASK) == CLOCKFD)
518 tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
520 if(CPUCLOCK_PERTHREAD(clockid))
521 tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
523 tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
524 printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
530 printxval(clocknames, clockid, "CLOCK_???");
534 sys_clock_settime(struct tcb *tcp)
537 printclockname(tcp->u_arg[0]);
539 printtv(tcp, tcp->u_arg[1]);
545 sys_clock_gettime(struct tcb *tcp)
548 printclockname(tcp->u_arg[0]);
552 tprintf("%#lx", tcp->u_arg[1]);
554 printtv(tcp, tcp->u_arg[1]);
560 sys_clock_nanosleep(struct tcb *tcp)
563 printclockname(tcp->u_arg[0]);
565 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
567 printtv(tcp, tcp->u_arg[2]);
571 tprintf("%#lx", tcp->u_arg[3]);
573 printtv(tcp, tcp->u_arg[3]);
579 sys_clock_adjtime(struct tcb *tcp)
582 return do_adjtimex(tcp, tcp->u_arg[1]);
583 printclockname(tcp->u_arg[0]);
588 #ifndef SIGEV_THREAD_ID
589 # define SIGEV_THREAD_ID 4
591 #include "xlat/sigev_value.h"
593 #if SUPPORTED_PERSONALITIES > 1
595 printsigevent32(struct tcb *tcp, long arg)
605 int function, attribute;
610 if (umove(tcp, arg, &sev) < 0)
613 tprintf("{%#x, ", sev.sigev_value);
614 if (sev.sigev_notify == SIGEV_SIGNAL)
615 tprintf("%s, ", signame(sev.sigev_signo));
617 tprintf("%u, ", sev.sigev_signo);
618 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
620 if (sev.sigev_notify == SIGEV_THREAD_ID)
621 tprintf("{%d}", sev.un.tid);
622 else if (sev.sigev_notify == SIGEV_THREAD)
623 tprintf("{%#x, %#x}",
624 sev.un.thread.function,
625 sev.un.thread.attribute);
634 printsigevent(struct tcb *tcp, long arg)
638 #if SUPPORTED_PERSONALITIES > 1
639 if (current_wordsize == 4) {
640 printsigevent32(tcp, arg);
644 if (umove(tcp, arg, &sev) < 0)
647 tprintf("{%p, ", sev.sigev_value.sival_ptr);
648 if (sev.sigev_notify == SIGEV_SIGNAL)
649 tprintf("%s, ", signame(sev.sigev_signo));
651 tprintf("%u, ", sev.sigev_signo);
652 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
654 if (sev.sigev_notify == SIGEV_THREAD_ID)
655 #if defined(HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD)
656 /* _pad[0] is the _tid field which might not be
657 present in the userlevel definition of the
659 tprintf("{%d}", sev._sigev_un._pad[0]);
660 #elif defined(HAVE_STRUCT_SIGEVENT___PAD)
661 tprintf("{%d}", sev.__pad[0]);
663 # warning unfamiliar struct sigevent => incomplete SIGEV_THREAD_ID decoding
666 else if (sev.sigev_notify == SIGEV_THREAD)
667 tprintf("{%p, %p}", sev.sigev_notify_function,
668 sev.sigev_notify_attributes);
676 sys_timer_create(struct tcb *tcp)
679 printclockname(tcp->u_arg[0]);
681 printsigevent(tcp, tcp->u_arg[1]);
686 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
687 tprintf("%#lx", tcp->u_arg[2]);
689 tprintf("{%d}", timer_id);
695 sys_timer_settime(struct tcb *tcp)
698 tprintf("%#lx, ", tcp->u_arg[0]);
699 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
701 printitv(tcp, tcp->u_arg[2]);
705 tprintf("%#lx", tcp->u_arg[3]);
707 printitv(tcp, tcp->u_arg[3]);
713 sys_timer_gettime(struct tcb *tcp)
716 tprintf("%#lx, ", tcp->u_arg[0]);
719 tprintf("%#lx", tcp->u_arg[1]);
721 printitv(tcp, tcp->u_arg[1]);
727 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
729 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
730 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
731 rt->tm_sec, rt->tm_min, rt->tm_hour,
732 rt->tm_mday, rt->tm_mon, rt->tm_year);
734 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
735 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
741 rtc_ioctl(struct tcb *tcp, const unsigned int code, long arg)
748 if (umove(tcp, arg, &rt) < 0)
749 tprintf(", %#lx", arg);
760 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
761 tprintf(", %#lx", arg);
771 tprintf(", %lu", arg);
776 tprintf(", %lu", arg);
780 struct rtc_wkalrm wk;
781 if (umove(tcp, arg, &wk) < 0)
782 tprintf(", %#lx", arg);
784 tprintf(", {enabled=%d, pending=%d, ",
785 wk.enabled, wk.pending);
786 print_rtc(tcp, &wk.time);
793 struct rtc_wkalrm wk;
794 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
795 tprintf(", %#lx", arg);
797 tprintf(", {enabled=%d, pending=%d, ",
798 wk.enabled, wk.pending);
799 print_rtc(tcp, &wk.time);
806 tprintf(", %#lx", arg);
812 #include "xlat/timerfdflags.h"
815 sys_timerfd(struct tcb *tcp)
818 /* It does not matter that the kernel uses itimerspec. */
819 tprintf("%ld, ", tcp->u_arg[0]);
820 printclockname(tcp->u_arg[0]);
822 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
824 printitv(tcp, tcp->u_arg[3]);
830 sys_timerfd_create(struct tcb *tcp)
833 printclockname(tcp->u_arg[0]);
835 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
841 sys_timerfd_settime(struct tcb *tcp)
844 printfd(tcp, tcp->u_arg[0]);
846 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
848 printitv(tcp, tcp->u_arg[2]);
850 printitv(tcp, tcp->u_arg[3]);
856 sys_timerfd_gettime(struct tcb *tcp)
859 printfd(tcp, tcp->u_arg[0]);
861 printitv(tcp, tcp->u_arg[1]);