#include "defs.h"
#include <fcntl.h>
#include <signal.h>
-#include <linux/version.h>
#include <sys/timex.h>
-#ifndef UTIME_NOW
-#define UTIME_NOW ((1l << 30) - 1l)
-#endif
-#ifndef UTIME_OMIT
-#define UTIME_OMIT ((1l << 30) - 2l)
-#endif
-
-#if SUPPORTED_PERSONALITIES > 1
-# if defined X86_64 || defined X32
-# define current_time_t_is_compat (current_personality == 1)
-# else
-# define current_time_t_is_compat (current_wordsize == 4)
-# endif
-#else
-# define current_time_t_is_compat 0
-#endif
-
-struct timeval32
-{
- u_int32_t tv_sec, tv_usec;
-};
-
static void
-tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
-{
- tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
-}
-
-static void
-tprint_timeval(struct tcb *tcp, const struct timeval *tv)
-{
- tprintf("{%ju, %ju}", (uintmax_t) tv->tv_sec, (uintmax_t) tv->tv_usec);
-}
-
-void
-printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
-{
- char buf[TIMEVAL_TEXT_BUFSIZE];
- sprinttv(buf, tcp, addr, bitness, special);
- tprints(buf);
-}
-
-static char *
-do_sprinttv(char *buf, const uintmax_t sec, const uintmax_t usec,
- const int special)
-{
- if (special) {
- switch (usec) {
- case UTIME_NOW:
- return stpcpy(buf, "UTIME_NOW");
- case UTIME_OMIT:
- return stpcpy(buf, "UTIME_OMIT");
- }
- }
- return buf + sprintf(buf, "{%ju, %ju}", sec, usec);
-}
-
-char *
-sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
-{
- if (addr == 0)
- return stpcpy(buf, "NULL");
-
- if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
- return buf + sprintf(buf, "%#lx", addr);
-
- if (bitness == BITNESS_32 || current_time_t_is_compat)
- {
- struct timeval32 tv;
-
- if (umove(tcp, addr, &tv) >= 0)
- return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
- } else {
- struct timeval tv;
-
- if (umove(tcp, addr, &tv) >= 0)
- return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
- }
-
- return buf + sprintf(buf, "%#lx", addr);
-}
-
-void
-print_timespec(struct tcb *tcp, long addr)
+print_timezone(struct tcb *tcp, const long addr)
{
- char buf[TIMESPEC_TEXT_BUFSIZE];
- sprint_timespec(buf, tcp, addr);
- tprints(buf);
-}
+ struct timezone tz;
-void
-sprint_timespec(char *buf, struct tcb *tcp, long addr)
-{
- if (addr == 0)
- strcpy(buf, "NULL");
- else if (!verbose(tcp))
- sprintf(buf, "%#lx", addr);
- else {
- int rc;
-
-#if SUPPORTED_PERSONALITIES > 1
- if (current_time_t_is_compat) {
- struct timeval32 tv;
-
- rc = umove(tcp, addr, &tv);
- if (rc >= 0)
- sprintf(buf, "{%u, %u}",
- tv.tv_sec, tv.tv_usec);
- } else
-#endif
- {
- struct timespec ts;
-
- rc = umove(tcp, addr, &ts);
- if (rc >= 0)
- sprintf(buf, "{%ju, %ju}",
- (uintmax_t) ts.tv_sec,
- (uintmax_t) ts.tv_nsec);
- }
- if (rc < 0)
- strcpy(buf, "{...}");
- }
-}
+ if (umove_or_printaddr(tcp, addr, &tz))
+ return;
-SYS_FUNC(time)
-{
- if (exiting(tcp)) {
- printnum_long(tcp, tcp->u_arg[0], "%ld");
- }
- return 0;
+ tprintf("{tz_minuteswest=%d, tz_dsttime=%d}",
+ tz.tz_minuteswest, tz.tz_dsttime);
}
SYS_FUNC(gettimeofday)
{
if (exiting(tcp)) {
- printtv(tcp, tcp->u_arg[0]);
+ print_timeval(tcp, tcp->u_arg[0]);
tprints(", ");
- printtv(tcp, tcp->u_arg[1]);
+ print_timezone(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(osf_gettimeofday)
{
if (exiting(tcp)) {
- printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
+ print_timeval32(tcp, tcp->u_arg[0]);
tprints(", ");
- printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
+ print_timezone(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(settimeofday)
{
- printtv(tcp, tcp->u_arg[0]);
+ print_timeval(tcp, tcp->u_arg[0]);
tprints(", ");
- printtv(tcp, tcp->u_arg[1]);
+ print_timezone(tcp, tcp->u_arg[1]);
return RVAL_DECODED;
}
#ifdef ALPHA
SYS_FUNC(osf_settimeofday)
{
- printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
+ print_timeval32(tcp, tcp->u_arg[0]);
tprints(", ");
- printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
+ print_timezone(tcp, tcp->u_arg[1]);
return RVAL_DECODED;
}
#endif
-SYS_FUNC(adjtime)
-{
- if (entering(tcp)) {
- printtv(tcp, tcp->u_arg[0]);
- tprints(", ");
- } else {
- printtv(tcp, tcp->u_arg[1]);
- }
- return 0;
-}
-
SYS_FUNC(nanosleep)
{
if (entering(tcp)) {
print_timespec(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
- /* Second (returned) timespec is only significant
- * if syscall was interrupted. On success, we print
- * only its address, since kernel doesn't modify it,
+
+ /*
+ * Second (returned) timespec is only significant if syscall
+ * was interrupted. On success and in case of other errors we
+ * print only its address, since kernel doesn't modify it,
* and printing the value may show uninitialized data.
*/
- switch (tcp->u_error) {
- default:
- /* Not interrupted (slept entire interval) */
- printaddr(tcp->u_arg[1]);
- break;
- case ERESTARTSYS:
- case ERESTARTNOINTR:
- case ERESTARTNOHAND:
- case ERESTART_RESTARTBLOCK:
- /* Interrupted */
+ if (is_erestart(tcp)) {
+ temporarily_clear_syserror(tcp);
print_timespec(tcp, tcp->u_arg[1]);
+ restore_cleared_syserror(tcp);
+ } else {
+ printaddr(tcp->u_arg[1]);
}
}
return 0;
#include "xlat/itimer_which.h"
-static void
-printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
-{
- if (bitness == BITNESS_32 || current_time_t_is_compat) {
- struct {
- struct timeval32 it_interval, it_value;
- } itv;
-
- if (!umove_or_printaddr(tcp, addr, &itv)) {
- tprints("{it_interval=");
- tprint_timeval32(tcp, &itv.it_interval);
- tprints(", it_value=");
- tprint_timeval32(tcp, &itv.it_value);
- tprints("}");
- }
- } else {
- struct itimerval itv;
-
- if (!umove_or_printaddr(tcp, addr, &itv)) {
- tprints("{it_interval=");
- tprint_timeval(tcp, &itv.it_interval);
- tprints(", it_value=");
- tprint_timeval(tcp, &itv.it_value);
- tprints("}");
- }
- }
-}
-
-#define printitv(tcp, addr) \
- printitv_bitness((tcp), (addr), BITNESS_CURRENT)
-
SYS_FUNC(getitimer)
{
if (entering(tcp)) {
printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
tprints(", ");
} else {
- printitv(tcp, tcp->u_arg[1]);
+ print_itimerval(tcp, tcp->u_arg[1]);
}
return 0;
}
printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
tprints(", ");
} else {
- printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
+ print_itimerval32(tcp, tcp->u_arg[1]);
}
return 0;
}
if (entering(tcp)) {
printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
tprints(", ");
- printitv(tcp, tcp->u_arg[1]);
+ print_itimerval(tcp, tcp->u_arg[1]);
tprints(", ");
} else {
- printitv(tcp, tcp->u_arg[2]);
+ print_itimerval(tcp, tcp->u_arg[2]);
}
return 0;
}
if (entering(tcp)) {
printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
tprints(", ");
- printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
+ print_itimerval32(tcp, tcp->u_arg[1]);
tprints(", ");
} else {
- printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
+ print_itimerval32(tcp, tcp->u_arg[2]);
}
return 0;
}
#endif
-#include "xlat/adjtimex_modes.h"
-#include "xlat/adjtimex_status.h"
#include "xlat/adjtimex_state.h"
-#if SUPPORTED_PERSONALITIES > 1
-static int
-tprint_timex32(struct tcb *tcp, long addr)
-{
- struct {
- unsigned int modes;
- int offset;
- int freq;
- int maxerror;
- int esterror;
- int status;
- int constant;
- int precision;
- int tolerance;
- struct timeval32 time;
- int tick;
- int ppsfreq;
- int jitter;
- int shift;
- int stabil;
- int jitcnt;
- int calcnt;
- int errcnt;
- int stbcnt;
- } tx;
-
- if (umove_or_printaddr(tcp, addr, &tx))
- return -1;
-
- tprints("{modes=");
- printflags(adjtimex_modes, tx.modes, "ADJ_???");
- tprintf(", offset=%d, freq=%d, maxerror=%d, ",
- tx.offset, tx.freq, tx.maxerror);
- tprintf("esterror=%u, status=", tx.esterror);
- printflags(adjtimex_status, tx.status, "STA_???");
- tprintf(", constant=%d, precision=%u, ",
- tx.constant, tx.precision);
- tprintf("tolerance=%d, time=", tx.tolerance);
- tprint_timeval32(tcp, &tx.time);
- tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
- tx.tick, tx.ppsfreq, tx.jitter);
- tprintf(", shift=%d, stabil=%d, jitcnt=%d",
- tx.shift, tx.stabil, tx.jitcnt);
- tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
- tx.calcnt, tx.errcnt, tx.stbcnt);
- tprints("}");
- return 0;
-}
-#endif /* SUPPORTED_PERSONALITIES > 1 */
-
-static int
-tprint_timex(struct tcb *tcp, long addr)
-{
- struct timex tx;
-
-#if SUPPORTED_PERSONALITIES > 1
- if (current_time_t_is_compat)
- return tprint_timex32(tcp, addr);
-#endif
- if (umove_or_printaddr(tcp, addr, &tx))
- return -1;
-
-#if LINUX_VERSION_CODE < 66332
- tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
- tx.mode, tx.offset, tx.frequency);
- tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
- tx.maxerror, tx.esterror, tx.status);
- tprintf("time_constant=%ld, precision=%lu, ",
- tx.time_constant, tx.precision);
- tprintf("tolerance=%ld, time=", tx.tolerance);
- tprint_timeval(tcp, &tx.time);
-#else
- tprints("{modes=");
- printflags(adjtimex_modes, tx.modes, "ADJ_???");
- tprintf(", offset=%jd, freq=%jd, maxerror=%ju, esterror=%ju, status=",
- (intmax_t) tx.offset, (intmax_t) tx.freq,
- (uintmax_t) tx.maxerror, (uintmax_t) tx.esterror);
- printflags(adjtimex_status, tx.status, "STA_???");
- tprintf(", constant=%jd, precision=%ju, tolerance=%jd, time=",
- (intmax_t) tx.constant, (uintmax_t) tx.precision,
- (intmax_t) tx.tolerance);
- tprint_timeval(tcp, &tx.time);
- tprintf(", tick=%jd, ppsfreq=%jd, jitter=%jd",
- (intmax_t) tx.tick, (intmax_t) tx.ppsfreq, (intmax_t) tx.jitter);
- tprintf(", shift=%d, stabil=%jd, jitcnt=%jd",
- tx.shift, (intmax_t) tx.stabil, (intmax_t) tx.jitcnt);
- tprintf(", calcnt=%jd, errcnt=%jd, stbcnt=%jd",
- (intmax_t) tx.calcnt, (intmax_t) tx.errcnt, (intmax_t) tx.stbcnt);
-#endif
- tprints("}");
- return 0;
-}
-
static int
do_adjtimex(struct tcb *tcp, long addr)
{
- if (tprint_timex(tcp, addr))
+ if (print_timex(tcp, addr))
return 0;
tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
if (tcp->auxstr)
{
printclockname(tcp->u_arg[0]);
tprints(", ");
- printtv(tcp, tcp->u_arg[1]);
+ print_timespec(tcp, tcp->u_arg[1]);
return RVAL_DECODED;
}
printclockname(tcp->u_arg[0]);
tprints(", ");
} else {
- printtv(tcp, tcp->u_arg[1]);
+ print_timespec(tcp, tcp->u_arg[1]);
}
return 0;
}
tprints(", ");
printflags(clockflags, tcp->u_arg[1], "TIMER_???");
tprints(", ");
- printtv(tcp, tcp->u_arg[2]);
+ print_timespec(tcp, tcp->u_arg[2]);
tprints(", ");
} else {
- printtv(tcp, tcp->u_arg[3]);
+ /*
+ * Second (returned) timespec is only significant
+ * if syscall was interrupted and flags is not TIMER_ABSTIME.
+ */
+ if (!tcp->u_arg[1] && is_erestart(tcp)) {
+ temporarily_clear_syserror(tcp);
+ print_timespec(tcp, tcp->u_arg[3]);
+ restore_cleared_syserror(tcp);
+ } else {
+ printaddr(tcp->u_arg[3]);
+ }
}
return 0;
}
return 0;
}
-#ifndef SIGEV_THREAD_ID
-# define SIGEV_THREAD_ID 4
-#endif
-#include "xlat/sigev_value.h"
-
-#if SUPPORTED_PERSONALITIES > 1
-static void
-printsigevent32(struct tcb *tcp, long arg)
-{
- struct {
- int sigev_value;
- int sigev_signo;
- int sigev_notify;
-
- union {
- int tid;
- struct {
- int function, attribute;
- } thread;
- } un;
- } sev;
-
- if (!umove_or_printaddr(tcp, arg, &sev)) {
- tprintf("{%#x, ", sev.sigev_value);
- if (sev.sigev_notify == SIGEV_SIGNAL)
- tprintf("%s, ", signame(sev.sigev_signo));
- else
- tprintf("%u, ", sev.sigev_signo);
- printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
- tprints(", ");
- if (sev.sigev_notify == SIGEV_THREAD_ID)
- tprintf("{%d}", sev.un.tid);
- else if (sev.sigev_notify == SIGEV_THREAD)
- tprintf("{%#x, %#x}",
- sev.un.thread.function,
- sev.un.thread.attribute);
- else
- tprints("{...}");
- tprints("}");
- }
-}
-#endif
-
-void
-printsigevent(struct tcb *tcp, long arg)
-{
- struct sigevent sev;
-
-#if SUPPORTED_PERSONALITIES > 1
- if (current_wordsize == 4) {
- printsigevent32(tcp, arg);
- return;
- }
-#endif
- if (!umove_or_printaddr(tcp, arg, &sev)) {
- tprintf("{%p, ", sev.sigev_value.sival_ptr);
- if (sev.sigev_notify == SIGEV_SIGNAL)
- tprintf("%s, ", signame(sev.sigev_signo));
- else
- tprintf("%u, ", sev.sigev_signo);
- printxval(sigev_value, sev.sigev_notify, "SIGEV_???");
- tprints(", ");
- if (sev.sigev_notify == SIGEV_THREAD_ID)
-#if defined(HAVE_STRUCT_SIGEVENT__SIGEV_UN__PAD)
- /* _pad[0] is the _tid field which might not be
- present in the userlevel definition of the
- struct. */
- tprintf("{%d}", sev._sigev_un._pad[0]);
-#elif defined(HAVE_STRUCT_SIGEVENT___PAD)
- tprintf("{%d}", sev.__pad[0]);
-#else
-# warning unfamiliar struct sigevent => incomplete SIGEV_THREAD_ID decoding
- tprints("{...}");
-#endif
- else if (sev.sigev_notify == SIGEV_THREAD)
- tprintf("{%p, %p}", sev.sigev_notify_function,
- sev.sigev_notify_attributes);
- else
- tprints("{...}");
- tprints("}");
- }
-}
-
SYS_FUNC(timer_create)
{
if (entering(tcp)) {
printclockname(tcp->u_arg[0]);
tprints(", ");
- printsigevent(tcp, tcp->u_arg[1]);
+ print_sigevent(tcp, tcp->u_arg[1]);
tprints(", ");
} else {
printnum_int(tcp, tcp->u_arg[2], "%d");
tprintf("%d, ", (int) tcp->u_arg[0]);
printflags(clockflags, tcp->u_arg[1], "TIMER_???");
tprints(", ");
- printitv(tcp, tcp->u_arg[2]);
+ print_itimerspec(tcp, tcp->u_arg[2]);
tprints(", ");
} else {
- printitv(tcp, tcp->u_arg[3]);
+ print_itimerspec(tcp, tcp->u_arg[3]);
}
return 0;
}
if (entering(tcp)) {
tprintf("%d, ", (int) tcp->u_arg[0]);
} else {
- printitv(tcp, tcp->u_arg[1]);
+ print_itimerspec(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(timerfd)
{
- /* It does not matter that the kernel uses itimerspec. */
tprintf("%ld, ", tcp->u_arg[0]);
printclockname(tcp->u_arg[0]);
tprints(", ");
printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
tprints(", ");
- printitv(tcp, tcp->u_arg[3]);
+ print_itimerspec(tcp, tcp->u_arg[3]);
- return RVAL_DECODED;
+ return RVAL_DECODED | RVAL_FD;
}
SYS_FUNC(timerfd_create)
tprints(", ");
printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
- return RVAL_DECODED;
+ return RVAL_DECODED | RVAL_FD;
}
SYS_FUNC(timerfd_settime)
tprints(", ");
printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
tprints(", ");
- printitv(tcp, tcp->u_arg[2]);
+ print_itimerspec(tcp, tcp->u_arg[2]);
tprints(", ");
- printitv(tcp, tcp->u_arg[3]);
+ print_itimerspec(tcp, tcp->u_arg[3]);
return RVAL_DECODED;
}
printfd(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
- printitv(tcp, tcp->u_arg[1]);
+ print_itimerspec(tcp, tcp->u_arg[1]);
}
return 0;
}