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)
46 u_int32_t tv_sec, tv_usec;
50 tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
52 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
56 tprint_timeval(struct tcb *tcp, const struct timeval *tv)
59 (unsigned long) tv->tv_sec, (unsigned long) tv->tv_usec);
63 printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
65 char buf[TIMEVAL_TEXT_BUFSIZE];
66 sprinttv(buf, tcp, addr, bitness, special);
71 do_sprinttv(char *buf, const unsigned long sec, const unsigned long usec,
77 return stpcpy(buf, "UTIME_NOW");
79 return stpcpy(buf, "UTIME_OMIT");
82 return buf + sprintf(buf, "{%lu, %lu}", sec, usec);
86 sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
89 return stpcpy(buf, "NULL");
92 return buf + sprintf(buf, "%#lx", addr);
94 if (bitness == BITNESS_32
95 #if SUPPORTED_PERSONALITIES > 1
96 || current_wordsize == 4
102 if (umove(tcp, addr, &tv) >= 0)
103 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
107 if (umove(tcp, addr, &tv) >= 0)
108 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
111 return stpcpy(buf, "{...}");
115 print_timespec(struct tcb *tcp, long addr)
117 char buf[TIMESPEC_TEXT_BUFSIZE];
118 sprint_timespec(buf, tcp, addr);
123 sprint_timespec(char *buf, struct tcb *tcp, long addr)
127 else if (!verbose(tcp))
128 sprintf(buf, "%#lx", addr);
132 #if SUPPORTED_PERSONALITIES > 1
133 if (current_wordsize == 4) {
136 rc = umove(tcp, addr, &tv);
138 sprintf(buf, "{%u, %u}",
139 tv.tv_sec, tv.tv_usec);
145 rc = umove(tcp, addr, &ts);
147 sprintf(buf, "{%lu, %lu}",
148 (unsigned long) ts.tv_sec,
149 (unsigned long) ts.tv_nsec);
152 strcpy(buf, "{...}");
157 sys_time(struct tcb *tcp)
160 printnum(tcp, tcp->u_arg[0], "%ld");
166 sys_gettimeofday(struct tcb *tcp)
170 tprintf("%#lx, %#lx",
171 tcp->u_arg[0], tcp->u_arg[1]);
174 printtv(tcp, tcp->u_arg[0]);
176 printtv(tcp, tcp->u_arg[1]);
183 sys_osf_gettimeofday(struct tcb *tcp)
187 tprintf("%#lx, %#lx", tcp->u_arg[0], tcp->u_arg[1]);
190 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
192 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
199 sys_settimeofday(struct tcb *tcp)
202 printtv(tcp, tcp->u_arg[0]);
204 printtv(tcp, tcp->u_arg[1]);
211 sys_osf_settimeofday(struct tcb *tcp)
214 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
216 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
223 sys_adjtime(struct tcb *tcp)
226 printtv(tcp, tcp->u_arg[0]);
230 tprintf("%#lx", tcp->u_arg[1]);
232 printtv(tcp, tcp->u_arg[1]);
238 sys_nanosleep(struct tcb *tcp)
241 print_timespec(tcp, tcp->u_arg[0]);
244 /* Second (returned) timespec is only significant
245 * if syscall was interrupted. On success, we print
246 * only its address, since kernel doesn't modify it,
247 * and printing the value may show uninitialized data.
249 switch (tcp->u_error) {
251 /* Not interrupted (slept entire interval) */
253 tprintf("%#lx", tcp->u_arg[1]);
256 /* Fall through: print_timespec(NULL) prints "NULL" */
260 case ERESTART_RESTARTBLOCK:
262 print_timespec(tcp, tcp->u_arg[1]);
268 #include "xlat/itimer_which.h"
271 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
275 else if (!verbose(tcp))
276 tprintf("%#lx", addr);
280 if (bitness == BITNESS_32
281 #if SUPPORTED_PERSONALITIES > 1
282 || current_wordsize == 4
287 struct timeval32 it_interval, it_value;
290 rc = umove(tcp, addr, &itv);
292 tprints("{it_interval=");
293 tprint_timeval32(tcp, &itv.it_interval);
294 tprints(", it_value=");
295 tprint_timeval32(tcp, &itv.it_value);
299 struct itimerval itv;
301 rc = umove(tcp, addr, &itv);
303 tprints("{it_interval=");
304 tprint_timeval(tcp, &itv.it_interval);
305 tprints(", it_value=");
306 tprint_timeval(tcp, &itv.it_value);
315 #define printitv(tcp, addr) \
316 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
319 sys_getitimer(struct tcb *tcp)
322 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
326 tprintf("%#lx", tcp->u_arg[1]);
328 printitv(tcp, tcp->u_arg[1]);
335 sys_osf_getitimer(struct tcb *tcp)
338 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
342 tprintf("%#lx", tcp->u_arg[1]);
344 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
351 sys_setitimer(struct tcb *tcp)
354 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
356 printitv(tcp, tcp->u_arg[1]);
360 tprintf("%#lx", tcp->u_arg[2]);
362 printitv(tcp, tcp->u_arg[2]);
369 sys_osf_setitimer(struct tcb *tcp)
372 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
374 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
378 tprintf("%#lx", tcp->u_arg[2]);
380 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
386 #include "xlat/adjtimex_modes.h"
387 #include "xlat/adjtimex_status.h"
388 #include "xlat/adjtimex_state.h"
390 #if SUPPORTED_PERSONALITIES > 1
392 tprint_timex32(struct tcb *tcp, long addr)
404 struct timeval32 time;
416 if (umove(tcp, addr, &tx) < 0)
420 printflags(adjtimex_modes, tx.modes, "ADJ_???");
421 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
422 tx.offset, tx.freq, tx.maxerror);
423 tprintf("esterror=%u, status=", tx.esterror);
424 printflags(adjtimex_status, tx.status, "STA_???");
425 tprintf(", constant=%d, precision=%u, ",
426 tx.constant, tx.precision);
427 tprintf("tolerance=%d, time=", tx.tolerance);
428 tprint_timeval32(tcp, &tx.time);
429 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
430 tx.tick, tx.ppsfreq, tx.jitter);
431 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
432 tx.shift, tx.stabil, tx.jitcnt);
433 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
434 tx.calcnt, tx.errcnt, tx.stbcnt);
438 #endif /* SUPPORTED_PERSONALITIES > 1 */
441 tprint_timex(struct tcb *tcp, long addr)
445 #if SUPPORTED_PERSONALITIES > 1
446 if (current_wordsize == 4)
447 return tprint_timex32(tcp, addr);
449 if (umove(tcp, addr, &tx) < 0)
452 #if LINUX_VERSION_CODE < 66332
453 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
454 tx.mode, tx.offset, tx.frequency);
455 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
456 tx.maxerror, tx.esterror, tx.status);
457 tprintf("time_constant=%ld, precision=%lu, ",
458 tx.time_constant, tx.precision);
459 tprintf("tolerance=%ld, time=", tx.tolerance);
460 tprint_timeval(tcp, &tx.time);
463 printflags(adjtimex_modes, tx.modes, "ADJ_???");
464 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
465 (long) tx.offset, (long) tx.freq, (long) tx.maxerror);
466 tprintf("esterror=%lu, status=", (long) tx.esterror);
467 printflags(adjtimex_status, tx.status, "STA_???");
468 tprintf(", constant=%ld, precision=%lu, ",
469 (long) tx.constant, (long) tx.precision);
470 tprintf("tolerance=%ld, time=", (long) tx.tolerance);
471 tprint_timeval(tcp, &tx.time);
472 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
473 (long) tx.tick, (long) tx.ppsfreq, (long) tx.jitter);
474 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
475 tx.shift, (long) tx.stabil, (long) tx.jitcnt);
476 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
477 (long) tx.calcnt, (long) tx.errcnt, (long) tx.stbcnt);
484 do_adjtimex(struct tcb *tcp, long addr)
488 else if (syserror(tcp) || !verbose(tcp))
489 tprintf("%#lx", addr);
490 else if (tprint_timex(tcp, addr) < 0)
494 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
501 sys_adjtimex(struct tcb *tcp)
504 return do_adjtimex(tcp, tcp->u_arg[0]);
508 #include "xlat/clockflags.h"
509 #include "xlat/clocknames.h"
512 printclockname(int clockid)
515 # include "xlat/cpuclocknames.h"
518 if ((clockid & CLOCKFD_MASK) == CLOCKFD)
519 tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
521 if(CPUCLOCK_PERTHREAD(clockid))
522 tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
524 tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
525 printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
531 printxval(clocknames, clockid, "CLOCK_???");
535 sys_clock_settime(struct tcb *tcp)
538 printclockname(tcp->u_arg[0]);
540 printtv(tcp, tcp->u_arg[1]);
546 sys_clock_gettime(struct tcb *tcp)
549 printclockname(tcp->u_arg[0]);
553 tprintf("%#lx", tcp->u_arg[1]);
555 printtv(tcp, tcp->u_arg[1]);
561 sys_clock_nanosleep(struct tcb *tcp)
564 printclockname(tcp->u_arg[0]);
566 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
568 printtv(tcp, tcp->u_arg[2]);
572 tprintf("%#lx", tcp->u_arg[3]);
574 printtv(tcp, tcp->u_arg[3]);
580 sys_clock_adjtime(struct tcb *tcp)
583 return do_adjtimex(tcp, tcp->u_arg[1]);
584 printclockname(tcp->u_arg[0]);
589 #ifndef SIGEV_THREAD_ID
590 # define SIGEV_THREAD_ID 4
592 #include "xlat/sigev_value.h"
594 #if SUPPORTED_PERSONALITIES > 1
596 printsigevent32(struct tcb *tcp, long arg)
606 int function, attribute;
611 if (umove(tcp, arg, &sev) < 0)
614 tprintf("{%#x, ", sev.sigev_value);
615 if (sev.sigev_notify == SIGEV_SIGNAL)
616 tprintf("%s, ", signame(sev.sigev_signo));
618 tprintf("%u, ", sev.sigev_signo);
619 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
621 if (sev.sigev_notify == SIGEV_THREAD_ID)
622 tprintf("{%d}", sev.un.tid);
623 else if (sev.sigev_notify == SIGEV_THREAD)
624 tprintf("{%#x, %#x}",
625 sev.un.thread.function,
626 sev.un.thread.attribute);
635 printsigevent(struct tcb *tcp, long arg)
639 #if SUPPORTED_PERSONALITIES > 1
640 if (current_wordsize == 4) {
641 printsigevent32(tcp, arg);
645 if (umove(tcp, arg, &sev) < 0)
648 tprintf("{%p, ", sev.sigev_value.sival_ptr);
649 if (sev.sigev_notify == SIGEV_SIGNAL)
650 tprintf("%s, ", signame(sev.sigev_signo));
652 tprintf("%u, ", sev.sigev_signo);
653 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
655 if (sev.sigev_notify == SIGEV_THREAD_ID)
656 #if defined(HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD)
657 /* _pad[0] is the _tid field which might not be
658 present in the userlevel definition of the
660 tprintf("{%d}", sev._sigev_un._pad[0]);
661 #elif defined(HAVE_STRUCT_SIGEVENT___PAD)
662 tprintf("{%d}", sev.__pad[0]);
664 # warning unfamiliar struct sigevent => incomplete SIGEV_THREAD_ID decoding
667 else if (sev.sigev_notify == SIGEV_THREAD)
668 tprintf("{%p, %p}", sev.sigev_notify_function,
669 sev.sigev_notify_attributes);
677 sys_timer_create(struct tcb *tcp)
680 printclockname(tcp->u_arg[0]);
682 printsigevent(tcp, tcp->u_arg[1]);
687 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
688 tprintf("%#lx", tcp->u_arg[2]);
690 tprintf("{%d}", timer_id);
696 sys_timer_settime(struct tcb *tcp)
699 tprintf("%#lx, ", tcp->u_arg[0]);
700 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
702 printitv(tcp, tcp->u_arg[2]);
706 tprintf("%#lx", tcp->u_arg[3]);
708 printitv(tcp, tcp->u_arg[3]);
714 sys_timer_gettime(struct tcb *tcp)
717 tprintf("%#lx, ", tcp->u_arg[0]);
720 tprintf("%#lx", tcp->u_arg[1]);
722 printitv(tcp, tcp->u_arg[1]);
728 print_rtc(struct tcb *tcp, const struct rtc_time *rt)
730 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
731 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
732 rt->tm_sec, rt->tm_min, rt->tm_hour,
733 rt->tm_mday, rt->tm_mon, rt->tm_year);
735 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
736 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
742 rtc_ioctl(struct tcb *tcp, const unsigned int code, long arg)
749 if (umove(tcp, arg, &rt) < 0)
750 tprintf(", %#lx", arg);
761 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
762 tprintf(", %#lx", arg);
772 tprintf(", %lu", arg);
777 tprintf(", %lu", arg);
781 struct rtc_wkalrm wk;
782 if (umove(tcp, arg, &wk) < 0)
783 tprintf(", %#lx", arg);
785 tprintf(", {enabled=%d, pending=%d, ",
786 wk.enabled, wk.pending);
787 print_rtc(tcp, &wk.time);
794 struct rtc_wkalrm wk;
795 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
796 tprintf(", %#lx", arg);
798 tprintf(", {enabled=%d, pending=%d, ",
799 wk.enabled, wk.pending);
800 print_rtc(tcp, &wk.time);
807 tprintf(", %#lx", arg);
813 #include "xlat/timerfdflags.h"
816 sys_timerfd(struct tcb *tcp)
819 /* It does not matter that the kernel uses itimerspec. */
820 tprintf("%ld, ", tcp->u_arg[0]);
821 printclockname(tcp->u_arg[0]);
823 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
825 printitv(tcp, tcp->u_arg[3]);
831 sys_timerfd_create(struct tcb *tcp)
834 printclockname(tcp->u_arg[0]);
836 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
842 sys_timerfd_settime(struct tcb *tcp)
845 printfd(tcp, tcp->u_arg[0]);
847 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
849 printitv(tcp, tcp->u_arg[2]);
851 printitv(tcp, tcp->u_arg[3]);
857 sys_timerfd_gettime(struct tcb *tcp)
860 printfd(tcp, tcp->u_arg[0]);
862 printitv(tcp, tcp->u_arg[1]);