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 #include "xlat/itimer_which.h"
285 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
289 else if (!verbose(tcp))
290 tprintf("%#lx", addr);
294 if (bitness == BITNESS_32
295 #if SUPPORTED_PERSONALITIES > 1
296 || current_wordsize == 4
301 struct timeval32 it_interval, it_value;
304 rc = umove(tcp, addr, &itv);
306 tprints("{it_interval=");
307 tprint_timeval32(tcp, &itv.it_interval);
308 tprints(", it_value=");
309 tprint_timeval32(tcp, &itv.it_value);
313 struct itimerval itv;
315 rc = umove(tcp, addr, &itv);
317 tprints("{it_interval=");
318 tprint_timeval(tcp, &itv.it_interval);
319 tprints(", it_value=");
320 tprint_timeval(tcp, &itv.it_value);
329 #define printitv(tcp, addr) \
330 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
333 sys_getitimer(struct tcb *tcp)
336 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
340 tprintf("%#lx", tcp->u_arg[1]);
342 printitv(tcp, tcp->u_arg[1]);
349 sys_osf_getitimer(struct tcb *tcp)
352 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
356 tprintf("%#lx", tcp->u_arg[1]);
358 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
365 sys_setitimer(struct tcb *tcp)
368 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
370 printitv(tcp, tcp->u_arg[1]);
374 tprintf("%#lx", tcp->u_arg[2]);
376 printitv(tcp, tcp->u_arg[2]);
383 sys_osf_setitimer(struct tcb *tcp)
386 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
388 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
392 tprintf("%#lx", tcp->u_arg[2]);
394 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
400 #include "xlat/adjtimex_modes.h"
402 #include "xlat/adjtimex_status.h"
404 #include "xlat/adjtimex_state.h"
406 #if SUPPORTED_PERSONALITIES > 1
408 tprint_timex32(struct tcb *tcp, long addr)
420 struct timeval32 time;
432 if (umove(tcp, addr, &tx) < 0)
436 printflags(adjtimex_modes, tx.modes, "ADJ_???");
437 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
438 tx.offset, tx.freq, tx.maxerror);
439 tprintf("esterror=%u, status=", tx.esterror);
440 printflags(adjtimex_status, tx.status, "STA_???");
441 tprintf(", constant=%d, precision=%u, ",
442 tx.constant, tx.precision);
443 tprintf("tolerance=%d, time=", tx.tolerance);
444 tprint_timeval32(tcp, &tx.time);
445 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
446 tx.tick, tx.ppsfreq, tx.jitter);
447 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
448 tx.shift, tx.stabil, tx.jitcnt);
449 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
450 tx.calcnt, tx.errcnt, tx.stbcnt);
454 #endif /* SUPPORTED_PERSONALITIES > 1 */
457 tprint_timex(struct tcb *tcp, long addr)
461 #if SUPPORTED_PERSONALITIES > 1
462 if (current_wordsize == 4)
463 return tprint_timex32(tcp, addr);
465 if (umove(tcp, addr, &tx) < 0)
468 #if LINUX_VERSION_CODE < 66332
469 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
470 tx.mode, tx.offset, tx.frequency);
471 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
472 tx.maxerror, tx.esterror, tx.status);
473 tprintf("time_constant=%ld, precision=%lu, ",
474 tx.time_constant, tx.precision);
475 tprintf("tolerance=%ld, time=", tx.tolerance);
476 tprint_timeval(tcp, &tx.time);
479 printflags(adjtimex_modes, tx.modes, "ADJ_???");
480 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
481 (long) tx.offset, (long) tx.freq, (long) tx.maxerror);
482 tprintf("esterror=%lu, status=", (long) tx.esterror);
483 printflags(adjtimex_status, tx.status, "STA_???");
484 tprintf(", constant=%ld, precision=%lu, ",
485 (long) tx.constant, (long) tx.precision);
486 tprintf("tolerance=%ld, time=", (long) tx.tolerance);
487 tprint_timeval(tcp, &tx.time);
488 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
489 (long) tx.tick, (long) tx.ppsfreq, (long) tx.jitter);
490 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
491 tx.shift, (long) tx.stabil, (long) tx.jitcnt);
492 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
493 (long) tx.calcnt, (long) tx.errcnt, (long) tx.stbcnt);
500 do_adjtimex(struct tcb *tcp, long addr)
504 else if (syserror(tcp) || !verbose(tcp))
505 tprintf("%#lx", addr);
506 else if (tprint_timex(tcp, addr) < 0)
510 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
517 sys_adjtimex(struct tcb *tcp)
520 return do_adjtimex(tcp, tcp->u_arg[0]);
524 #include "xlat/clockflags.h"
526 #include "xlat/clocknames.h"
529 #include "xlat/cpuclocknames.h"
533 printclockname(int clockid)
537 if ((clockid & CLOCKFD_MASK) == CLOCKFD)
538 tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
540 if(CPUCLOCK_PERTHREAD(clockid))
541 tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
543 tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
544 printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
550 printxval(clocknames, clockid, "CLOCK_???");
554 sys_clock_settime(struct tcb *tcp)
557 printclockname(tcp->u_arg[0]);
559 printtv(tcp, tcp->u_arg[1]);
565 sys_clock_gettime(struct tcb *tcp)
568 printclockname(tcp->u_arg[0]);
572 tprintf("%#lx", tcp->u_arg[1]);
574 printtv(tcp, tcp->u_arg[1]);
580 sys_clock_nanosleep(struct tcb *tcp)
583 printclockname(tcp->u_arg[0]);
585 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
587 printtv(tcp, tcp->u_arg[2]);
591 tprintf("%#lx", tcp->u_arg[3]);
593 printtv(tcp, tcp->u_arg[3]);
599 sys_clock_adjtime(struct tcb *tcp)
602 return do_adjtimex(tcp, tcp->u_arg[1]);
603 printclockname(tcp->u_arg[0]);
608 #ifndef SIGEV_THREAD_ID
609 # define SIGEV_THREAD_ID 4
611 #include "xlat/sigev_value.h"
613 #if SUPPORTED_PERSONALITIES > 1
615 printsigevent32(struct tcb *tcp, long arg)
625 int function, attribute;
630 if (umove(tcp, arg, &sev) < 0)
633 tprintf("{%#x, ", sev.sigev_value);
634 if (sev.sigev_notify == SIGEV_SIGNAL)
635 tprintf("%s, ", signame(sev.sigev_signo));
637 tprintf("%u, ", sev.sigev_signo);
638 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
640 if (sev.sigev_notify == SIGEV_THREAD_ID)
641 tprintf("{%d}", sev.un.tid);
642 else if (sev.sigev_notify == SIGEV_THREAD)
643 tprintf("{%#x, %#x}",
644 sev.un.thread.function,
645 sev.un.thread.attribute);
654 printsigevent(struct tcb *tcp, long arg)
658 #if SUPPORTED_PERSONALITIES > 1
659 if (current_wordsize == 4) {
660 printsigevent32(tcp, arg);
664 if (umove(tcp, arg, &sev) < 0)
667 tprintf("{%p, ", sev.sigev_value.sival_ptr);
668 if (sev.sigev_notify == SIGEV_SIGNAL)
669 tprintf("%s, ", signame(sev.sigev_signo));
671 tprintf("%u, ", sev.sigev_signo);
672 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
674 if (sev.sigev_notify == SIGEV_THREAD_ID)
675 #if defined(HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD)
676 /* _pad[0] is the _tid field which might not be
677 present in the userlevel definition of the
679 tprintf("{%d}", sev._sigev_un._pad[0]);
680 #elif defined(HAVE_STRUCT_SIGEVENT___PAD)
681 tprintf("{%d}", sev.__pad[0]);
683 # warning unfamiliar struct sigevent => incomplete SIGEV_THREAD_ID decoding
686 else if (sev.sigev_notify == SIGEV_THREAD)
687 tprintf("{%p, %p}", sev.sigev_notify_function,
688 sev.sigev_notify_attributes);
696 sys_timer_create(struct tcb *tcp)
699 printclockname(tcp->u_arg[0]);
701 printsigevent(tcp, tcp->u_arg[1]);
706 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
707 tprintf("%#lx", tcp->u_arg[2]);
709 tprintf("{%d}", timer_id);
715 sys_timer_settime(struct tcb *tcp)
718 tprintf("%#lx, ", tcp->u_arg[0]);
719 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
721 printitv(tcp, tcp->u_arg[2]);
725 tprintf("%#lx", tcp->u_arg[3]);
727 printitv(tcp, tcp->u_arg[3]);
733 sys_timer_gettime(struct tcb *tcp)
736 tprintf("%#lx, ", tcp->u_arg[0]);
739 tprintf("%#lx", tcp->u_arg[1]);
741 printitv(tcp, tcp->u_arg[1]);
747 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
749 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
750 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
751 rt->tm_sec, rt->tm_min, rt->tm_hour,
752 rt->tm_mday, rt->tm_mon, rt->tm_year);
754 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
755 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
761 rtc_ioctl(struct tcb *tcp, long code, long arg)
768 if (umove(tcp, arg, &rt) < 0)
769 tprintf(", %#lx", arg);
780 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
781 tprintf(", %#lx", arg);
791 tprintf(", %lu", arg);
796 tprintf(", %lu", arg);
800 struct rtc_wkalrm wk;
801 if (umove(tcp, arg, &wk) < 0)
802 tprintf(", %#lx", arg);
804 tprintf(", {enabled=%d, pending=%d, ",
805 wk.enabled, wk.pending);
806 print_rtc(tcp, &wk.time);
813 struct rtc_wkalrm wk;
814 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
815 tprintf(", %#lx", arg);
817 tprintf(", {enabled=%d, pending=%d, ",
818 wk.enabled, wk.pending);
819 print_rtc(tcp, &wk.time);
826 tprintf(", %#lx", arg);
832 #ifndef TFD_TIMER_ABSTIME
833 #define TFD_TIMER_ABSTIME (1 << 0)
836 #include "xlat/timerfdflags.h"
839 sys_timerfd(struct tcb *tcp)
842 /* It does not matter that the kernel uses itimerspec. */
843 tprintf("%ld, ", tcp->u_arg[0]);
844 printclockname(tcp->u_arg[0]);
846 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
848 printitv(tcp, tcp->u_arg[3]);
854 sys_timerfd_create(struct tcb *tcp)
857 printclockname(tcp->u_arg[0]);
859 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
865 sys_timerfd_settime(struct tcb *tcp)
868 printfd(tcp, tcp->u_arg[0]);
870 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
872 printitv(tcp, tcp->u_arg[2]);
874 printitv(tcp, tcp->u_arg[3]);
880 sys_timerfd_gettime(struct tcb *tcp)
883 printfd(tcp, tcp->u_arg[0]);
885 printitv(tcp, tcp->u_arg[1]);