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.
33 #include <linux/version.h>
34 #include <sys/timex.h>
37 #define UTIME_NOW ((1l << 30) - 1l)
40 #define UTIME_OMIT ((1l << 30) - 2l)
43 #if SUPPORTED_PERSONALITIES > 1
44 # if defined X86_64 || defined X32
45 # define current_time_t_is_compat (current_personality == 1)
47 # define current_time_t_is_compat (current_wordsize == 4)
50 # define current_time_t_is_compat 0
55 u_int32_t tv_sec, tv_usec;
59 tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
61 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
65 tprint_timeval(struct tcb *tcp, const struct timeval *tv)
67 tprintf("{%ju, %ju}", (uintmax_t) tv->tv_sec, (uintmax_t) tv->tv_usec);
71 printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
73 char buf[TIMEVAL_TEXT_BUFSIZE];
74 sprinttv(buf, tcp, addr, bitness, special);
79 do_sprinttv(char *buf, const uintmax_t sec, const uintmax_t usec,
85 return stpcpy(buf, "UTIME_NOW");
87 return stpcpy(buf, "UTIME_OMIT");
90 return buf + sprintf(buf, "{%ju, %ju}", sec, usec);
94 sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
97 return stpcpy(buf, "NULL");
99 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
100 return buf + sprintf(buf, "%#lx", addr);
102 if (bitness == BITNESS_32 || current_time_t_is_compat)
106 if (umove(tcp, addr, &tv) >= 0)
107 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
111 if (umove(tcp, addr, &tv) >= 0)
112 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
115 return buf + sprintf(buf, "%#lx", addr);
119 print_timespec(struct tcb *tcp, long addr)
121 char buf[TIMESPEC_TEXT_BUFSIZE];
122 sprint_timespec(buf, tcp, addr);
127 sprint_timespec(char *buf, struct tcb *tcp, long addr)
131 else if (!verbose(tcp))
132 sprintf(buf, "%#lx", addr);
136 #if SUPPORTED_PERSONALITIES > 1
137 if (current_time_t_is_compat) {
140 rc = umove(tcp, addr, &tv);
142 sprintf(buf, "{%u, %u}",
143 tv.tv_sec, tv.tv_usec);
149 rc = umove(tcp, addr, &ts);
151 sprintf(buf, "{%ju, %ju}",
152 (uintmax_t) ts.tv_sec,
153 (uintmax_t) ts.tv_nsec);
156 strcpy(buf, "{...}");
163 printnum_long(tcp, tcp->u_arg[0], "%ld");
168 SYS_FUNC(gettimeofday)
171 printtv(tcp, tcp->u_arg[0]);
173 printtv(tcp, tcp->u_arg[1]);
179 SYS_FUNC(osf_gettimeofday)
182 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
184 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
190 SYS_FUNC(settimeofday)
192 printtv(tcp, tcp->u_arg[0]);
194 printtv(tcp, tcp->u_arg[1]);
200 SYS_FUNC(osf_settimeofday)
202 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
204 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
213 printtv(tcp, tcp->u_arg[0]);
216 printtv(tcp, tcp->u_arg[1]);
224 print_timespec(tcp, tcp->u_arg[0]);
227 /* Second (returned) timespec is only significant
228 * if syscall was interrupted. On success, we print
229 * only its address, since kernel doesn't modify it,
230 * and printing the value may show uninitialized data.
232 switch (tcp->u_error) {
234 /* Not interrupted (slept entire interval) */
235 printaddr(tcp->u_arg[1]);
240 case ERESTART_RESTARTBLOCK:
242 print_timespec(tcp, tcp->u_arg[1]);
248 #include "xlat/itimer_which.h"
251 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
253 if (bitness == BITNESS_32 || current_time_t_is_compat) {
255 struct timeval32 it_interval, it_value;
258 if (!umove_or_printaddr(tcp, addr, &itv)) {
259 tprints("{it_interval=");
260 tprint_timeval32(tcp, &itv.it_interval);
261 tprints(", it_value=");
262 tprint_timeval32(tcp, &itv.it_value);
266 struct itimerval itv;
268 if (!umove_or_printaddr(tcp, addr, &itv)) {
269 tprints("{it_interval=");
270 tprint_timeval(tcp, &itv.it_interval);
271 tprints(", it_value=");
272 tprint_timeval(tcp, &itv.it_value);
278 #define printitv(tcp, addr) \
279 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
284 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
287 printitv(tcp, tcp->u_arg[1]);
293 SYS_FUNC(osf_getitimer)
296 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
299 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
308 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
310 printitv(tcp, tcp->u_arg[1]);
313 printitv(tcp, tcp->u_arg[2]);
319 SYS_FUNC(osf_setitimer)
322 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
324 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
327 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
333 #include "xlat/adjtimex_modes.h"
334 #include "xlat/adjtimex_status.h"
335 #include "xlat/adjtimex_state.h"
337 #if SUPPORTED_PERSONALITIES > 1
339 tprint_timex32(struct tcb *tcp, long addr)
351 struct timeval32 time;
363 if (umove_or_printaddr(tcp, addr, &tx))
367 printflags(adjtimex_modes, tx.modes, "ADJ_???");
368 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
369 tx.offset, tx.freq, tx.maxerror);
370 tprintf("esterror=%u, status=", tx.esterror);
371 printflags(adjtimex_status, tx.status, "STA_???");
372 tprintf(", constant=%d, precision=%u, ",
373 tx.constant, tx.precision);
374 tprintf("tolerance=%d, time=", tx.tolerance);
375 tprint_timeval32(tcp, &tx.time);
376 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
377 tx.tick, tx.ppsfreq, tx.jitter);
378 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
379 tx.shift, tx.stabil, tx.jitcnt);
380 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
381 tx.calcnt, tx.errcnt, tx.stbcnt);
385 #endif /* SUPPORTED_PERSONALITIES > 1 */
388 tprint_timex(struct tcb *tcp, long addr)
392 #if SUPPORTED_PERSONALITIES > 1
393 if (current_time_t_is_compat)
394 return tprint_timex32(tcp, addr);
396 if (umove_or_printaddr(tcp, addr, &tx))
400 printflags(adjtimex_modes, tx.modes, "ADJ_???");
401 tprintf(", offset=%jd, freq=%jd, maxerror=%ju, esterror=%ju, status=",
402 (intmax_t) tx.offset, (intmax_t) tx.freq,
403 (uintmax_t) tx.maxerror, (uintmax_t) tx.esterror);
404 printflags(adjtimex_status, tx.status, "STA_???");
405 tprintf(", constant=%jd, precision=%ju, tolerance=%jd, time=",
406 (intmax_t) tx.constant, (uintmax_t) tx.precision,
407 (intmax_t) tx.tolerance);
408 tprint_timeval(tcp, &tx.time);
409 tprintf(", tick=%jd, ppsfreq=%jd, jitter=%jd",
410 (intmax_t) tx.tick, (intmax_t) tx.ppsfreq, (intmax_t) tx.jitter);
411 tprintf(", shift=%d, stabil=%jd, jitcnt=%jd",
412 tx.shift, (intmax_t) tx.stabil, (intmax_t) tx.jitcnt);
413 tprintf(", calcnt=%jd, errcnt=%jd, stbcnt=%jd",
414 (intmax_t) tx.calcnt, (intmax_t) tx.errcnt, (intmax_t) tx.stbcnt);
420 do_adjtimex(struct tcb *tcp, long addr)
422 if (tprint_timex(tcp, addr))
424 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
433 return do_adjtimex(tcp, tcp->u_arg[0]);
437 #include "xlat/clockflags.h"
438 #include "xlat/clocknames.h"
441 printclockname(int clockid)
444 # include "xlat/cpuclocknames.h"
447 if ((clockid & CLOCKFD_MASK) == CLOCKFD)
448 tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
450 if(CPUCLOCK_PERTHREAD(clockid))
451 tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
453 tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
454 printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
460 printxval(clocknames, clockid, "CLOCK_???");
463 SYS_FUNC(clock_settime)
465 printclockname(tcp->u_arg[0]);
467 printtv(tcp, tcp->u_arg[1]);
472 SYS_FUNC(clock_gettime)
475 printclockname(tcp->u_arg[0]);
478 printtv(tcp, tcp->u_arg[1]);
483 SYS_FUNC(clock_nanosleep)
486 printclockname(tcp->u_arg[0]);
488 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
490 printtv(tcp, tcp->u_arg[2]);
493 printtv(tcp, tcp->u_arg[3]);
498 SYS_FUNC(clock_adjtime)
501 return do_adjtimex(tcp, tcp->u_arg[1]);
502 printclockname(tcp->u_arg[0]);
507 #ifndef SIGEV_THREAD_ID
508 # define SIGEV_THREAD_ID 4
510 #include "xlat/sigev_value.h"
512 #if SUPPORTED_PERSONALITIES > 1
514 printsigevent32(struct tcb *tcp, long arg)
524 int function, attribute;
529 if (!umove_or_printaddr(tcp, arg, &sev)) {
530 tprintf("{%#x, ", sev.sigev_value);
531 if (sev.sigev_notify == SIGEV_SIGNAL)
532 tprintf("%s, ", signame(sev.sigev_signo));
534 tprintf("%u, ", sev.sigev_signo);
535 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
537 if (sev.sigev_notify == SIGEV_THREAD_ID)
538 tprintf("{%d}", sev.un.tid);
539 else if (sev.sigev_notify == SIGEV_THREAD)
540 tprintf("{%#x, %#x}",
541 sev.un.thread.function,
542 sev.un.thread.attribute);
551 printsigevent(struct tcb *tcp, long arg)
555 #if SUPPORTED_PERSONALITIES > 1
556 if (current_wordsize == 4) {
557 printsigevent32(tcp, arg);
561 if (!umove_or_printaddr(tcp, arg, &sev)) {
562 tprintf("{%p, ", sev.sigev_value.sival_ptr);
563 if (sev.sigev_notify == SIGEV_SIGNAL)
564 tprintf("%s, ", signame(sev.sigev_signo));
566 tprintf("%u, ", sev.sigev_signo);
567 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
569 if (sev.sigev_notify == SIGEV_THREAD_ID)
570 #if defined(HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD)
571 /* _pad[0] is the _tid field which might not be
572 present in the userlevel definition of the
574 tprintf("{%d}", sev._sigev_un._pad[0]);
575 #elif defined(HAVE_STRUCT_SIGEVENT___PAD)
576 tprintf("{%d}", sev.__pad[0]);
578 # warning unfamiliar struct sigevent => incomplete SIGEV_THREAD_ID decoding
581 else if (sev.sigev_notify == SIGEV_THREAD)
582 tprintf("{%p, %p}", sev.sigev_notify_function,
583 sev.sigev_notify_attributes);
590 SYS_FUNC(timer_create)
593 printclockname(tcp->u_arg[0]);
595 printsigevent(tcp, tcp->u_arg[1]);
598 printnum_int(tcp, tcp->u_arg[2], "%d");
603 SYS_FUNC(timer_settime)
606 tprintf("%d, ", (int) tcp->u_arg[0]);
607 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
609 printitv(tcp, tcp->u_arg[2]);
612 printitv(tcp, tcp->u_arg[3]);
617 SYS_FUNC(timer_gettime)
620 tprintf("%d, ", (int) tcp->u_arg[0]);
622 printitv(tcp, tcp->u_arg[1]);
627 #include "xlat/timerfdflags.h"
631 /* It does not matter that the kernel uses itimerspec. */
632 tprintf("%ld, ", tcp->u_arg[0]);
633 printclockname(tcp->u_arg[0]);
635 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
637 printitv(tcp, tcp->u_arg[3]);
642 SYS_FUNC(timerfd_create)
644 printclockname(tcp->u_arg[0]);
646 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
651 SYS_FUNC(timerfd_settime)
653 printfd(tcp, tcp->u_arg[0]);
655 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
657 printitv(tcp, tcp->u_arg[2]);
659 printitv(tcp, tcp->u_arg[3]);
664 SYS_FUNC(timerfd_gettime)
667 printfd(tcp, tcp->u_arg[0]);
670 printitv(tcp, tcp->u_arg[1]);