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>
36 #define UTIME_NOW ((1l << 30) - 1l)
39 #define UTIME_OMIT ((1l << 30) - 2l)
42 #if SUPPORTED_PERSONALITIES > 1
43 # if defined X86_64 || defined X32
44 # define current_time_t_is_compat (current_personality == 1)
46 # define current_time_t_is_compat (current_wordsize == 4)
49 # define current_time_t_is_compat 0
54 u_int32_t tv_sec, tv_usec;
58 tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
60 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
64 tprint_timeval(struct tcb *tcp, const struct timeval *tv)
66 tprintf("{%ju, %ju}", (uintmax_t) tv->tv_sec, (uintmax_t) tv->tv_usec);
70 printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
72 char buf[TIMEVAL_TEXT_BUFSIZE];
73 sprinttv(buf, tcp, addr, bitness, special);
78 do_sprinttv(char *buf, const uintmax_t sec, const uintmax_t usec,
84 return stpcpy(buf, "UTIME_NOW");
86 return stpcpy(buf, "UTIME_OMIT");
89 return buf + sprintf(buf, "{%ju, %ju}", sec, usec);
93 sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
96 return stpcpy(buf, "NULL");
98 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
99 return buf + sprintf(buf, "%#lx", addr);
101 if (bitness == BITNESS_32 || current_time_t_is_compat)
105 if (umove(tcp, addr, &tv) >= 0)
106 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
110 if (umove(tcp, addr, &tv) >= 0)
111 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
114 return buf + sprintf(buf, "%#lx", addr);
118 print_timespec(struct tcb *tcp, long addr)
120 char buf[TIMESPEC_TEXT_BUFSIZE];
121 sprint_timespec(buf, tcp, addr);
126 sprint_timespec(char *buf, struct tcb *tcp, long addr)
130 else if (!verbose(tcp))
131 sprintf(buf, "%#lx", addr);
135 #if SUPPORTED_PERSONALITIES > 1
136 if (current_time_t_is_compat) {
139 rc = umove(tcp, addr, &tv);
141 sprintf(buf, "{%u, %u}",
142 tv.tv_sec, tv.tv_usec);
148 rc = umove(tcp, addr, &ts);
150 sprintf(buf, "{%ju, %ju}",
151 (uintmax_t) ts.tv_sec,
152 (uintmax_t) ts.tv_nsec);
155 strcpy(buf, "{...}");
162 printnum_long(tcp, tcp->u_arg[0], "%ld");
167 SYS_FUNC(gettimeofday)
170 printtv(tcp, tcp->u_arg[0]);
172 printtv(tcp, tcp->u_arg[1]);
178 SYS_FUNC(osf_gettimeofday)
181 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
183 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
189 SYS_FUNC(settimeofday)
192 printtv(tcp, tcp->u_arg[0]);
194 printtv(tcp, tcp->u_arg[1]);
200 SYS_FUNC(osf_settimeofday)
203 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
205 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
214 printtv(tcp, tcp->u_arg[0]);
217 printtv(tcp, tcp->u_arg[1]);
225 print_timespec(tcp, tcp->u_arg[0]);
228 /* Second (returned) timespec is only significant
229 * if syscall was interrupted. On success, we print
230 * only its address, since kernel doesn't modify it,
231 * and printing the value may show uninitialized data.
233 switch (tcp->u_error) {
235 /* Not interrupted (slept entire interval) */
237 tprintf("%#lx", tcp->u_arg[1]);
240 /* Fall through: print_timespec(NULL) prints "NULL" */
244 case ERESTART_RESTARTBLOCK:
246 print_timespec(tcp, tcp->u_arg[1]);
252 #include "xlat/itimer_which.h"
255 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
259 else if (!verbose(tcp))
260 tprintf("%#lx", addr);
264 if (bitness == BITNESS_32 || current_time_t_is_compat) {
266 struct timeval32 it_interval, it_value;
269 rc = umove(tcp, addr, &itv);
271 tprints("{it_interval=");
272 tprint_timeval32(tcp, &itv.it_interval);
273 tprints(", it_value=");
274 tprint_timeval32(tcp, &itv.it_value);
278 struct itimerval itv;
280 rc = umove(tcp, addr, &itv);
282 tprints("{it_interval=");
283 tprint_timeval(tcp, &itv.it_interval);
284 tprints(", it_value=");
285 tprint_timeval(tcp, &itv.it_value);
294 #define printitv(tcp, addr) \
295 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
300 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
304 tprintf("%#lx", tcp->u_arg[1]);
306 printitv(tcp, tcp->u_arg[1]);
312 SYS_FUNC(osf_getitimer)
315 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
319 tprintf("%#lx", tcp->u_arg[1]);
321 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
330 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
332 printitv(tcp, tcp->u_arg[1]);
336 tprintf("%#lx", tcp->u_arg[2]);
338 printitv(tcp, tcp->u_arg[2]);
344 SYS_FUNC(osf_setitimer)
347 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
349 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
353 tprintf("%#lx", tcp->u_arg[2]);
355 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
361 #include "xlat/adjtimex_modes.h"
362 #include "xlat/adjtimex_status.h"
363 #include "xlat/adjtimex_state.h"
365 #if SUPPORTED_PERSONALITIES > 1
367 tprint_timex32(struct tcb *tcp, long addr)
379 struct timeval32 time;
391 if (umove(tcp, addr, &tx) < 0)
395 printflags(adjtimex_modes, tx.modes, "ADJ_???");
396 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
397 tx.offset, tx.freq, tx.maxerror);
398 tprintf("esterror=%u, status=", tx.esterror);
399 printflags(adjtimex_status, tx.status, "STA_???");
400 tprintf(", constant=%d, precision=%u, ",
401 tx.constant, tx.precision);
402 tprintf("tolerance=%d, time=", tx.tolerance);
403 tprint_timeval32(tcp, &tx.time);
404 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
405 tx.tick, tx.ppsfreq, tx.jitter);
406 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
407 tx.shift, tx.stabil, tx.jitcnt);
408 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
409 tx.calcnt, tx.errcnt, tx.stbcnt);
413 #endif /* SUPPORTED_PERSONALITIES > 1 */
416 tprint_timex(struct tcb *tcp, long addr)
420 #if SUPPORTED_PERSONALITIES > 1
421 if (current_time_t_is_compat)
422 return tprint_timex32(tcp, addr);
424 if (umove(tcp, addr, &tx) < 0)
427 #if LINUX_VERSION_CODE < 66332
428 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
429 tx.mode, tx.offset, tx.frequency);
430 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
431 tx.maxerror, tx.esterror, tx.status);
432 tprintf("time_constant=%ld, precision=%lu, ",
433 tx.time_constant, tx.precision);
434 tprintf("tolerance=%ld, time=", tx.tolerance);
435 tprint_timeval(tcp, &tx.time);
438 printflags(adjtimex_modes, tx.modes, "ADJ_???");
439 tprintf(", offset=%jd, freq=%jd, maxerror=%ju, esterror=%ju, status=",
440 (intmax_t) tx.offset, (intmax_t) tx.freq,
441 (uintmax_t) tx.maxerror, (uintmax_t) tx.esterror);
442 printflags(adjtimex_status, tx.status, "STA_???");
443 tprintf(", constant=%jd, precision=%ju, tolerance=%jd, time=",
444 (intmax_t) tx.constant, (uintmax_t) tx.precision,
445 (intmax_t) tx.tolerance);
446 tprint_timeval(tcp, &tx.time);
447 tprintf(", tick=%jd, ppsfreq=%jd, jitter=%jd",
448 (intmax_t) tx.tick, (intmax_t) tx.ppsfreq, (intmax_t) tx.jitter);
449 tprintf(", shift=%d, stabil=%jd, jitcnt=%jd",
450 tx.shift, (intmax_t) tx.stabil, (intmax_t) tx.jitcnt);
451 tprintf(", calcnt=%jd, errcnt=%jd, stbcnt=%jd",
452 (intmax_t) tx.calcnt, (intmax_t) tx.errcnt, (intmax_t) tx.stbcnt);
459 do_adjtimex(struct tcb *tcp, long addr)
463 else if (syserror(tcp) || !verbose(tcp))
464 tprintf("%#lx", addr);
465 else if (tprint_timex(tcp, addr) < 0)
469 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
478 return do_adjtimex(tcp, tcp->u_arg[0]);
482 #include "xlat/clockflags.h"
483 #include "xlat/clocknames.h"
486 printclockname(int clockid)
489 # include "xlat/cpuclocknames.h"
492 if ((clockid & CLOCKFD_MASK) == CLOCKFD)
493 tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
495 if(CPUCLOCK_PERTHREAD(clockid))
496 tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
498 tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
499 printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
505 printxval(clocknames, clockid, "CLOCK_???");
508 SYS_FUNC(clock_settime)
511 printclockname(tcp->u_arg[0]);
513 printtv(tcp, tcp->u_arg[1]);
518 SYS_FUNC(clock_gettime)
521 printclockname(tcp->u_arg[0]);
524 printtv(tcp, tcp->u_arg[1]);
529 SYS_FUNC(clock_nanosleep)
532 printclockname(tcp->u_arg[0]);
534 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
536 printtv(tcp, tcp->u_arg[2]);
539 printtv(tcp, tcp->u_arg[3]);
544 SYS_FUNC(clock_adjtime)
547 return do_adjtimex(tcp, tcp->u_arg[1]);
548 printclockname(tcp->u_arg[0]);
553 #ifndef SIGEV_THREAD_ID
554 # define SIGEV_THREAD_ID 4
556 #include "xlat/sigev_value.h"
558 #if SUPPORTED_PERSONALITIES > 1
560 printsigevent32(struct tcb *tcp, long arg)
570 int function, attribute;
575 if (umove(tcp, arg, &sev) < 0)
578 tprintf("{%#x, ", sev.sigev_value);
579 if (sev.sigev_notify == SIGEV_SIGNAL)
580 tprintf("%s, ", signame(sev.sigev_signo));
582 tprintf("%u, ", sev.sigev_signo);
583 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
585 if (sev.sigev_notify == SIGEV_THREAD_ID)
586 tprintf("{%d}", sev.un.tid);
587 else if (sev.sigev_notify == SIGEV_THREAD)
588 tprintf("{%#x, %#x}",
589 sev.un.thread.function,
590 sev.un.thread.attribute);
599 printsigevent(struct tcb *tcp, long arg)
603 #if SUPPORTED_PERSONALITIES > 1
604 if (current_wordsize == 4) {
605 printsigevent32(tcp, arg);
609 if (umove(tcp, arg, &sev) < 0)
612 tprintf("{%p, ", sev.sigev_value.sival_ptr);
613 if (sev.sigev_notify == SIGEV_SIGNAL)
614 tprintf("%s, ", signame(sev.sigev_signo));
616 tprintf("%u, ", sev.sigev_signo);
617 printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
619 if (sev.sigev_notify == SIGEV_THREAD_ID)
620 #if defined(HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD)
621 /* _pad[0] is the _tid field which might not be
622 present in the userlevel definition of the
624 tprintf("{%d}", sev._sigev_un._pad[0]);
625 #elif defined(HAVE_STRUCT_SIGEVENT___PAD)
626 tprintf("{%d}", sev.__pad[0]);
628 # warning unfamiliar struct sigevent => incomplete SIGEV_THREAD_ID decoding
631 else if (sev.sigev_notify == SIGEV_THREAD)
632 tprintf("{%p, %p}", sev.sigev_notify_function,
633 sev.sigev_notify_attributes);
640 SYS_FUNC(timer_create)
643 printclockname(tcp->u_arg[0]);
645 printsigevent(tcp, tcp->u_arg[1]);
650 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &timer_id) < 0)
651 tprintf("%#lx", tcp->u_arg[2]);
653 tprintf("{%d}", timer_id);
658 SYS_FUNC(timer_settime)
661 tprintf("%#lx, ", tcp->u_arg[0]);
662 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
664 printitv(tcp, tcp->u_arg[2]);
668 tprintf("%#lx", tcp->u_arg[3]);
670 printitv(tcp, tcp->u_arg[3]);
675 SYS_FUNC(timer_gettime)
678 tprintf("%#lx, ", tcp->u_arg[0]);
681 tprintf("%#lx", tcp->u_arg[1]);
683 printitv(tcp, tcp->u_arg[1]);
688 #include "xlat/timerfdflags.h"
693 /* It does not matter that the kernel uses itimerspec. */
694 tprintf("%ld, ", tcp->u_arg[0]);
695 printclockname(tcp->u_arg[0]);
697 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
699 printitv(tcp, tcp->u_arg[3]);
704 SYS_FUNC(timerfd_create)
707 printclockname(tcp->u_arg[0]);
709 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
714 SYS_FUNC(timerfd_settime)
717 printfd(tcp, tcp->u_arg[0]);
719 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
721 printitv(tcp, tcp->u_arg[2]);
723 printitv(tcp, tcp->u_arg[3]);
728 SYS_FUNC(timerfd_gettime)
731 printfd(tcp, tcp->u_arg[0]);
733 printitv(tcp, tcp->u_arg[1]);