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.
35 #include <linux/version.h>
36 #include <sys/timex.h>
37 #include <linux/ioctl.h>
38 #include <linux/rtc.h>
41 #define UTIME_NOW ((1l << 30) - 1l)
44 #define UTIME_OMIT ((1l << 30) - 2l)
50 u_int32_t tv_sec, tv_usec;
54 tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
56 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
60 tprint_timeval(struct tcb *tcp, const struct timeval *tv)
63 (unsigned long) tv->tv_sec, (unsigned long) tv->tv_usec);
67 printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
71 else if (!verbose(tcp))
72 tprintf("%#lx", addr);
77 if (bitness == BITNESS_32
78 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
79 || personality_wordsize[current_personality] == 4
85 if ((rc = umove(tcp, addr, &tv)) >= 0) {
86 if (special && tv.tv_sec == 0 &&
87 tv.tv_usec == UTIME_NOW)
89 else if (special && tv.tv_sec == 0 &&
90 tv.tv_usec == UTIME_OMIT)
91 tprintf("UTIME_OMIT");
93 tprint_timeval32(tcp, &tv);
99 if ((rc = umove(tcp, addr, &tv)) >= 0) {
100 if (special && tv.tv_sec == 0 &&
101 tv.tv_usec == UTIME_NOW)
102 tprintf("UTIME_NOW");
103 else if (special && tv.tv_sec == 0 &&
104 tv.tv_usec == UTIME_OMIT)
105 tprintf("UTIME_OMIT");
107 tprint_timeval(tcp, &tv);
117 sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf)
121 else if (!verbose(tcp))
122 sprintf(buf, "%#lx", addr);
127 if (bitness == BITNESS_32
128 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
129 || personality_wordsize[current_personality] == 4
135 if ((rc = umove(tcp, addr, &tv)) >= 0)
136 sprintf(buf, "{%u, %u}",
137 tv.tv_sec, tv.tv_usec);
142 if ((rc = umove(tcp, addr, &tv)) >= 0)
143 sprintf(buf, "{%lu, %lu}",
144 (unsigned long) tv.tv_sec,
145 (unsigned long) tv.tv_usec);
149 strcpy(buf, "{...}");
153 void print_timespec (struct tcb *tcp, long addr)
157 else if (!verbose(tcp))
158 tprintf("%#lx", addr);
162 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
163 if (personality_wordsize[current_personality] == 4)
167 if ((rc = umove(tcp, addr, &tv)) >= 0)
169 tv.tv_sec, tv.tv_usec);
175 if ((rc = umove(tcp, addr, &ts)) >= 0)
176 tprintf("{%lu, %lu}",
177 (unsigned long) ts.tv_sec,
178 (unsigned long) ts.tv_nsec);
179 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
188 void sprint_timespec (char *buf, struct tcb *tcp, long addr)
192 else if (!verbose(tcp))
193 sprintf(buf, "%#lx", addr);
197 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
198 if (personality_wordsize[current_personality] == 4)
202 if ((rc = umove(tcp, addr, &tv)) >= 0)
203 sprintf(buf, "{%u, %u}",
204 tv.tv_sec, tv.tv_usec);
210 if ((rc = umove(tcp, addr, &ts)) >= 0)
211 sprintf(buf, "{%lu, %lu}",
212 (unsigned long) ts.tv_sec,
213 (unsigned long) ts.tv_nsec);
214 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
219 strcpy(buf, "{...}");
229 printnum(tcp, tcp->u_arg[0], "%ld");
240 printnum(tcp, tcp->u_arg[0], "%ld");
246 sys_gettimeofday(tcp)
251 tprintf("%#lx, %#lx",
252 tcp->u_arg[0], tcp->u_arg[1]);
255 printtv(tcp, tcp->u_arg[0]);
258 printtv(tcp, tcp->u_arg[1]);
267 sys_osf_gettimeofday(tcp)
272 tprintf("%#lx, %#lx",
273 tcp->u_arg[0], tcp->u_arg[1]);
276 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
279 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
287 sys_settimeofday(tcp)
291 printtv(tcp, tcp->u_arg[0]);
294 printtv(tcp, tcp->u_arg[1]);
302 sys_osf_settimeofday(tcp)
306 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
309 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
321 printtv(tcp, tcp->u_arg[0]);
325 tprintf("%#lx", tcp->u_arg[1]);
327 printtv(tcp, tcp->u_arg[1]);
332 static const struct xlat which[] = {
333 { ITIMER_REAL, "ITIMER_REAL" },
334 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
335 { ITIMER_PROF, "ITIMER_PROF" },
340 printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
344 else if (!verbose(tcp))
345 tprintf("%#lx", addr);
350 if (bitness == BITNESS_32
351 #if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
352 || personality_wordsize[current_personality] == 4
358 struct timeval32 it_interval, it_value;
361 if ((rc = umove(tcp, addr, &itv)) >= 0) {
362 tprintf("{it_interval=");
363 tprint_timeval32(tcp, &itv.it_interval);
364 tprintf(", it_value=");
365 tprint_timeval32(tcp, &itv.it_value);
370 struct itimerval itv;
372 if ((rc = umove(tcp, addr, &itv)) >= 0) {
373 tprintf("{it_interval=");
374 tprint_timeval(tcp, &itv.it_interval);
375 tprintf(", it_value=");
376 tprint_timeval(tcp, &itv.it_value);
386 #define printitv(tcp, addr) \
387 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
394 printxval(which, tcp->u_arg[0], "ITIMER_???");
398 tprintf("%#lx", tcp->u_arg[1]);
400 printitv(tcp, tcp->u_arg[1]);
408 sys_osf_getitimer(tcp)
412 printxval(which, tcp->u_arg[0], "ITIMER_???");
416 tprintf("%#lx", tcp->u_arg[1]);
418 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
429 printxval(which, tcp->u_arg[0], "ITIMER_???");
431 printitv(tcp, tcp->u_arg[1]);
435 tprintf("%#lx", tcp->u_arg[2]);
437 printitv(tcp, tcp->u_arg[2]);
444 sys_osf_setitimer(tcp)
448 printxval(which, tcp->u_arg[0], "ITIMER_???");
450 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
454 tprintf("%#lx", tcp->u_arg[2]);
456 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
464 static const struct xlat adjtimex_modes[] = {
467 { ADJ_OFFSET, "ADJ_OFFSET" },
470 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
473 { ADJ_MAXERROR, "ADJ_MAXERROR" },
476 { ADJ_ESTERROR, "ADJ_ESTERROR" },
479 { ADJ_STATUS, "ADJ_STATUS" },
482 { ADJ_TIMECONST, "ADJ_TIMECONST" },
485 { ADJ_TICK, "ADJ_TICK" },
487 #ifdef ADJ_OFFSET_SINGLESHOT
488 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
493 static const struct xlat adjtimex_status[] = {
495 { STA_PLL, "STA_PLL" },
498 { STA_PPSFREQ, "STA_PPSFREQ" },
501 { STA_PPSTIME, "STA_PPSTIME" },
504 { STA_FLL, "STA_FLL" },
507 { STA_INS, "STA_INS" },
510 { STA_DEL, "STA_DEL" },
513 { STA_UNSYNC, "STA_UNSYNC" },
516 { STA_FREQHOLD, "STA_FREQHOLD" },
519 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
522 { STA_PPSJITTER, "STA_PPSJITTER" },
525 { STA_PPSWANDER, "STA_PPSWANDER" },
528 { STA_PPSERROR, "STA_PPSERROR" },
531 { STA_CLOCKERR, "STA_CLOCKERR" },
536 static const struct xlat adjtimex_state[] = {
538 { TIME_OK, "TIME_OK" },
541 { TIME_INS, "TIME_INS" },
544 { TIME_DEL, "TIME_DEL" },
547 { TIME_OOP, "TIME_OOP" },
550 { TIME_WAIT, "TIME_WAIT" },
553 { TIME_ERROR, "TIME_ERROR" },
558 #if SUPPORTED_PERSONALITIES > 1
560 tprint_timex32(struct tcb *tcp, long addr)
573 struct timeval32 time;
585 if (umove(tcp, addr, &tx) < 0)
589 printflags(adjtimex_modes, tx.modes, "ADJ_???");
590 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
591 tx.offset, tx.freq, tx.maxerror);
592 tprintf("esterror=%u, status=", tx.esterror);
593 printflags(adjtimex_status, tx.status, "STA_???");
594 tprintf(", constant=%d, precision=%u, ",
595 tx.constant, tx.precision);
596 tprintf("tolerance=%d, time=", tx.tolerance);
597 tprint_timeval32(tcp, &tx.time);
598 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
599 tx.tick, tx.ppsfreq, tx.jitter);
600 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
601 tx.shift, tx.stabil, tx.jitcnt);
602 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
603 tx.calcnt, tx.errcnt, tx.stbcnt);
607 #endif /* SUPPORTED_PERSONALITIES > 1 */
610 tprint_timex(struct tcb *tcp, long addr)
614 #if SUPPORTED_PERSONALITIES > 1
615 if (personality_wordsize[current_personality] == 4)
616 return tprint_timex32(tcp, addr);
618 if (umove(tcp, addr, &tx) < 0)
621 #if LINUX_VERSION_CODE < 66332
622 tprintf("{mode=%d, offset=%ld, frequency=%ld, ",
623 tx.mode, tx.offset, tx.frequency);
624 tprintf("maxerror=%ld, esterror=%lu, status=%u, ",
625 tx.maxerror, tx.esterror, tx.status);
626 tprintf("time_constant=%ld, precision=%lu, ",
627 tx.time_constant, tx.precision);
628 tprintf("tolerance=%ld, time=", tx.tolerance);
629 tprint_timeval(tcp, &tx.time);
632 printflags(adjtimex_modes, tx.modes, "ADJ_???");
633 tprintf(", offset=%ld, freq=%ld, maxerror=%ld, ",
634 tx.offset, tx.freq, tx.maxerror);
635 tprintf("esterror=%lu, status=", tx.esterror);
636 printflags(adjtimex_status, tx.status, "STA_???");
637 tprintf(", constant=%ld, precision=%lu, ",
638 tx.constant, tx.precision);
639 tprintf("tolerance=%ld, time=", tx.tolerance);
640 tprint_timeval(tcp, &tx.time);
641 tprintf(", tick=%ld, ppsfreq=%ld, jitter=%ld",
642 tx.tick, tx.ppsfreq, tx.jitter);
643 tprintf(", shift=%d, stabil=%ld, jitcnt=%ld",
644 tx.shift, tx.stabil, tx.jitcnt);
645 tprintf(", calcnt=%ld, errcnt=%ld, stbcnt=%ld",
646 tx.calcnt, tx.errcnt, tx.stbcnt);
653 sys_adjtimex(struct tcb *tcp)
656 if (tcp->u_arg[0] == 0)
658 else if (syserror(tcp) || !verbose(tcp))
659 tprintf("%#lx", tcp->u_arg[0]);
660 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
662 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
669 static const struct xlat clockflags[] = {
670 { TIMER_ABSTIME, "TIMER_ABSTIME" },
674 static const struct xlat clocknames[] = {
675 #ifdef CLOCK_REALTIME
676 { CLOCK_REALTIME, "CLOCK_REALTIME" },
678 #ifdef CLOCK_MONOTONIC
679 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
685 sys_clock_settime(tcp)
689 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
691 printtv(tcp, tcp->u_arg[1]);
697 sys_clock_gettime(tcp)
701 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
705 tprintf("%#lx", tcp->u_arg[1]);
707 printtv(tcp, tcp->u_arg[1]);
713 sys_clock_nanosleep(tcp)
717 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
719 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
721 printtv(tcp, tcp->u_arg[2]);
725 tprintf("%#lx", tcp->u_arg[3]);
727 printtv(tcp, tcp->u_arg[3]);
732 #ifndef SIGEV_THREAD_ID
733 # define SIGEV_THREAD_ID 4
735 static const struct xlat sigev_value[] = {
736 { SIGEV_SIGNAL+1, "SIGEV_SIGNAL" },
737 { SIGEV_NONE+1, "SIGEV_NONE" },
738 { SIGEV_THREAD+1, "SIGEV_THREAD" },
739 { SIGEV_THREAD_ID+1, "SIGEV_THREAD_ID" },
743 #if SUPPORTED_PERSONALITIES > 1
745 printsigevent32(struct tcb *tcp, long arg)
758 int function, attribute;
763 if (umove(tcp, arg, &sev) < 0)
767 tprintf("{%#x, ", sev.sigev_value);
768 if (sev.sigev_notify == SIGEV_SIGNAL)
769 tprintf("%s, ", signame(sev.sigev_signo));
771 tprintf("%u, ", sev.sigev_signo);
772 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
774 if (sev.sigev_notify == SIGEV_THREAD_ID)
775 tprintf("{%d}", sev.un.tid);
776 else if (sev.sigev_notify == SIGEV_THREAD)
777 tprintf("{%#x, %#x}",
778 sev.un.thread.function,
779 sev.un.thread.attribute);
788 printsigevent(struct tcb *tcp, long arg)
792 #if SUPPORTED_PERSONALITIES > 1
793 if (personality_wordsize[current_personality] == 4)
795 printsigevent32(tcp, arg);
799 if (umove (tcp, arg, &sev) < 0)
802 tprintf("{%p, ", sev.sigev_value.sival_ptr);
803 if (sev.sigev_notify == SIGEV_SIGNAL)
804 tprintf("%s, ", signame(sev.sigev_signo));
806 tprintf("%u, ", sev.sigev_signo);
807 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
809 if (sev.sigev_notify == SIGEV_THREAD_ID)
810 /* _pad[0] is the _tid field which might not be
811 present in the userlevel definition of the
813 tprintf("{%d}", sev._sigev_un._pad[0]);
814 else if (sev.sigev_notify == SIGEV_THREAD)
815 tprintf("{%p, %p}", sev.sigev_notify_function,
816 sev.sigev_notify_attributes);
824 sys_timer_create(tcp)
828 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
830 printsigevent(tcp, tcp->u_arg[1]);
835 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &p) < 0)
836 tprintf("%#lx", tcp->u_arg[2]);
844 sys_timer_settime(tcp)
848 tprintf("%#lx, ", tcp->u_arg[0]);
849 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
851 printitv(tcp, tcp->u_arg[2]);
855 tprintf("%#lx", tcp->u_arg[3]);
857 printitv(tcp, tcp->u_arg[3]);
863 sys_timer_gettime(tcp)
867 tprintf("%#lx, ", tcp->u_arg[0]);
870 tprintf("%#lx", tcp->u_arg[1]);
872 printitv(tcp, tcp->u_arg[1]);
880 const struct rtc_time *rt;
882 tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, "
883 "tm_mday=%d, tm_mon=%d, tm_year=%d, ",
884 rt->tm_sec, rt->tm_min, rt->tm_hour,
885 rt->tm_mday, rt->tm_mon, rt->tm_year);
887 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
888 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
894 rtc_ioctl(tcp, code, arg)
904 if (umove(tcp, arg, &rt) < 0)
905 tprintf(", %#lx", arg);
916 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
917 tprintf(", %#lx", arg);
927 tprintf(", %lu", arg);
932 tprintf(", %lu", arg);
936 struct rtc_wkalrm wk;
937 if (umove(tcp, arg, &wk) < 0)
938 tprintf(", %#lx", arg);
940 tprintf(", {enabled=%d, pending=%d, ",
941 wk.enabled, wk.pending);
942 print_rtc(tcp, &wk.time);
949 struct rtc_wkalrm wk;
950 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
951 tprintf(", %#lx", arg);
953 tprintf(", {enabled=%d, pending=%d, ",
954 wk.enabled, wk.pending);
955 print_rtc(tcp, &wk.time);
962 tprintf(", %#lx", arg);
968 #ifndef TFD_TIMER_ABSTIME
969 #define TFD_TIMER_ABSTIME (1 << 0)
972 static const struct xlat timerfdflags[] = {
973 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
982 /* It does not matter that the kernel uses itimerspec. */
983 tprintf("%ld, ", tcp->u_arg[0]);
984 printxval(clocknames, tcp->u_arg[1], "CLOCK_???");
986 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
988 printitv(tcp, tcp->u_arg[3]);