blob: 676aace4818c55c53f344b183d9a5988f296e20b [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
17 *
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.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#ifdef LINUX
35#include <linux/version.h>
Wichert Akkermand856b992000-10-13 12:47:12 +000036#include <sys/timex.h>
Roland McGrathd83c50b2004-10-06 22:27:43 +000037#include <linux/ioctl.h>
38#include <linux/rtc.h>
Roland McGrath6afc5652007-07-24 01:57:11 +000039
40#ifndef UTIME_NOW
41#define UTIME_NOW ((1l << 30) - 1l)
42#endif
43#ifndef UTIME_OMIT
44#define UTIME_OMIT ((1l << 30) - 2l)
45#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046#endif /* LINUX */
47
Dmitry V. Levina7945a32006-12-13 17:10:11 +000048struct timeval32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049{
Dmitry V. Levina7945a32006-12-13 17:10:11 +000050 u_int32_t tv_sec, tv_usec;
51};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +000053static void
54tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
55{
56 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
57}
58
59static void
60tprint_timeval(struct tcb *tcp, const struct timeval *tv)
61{
62 tprintf("{%lu, %lu}",
63 (unsigned long) tv->tv_sec, (unsigned long) tv->tv_usec);
64}
65
Dmitry V. Levina7945a32006-12-13 17:10:11 +000066void
Roland McGrath6afc5652007-07-24 01:57:11 +000067printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
Dmitry V. Levina7945a32006-12-13 17:10:11 +000068{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000069 if (addr == 0)
70 tprintf("NULL");
71 else if (!verbose(tcp))
72 tprintf("%#lx", addr);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073 else
Dmitry V. Levina7945a32006-12-13 17:10:11 +000074 {
75 int rc;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076
Dmitry V. Levina7945a32006-12-13 17:10:11 +000077 if (bitness == BITNESS_32
78#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
79 || personality_wordsize[current_personality] == 4
80#endif
81 )
82 {
83 struct timeval32 tv;
84
Roland McGrath6afc5652007-07-24 01:57:11 +000085 if ((rc = umove(tcp, addr, &tv)) >= 0) {
Roland McGrath41383392007-07-24 01:58:52 +000086 if (special && tv.tv_sec == 0 &&
87 tv.tv_usec == UTIME_NOW)
Roland McGrath6afc5652007-07-24 01:57:11 +000088 tprintf("UTIME_NOW");
Roland McGrath41383392007-07-24 01:58:52 +000089 else if (special && tv.tv_sec == 0 &&
90 tv.tv_usec == UTIME_OMIT)
Roland McGrath6afc5652007-07-24 01:57:11 +000091 tprintf("UTIME_OMIT");
92 else
93 tprint_timeval32(tcp, &tv);
94 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +000095 } else
96 {
97 struct timeval tv;
98
Roland McGrath6afc5652007-07-24 01:57:11 +000099 if ((rc = umove(tcp, addr, &tv)) >= 0) {
Roland McGrath41383392007-07-24 01:58:52 +0000100 if (special && tv.tv_sec == 0 &&
101 tv.tv_usec == UTIME_NOW)
Roland McGrath6afc5652007-07-24 01:57:11 +0000102 tprintf("UTIME_NOW");
Roland McGrath41383392007-07-24 01:58:52 +0000103 else if (special && tv.tv_sec == 0 &&
104 tv.tv_usec == UTIME_OMIT)
Roland McGrath6afc5652007-07-24 01:57:11 +0000105 tprintf("UTIME_OMIT");
106 else
107 tprint_timeval(tcp, &tv);
108 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000109 }
110
111 if (rc < 0)
112 tprintf("{...}");
113 }
114}
Wichert Akkerman221f54f1999-11-18 17:26:45 +0000115
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000116void
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000117sprinttv(struct tcb *tcp, long addr, enum bitness_t bitness, char *buf)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000118{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000119 if (addr == 0)
120 strcpy(buf, "NULL");
121 else if (!verbose(tcp))
122 sprintf(buf, "%#lx", addr);
123 else
124 {
125 int rc;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000126
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000127 if (bitness == BITNESS_32
128#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
129 || personality_wordsize[current_personality] == 4
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000130#endif
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000131 )
132 {
133 struct timeval32 tv;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000134
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000135 if ((rc = umove(tcp, addr, &tv)) >= 0)
136 sprintf(buf, "{%u, %u}",
137 tv.tv_sec, tv.tv_usec);
138 } else
139 {
140 struct timeval tv;
141
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);
146 }
147
148 if (rc < 0)
149 strcpy(buf, "{...}");
150 }
151}
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000152
Roland McGrath6bc09da2007-11-01 21:50:54 +0000153void print_timespec (struct tcb *tcp, long addr)
154{
155 if (addr == 0)
156 tprintf("NULL");
157 else if (!verbose(tcp))
158 tprintf("%#lx", addr);
159 else {
160 int rc;
161
162#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
163 if (personality_wordsize[current_personality] == 4)
164 {
165 struct timeval32 tv;
166
167 if ((rc = umove(tcp, addr, &tv)) >= 0)
168 tprintf("{%u, %u}",
169 tv.tv_sec, tv.tv_usec);
170 } else
171 {
172#endif
173 struct timespec ts;
174
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
180 }
181#endif
182
183 if (rc < 0)
184 tprintf("{...}");
185 }
186}
187
188void sprint_timespec (char *buf, struct tcb *tcp, long addr)
189{
190 if (addr == 0)
191 strcpy(buf, "NULL");
192 else if (!verbose(tcp))
193 sprintf(buf, "%#lx", addr);
194 else {
195 int rc;
196
197#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
198 if (personality_wordsize[current_personality] == 4)
199 {
200 struct timeval32 tv;
201
202 if ((rc = umove(tcp, addr, &tv)) >= 0)
203 sprintf(buf, "{%u, %u}",
204 tv.tv_sec, tv.tv_usec);
205 } else
206 {
207#endif
208 struct timespec ts;
209
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
215 }
216#endif
217
218 if (rc < 0)
219 strcpy(buf, "{...}");
220 }
221}
222
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223int
224sys_time(tcp)
225struct tcb *tcp;
226{
227 if (exiting(tcp)) {
228#ifndef SVR4
229 printnum(tcp, tcp->u_arg[0], "%ld");
230#endif /* SVR4 */
231 }
232 return 0;
233}
234
235int
236sys_stime(tcp)
237struct tcb *tcp;
238{
239 if (exiting(tcp)) {
240 printnum(tcp, tcp->u_arg[0], "%ld");
241 }
242 return 0;
243}
244
245int
246sys_gettimeofday(tcp)
247struct tcb *tcp;
248{
249 if (exiting(tcp)) {
250 if (syserror(tcp)) {
251 tprintf("%#lx, %#lx",
252 tcp->u_arg[0], tcp->u_arg[1]);
253 return 0;
254 }
255 printtv(tcp, tcp->u_arg[0]);
256#ifndef SVR4
257 tprintf(", ");
258 printtv(tcp, tcp->u_arg[1]);
259#endif /* !SVR4 */
260 }
261 return 0;
262}
263
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000264
265#ifdef ALPHA
266int
267sys_osf_gettimeofday(tcp)
268struct tcb *tcp;
269{
270 if (exiting(tcp)) {
271 if (syserror(tcp)) {
272 tprintf("%#lx, %#lx",
273 tcp->u_arg[0], tcp->u_arg[1]);
274 return 0;
275 }
Roland McGrath6afc5652007-07-24 01:57:11 +0000276 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000277#ifndef SVR4
278 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000279 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000280#endif /* !SVR4 */
281 }
282 return 0;
283}
284#endif
285
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000286int
287sys_settimeofday(tcp)
288struct tcb *tcp;
289{
290 if (entering(tcp)) {
291 printtv(tcp, tcp->u_arg[0]);
292#ifndef SVR4
293 tprintf(", ");
294 printtv(tcp, tcp->u_arg[1]);
295#endif /* !SVR4 */
296 }
297 return 0;
298}
299
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000300#ifdef ALPHA
301int
302sys_osf_settimeofday(tcp)
303struct tcb *tcp;
304{
305 if (entering(tcp)) {
Roland McGrath6afc5652007-07-24 01:57:11 +0000306 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000307#ifndef SVR4
308 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000309 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000310#endif /* !SVR4 */
311 }
312 return 0;
313}
314#endif
315
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316int
317sys_adjtime(tcp)
318struct tcb *tcp;
319{
320 if (entering(tcp)) {
321 printtv(tcp, tcp->u_arg[0]);
322 tprintf(", ");
323 } else {
324 if (syserror(tcp))
325 tprintf("%#lx", tcp->u_arg[1]);
326 else
327 printtv(tcp, tcp->u_arg[1]);
328 }
329 return 0;
330}
331
Roland McGrathd9f816f2004-09-04 03:39:20 +0000332static const struct xlat which[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000333 { ITIMER_REAL, "ITIMER_REAL" },
334 { ITIMER_VIRTUAL,"ITIMER_VIRTUAL"},
335 { ITIMER_PROF, "ITIMER_PROF" },
336 { 0, NULL },
337};
338
339static void
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000340printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000341{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000342 if (addr == 0)
343 tprintf("NULL");
344 else if (!verbose(tcp))
345 tprintf("%#lx", addr);
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000346 else
347 {
348 int rc;
349
350 if (bitness == BITNESS_32
351#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
352 || personality_wordsize[current_personality] == 4
353#endif
354 )
355 {
356 struct
357 {
358 struct timeval32 it_interval, it_value;
359 } itv;
360
Roland McGrathe4662342007-08-02 01:25:34 +0000361 if ((rc = umove(tcp, addr, &itv)) >= 0) {
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000362 tprintf("{it_interval=");
363 tprint_timeval32(tcp, &itv.it_interval);
364 tprintf(", it_value=");
365 tprint_timeval32(tcp, &itv.it_value);
366 tprintf("}");
Roland McGrathe4662342007-08-02 01:25:34 +0000367 }
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000368 } else
369 {
370 struct itimerval itv;
371
Roland McGrathe4662342007-08-02 01:25:34 +0000372 if ((rc = umove(tcp, addr, &itv)) >= 0) {
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000373 tprintf("{it_interval=");
374 tprint_timeval(tcp, &itv.it_interval);
375 tprintf(", it_value=");
376 tprint_timeval(tcp, &itv.it_value);
377 tprintf("}");
Roland McGrathe4662342007-08-02 01:25:34 +0000378 }
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000379 }
380
381 if (rc < 0)
382 tprintf("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383 }
384}
385
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000386#define printitv(tcp, addr) \
387 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000388
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000389int
390sys_getitimer(tcp)
391struct tcb *tcp;
392{
393 if (entering(tcp)) {
394 printxval(which, tcp->u_arg[0], "ITIMER_???");
395 tprintf(", ");
396 } else {
397 if (syserror(tcp))
398 tprintf("%#lx", tcp->u_arg[1]);
399 else
400 printitv(tcp, tcp->u_arg[1]);
401 }
402 return 0;
403}
404
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000405
406#ifdef ALPHA
407int
408sys_osf_getitimer(tcp)
409struct tcb *tcp;
410{
411 if (entering(tcp)) {
412 printxval(which, tcp->u_arg[0], "ITIMER_???");
413 tprintf(", ");
414 } else {
415 if (syserror(tcp))
416 tprintf("%#lx", tcp->u_arg[1]);
417 else
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000418 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000419 }
420 return 0;
421}
422#endif
423
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000424int
425sys_setitimer(tcp)
426struct tcb *tcp;
427{
428 if (entering(tcp)) {
429 printxval(which, tcp->u_arg[0], "ITIMER_???");
430 tprintf(", ");
431 printitv(tcp, tcp->u_arg[1]);
432 tprintf(", ");
433 } else {
434 if (syserror(tcp))
435 tprintf("%#lx", tcp->u_arg[2]);
436 else
437 printitv(tcp, tcp->u_arg[2]);
438 }
439 return 0;
440}
441
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000442#ifdef ALPHA
443int
444sys_osf_setitimer(tcp)
445struct tcb *tcp;
446{
447 if (entering(tcp)) {
448 printxval(which, tcp->u_arg[0], "ITIMER_???");
449 tprintf(", ");
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000450 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000451 tprintf(", ");
452 } else {
453 if (syserror(tcp))
454 tprintf("%#lx", tcp->u_arg[2]);
455 else
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000456 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000457 }
458 return 0;
459}
460#endif
461
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462#ifdef LINUX
463
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000464static const struct xlat adjtimex_modes[] = {
465 { 0, "0" },
466#ifdef ADJ_OFFSET
467 { ADJ_OFFSET, "ADJ_OFFSET" },
468#endif
469#ifdef ADJ_FREQUENCY
470 { ADJ_FREQUENCY, "ADJ_FREQUENCY" },
471#endif
472#ifdef ADJ_MAXERROR
473 { ADJ_MAXERROR, "ADJ_MAXERROR" },
474#endif
475#ifdef ADJ_ESTERROR
476 { ADJ_ESTERROR, "ADJ_ESTERROR" },
477#endif
478#ifdef ADJ_STATUS
479 { ADJ_STATUS, "ADJ_STATUS" },
480#endif
481#ifdef ADJ_TIMECONST
482 { ADJ_TIMECONST, "ADJ_TIMECONST" },
483#endif
484#ifdef ADJ_TICK
485 { ADJ_TICK, "ADJ_TICK" },
486#endif
487#ifdef ADJ_OFFSET_SINGLESHOT
488 { ADJ_OFFSET_SINGLESHOT, "ADJ_OFFSET_SINGLESHOT" },
489#endif
490 { 0, NULL }
491};
492
493static const struct xlat adjtimex_status[] = {
494#ifdef STA_PLL
495 { STA_PLL, "STA_PLL" },
496#endif
497#ifdef STA_PPSFREQ
498 { STA_PPSFREQ, "STA_PPSFREQ" },
499#endif
500#ifdef STA_PPSTIME
501 { STA_PPSTIME, "STA_PPSTIME" },
502#endif
503#ifdef STA_FLL
504 { STA_FLL, "STA_FLL" },
505#endif
506#ifdef STA_INS
507 { STA_INS, "STA_INS" },
508#endif
509#ifdef STA_DEL
510 { STA_DEL, "STA_DEL" },
511#endif
512#ifdef STA_UNSYNC
513 { STA_UNSYNC, "STA_UNSYNC" },
514#endif
515#ifdef STA_FREQHOLD
516 { STA_FREQHOLD, "STA_FREQHOLD" },
517#endif
518#ifdef STA_PPSSIGNAL
519 { STA_PPSSIGNAL, "STA_PPSSIGNAL" },
520#endif
521#ifdef STA_PPSJITTER
522 { STA_PPSJITTER, "STA_PPSJITTER" },
523#endif
524#ifdef STA_PPSWANDER
525 { STA_PPSWANDER, "STA_PPSWANDER" },
526#endif
527#ifdef STA_PPSERROR
528 { STA_PPSERROR, "STA_PPSERROR" },
529#endif
530#ifdef STA_CLOCKERR
531 { STA_CLOCKERR, "STA_CLOCKERR" },
532#endif
533 { 0, NULL }
534};
535
536static const struct xlat adjtimex_state[] = {
537#ifdef TIME_OK
538 { TIME_OK, "TIME_OK" },
539#endif
540#ifdef TIME_INS
541 { TIME_INS, "TIME_INS" },
542#endif
543#ifdef TIME_DEL
544 { TIME_DEL, "TIME_DEL" },
545#endif
546#ifdef TIME_OOP
547 { TIME_OOP, "TIME_OOP" },
548#endif
549#ifdef TIME_WAIT
550 { TIME_WAIT, "TIME_WAIT" },
551#endif
552#ifdef TIME_ERROR
553 { TIME_ERROR, "TIME_ERROR" },
554#endif
555 { 0, NULL }
556};
557
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000558#if SUPPORTED_PERSONALITIES > 1
559static int
560tprint_timex32(struct tcb *tcp, long addr)
561{
562 struct
563 {
564 unsigned int modes;
565 int offset;
566 int freq;
567 int maxerror;
568 int esterror;
569 int status;
570 int constant;
571 int precision;
572 int tolerance;
573 struct timeval32 time;
574 int tick;
575 int ppsfreq;
576 int jitter;
577 int shift;
578 int stabil;
579 int jitcnt;
580 int calcnt;
581 int errcnt;
582 int stbcnt;
583 } tx;
584
585 if (umove(tcp, addr, &tx) < 0)
586 return -1;
587
588 tprintf("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000589 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000590 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);
604 tprintf("}");
605 return 0;
606}
607#endif /* SUPPORTED_PERSONALITIES > 1 */
608
609static int
610tprint_timex(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611{
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000612 struct timex tx;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000613
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000614#if SUPPORTED_PERSONALITIES > 1
615 if (personality_wordsize[current_personality] == 4)
616 return tprint_timex32(tcp, addr);
617#endif
618 if (umove(tcp, addr, &tx) < 0)
619 return -1;
620
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);
630#else
631 tprintf("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000632 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000633 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);
647#endif
648 tprintf("}");
649 return 0;
650}
651
652int
653sys_adjtimex(struct tcb *tcp)
654{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000655 if (exiting(tcp)) {
656 if (tcp->u_arg[0] == 0)
657 tprintf("NULL");
658 else if (syserror(tcp) || !verbose(tcp))
659 tprintf("%#lx", tcp->u_arg[0]);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000660 else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000661 tprintf("{...}");
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000662 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
663 if (tcp->auxstr)
664 return RVAL_STR;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000665 }
666 return 0;
667}
Roland McGrath1e356792003-03-30 23:52:28 +0000668
Roland McGrathd9f816f2004-09-04 03:39:20 +0000669static const struct xlat clockflags[] = {
Roland McGrath1e356792003-03-30 23:52:28 +0000670 { TIMER_ABSTIME, "TIMER_ABSTIME" },
671 { 0, NULL }
672};
673
Roland McGrathd9f816f2004-09-04 03:39:20 +0000674static const struct xlat clocknames[] = {
Roland McGrath55a00f82004-08-31 08:26:39 +0000675#ifdef CLOCK_REALTIME
Roland McGrath54a4edd2004-08-31 06:52:45 +0000676 { CLOCK_REALTIME, "CLOCK_REALTIME" },
Roland McGrath55a00f82004-08-31 08:26:39 +0000677#endif
678#ifdef CLOCK_MONOTONIC
Roland McGrath54a4edd2004-08-31 06:52:45 +0000679 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" },
Roland McGrath55a00f82004-08-31 08:26:39 +0000680#endif
Roland McGrath54a4edd2004-08-31 06:52:45 +0000681 { 0, NULL }
682};
683
Roland McGrath1e356792003-03-30 23:52:28 +0000684int
685sys_clock_settime(tcp)
686struct tcb *tcp;
687{
688 if (entering(tcp)) {
Roland McGrath54a4edd2004-08-31 06:52:45 +0000689 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
690 tprintf(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000691 printtv(tcp, tcp->u_arg[1]);
692 }
693 return 0;
694}
695
696int
697sys_clock_gettime(tcp)
698struct tcb *tcp;
699{
700 if (entering(tcp)) {
Roland McGrath54a4edd2004-08-31 06:52:45 +0000701 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
702 tprintf(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000703 } else {
704 if (syserror(tcp))
705 tprintf("%#lx", tcp->u_arg[1]);
706 else
707 printtv(tcp, tcp->u_arg[1]);
708 }
709 return 0;
710}
711
712int
713sys_clock_nanosleep(tcp)
714struct tcb *tcp;
715{
716 if (entering(tcp)) {
Roland McGrath54a4edd2004-08-31 06:52:45 +0000717 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
718 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000719 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Roland McGrath1e356792003-03-30 23:52:28 +0000720 tprintf(", ");
721 printtv(tcp, tcp->u_arg[2]);
722 tprintf(", ");
723 } else {
724 if (syserror(tcp))
725 tprintf("%#lx", tcp->u_arg[3]);
726 else
727 printtv(tcp, tcp->u_arg[3]);
728 }
729 return 0;
730}
731
732#ifndef SIGEV_THREAD_ID
733# define SIGEV_THREAD_ID 4
734#endif
Roland McGrathd9f816f2004-09-04 03:39:20 +0000735static const struct xlat sigev_value[] = {
Roland McGrath1e356792003-03-30 23:52:28 +0000736 { 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" },
740 { 0, NULL }
741};
742
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000743#if SUPPORTED_PERSONALITIES > 1
744static void
745printsigevent32(struct tcb *tcp, long arg)
746{
747 struct
748 {
749 int sigev_value;
750 int sigev_signo;
751 int sigev_notify;
752
753 union
754 {
755 int tid;
756 struct
757 {
758 int function, attribute;
759 } thread;
760 } un;
761 } sev;
762
763 if (umove(tcp, arg, &sev) < 0)
764 tprintf("{...}");
765 else
766 {
767 tprintf("{%#x, ", sev.sigev_value);
768 if (sev.sigev_notify == SIGEV_SIGNAL)
769 tprintf("%s, ", signame(sev.sigev_signo));
770 else
771 tprintf("%u, ", sev.sigev_signo);
772 printxval(sigev_value, sev.sigev_notify + 1, "SIGEV_???");
773 tprintf(", ");
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);
780 else
781 tprintf("{...}");
782 tprintf("}");
783 }
784}
785#endif
786
Roland McGrath1e356792003-03-30 23:52:28 +0000787void
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000788printsigevent(struct tcb *tcp, long arg)
Roland McGrath1e356792003-03-30 23:52:28 +0000789{
790 struct sigevent sev;
Dmitry V. Levind3cb3922006-12-13 17:45:02 +0000791
792#if SUPPORTED_PERSONALITIES > 1
793 if (personality_wordsize[current_personality] == 4)
794 {
795 printsigevent32(tcp, arg);
796 return;
797 }
798#endif
Roland McGrath1e356792003-03-30 23:52:28 +0000799 if (umove (tcp, arg, &sev) < 0)
800 tprintf("{...}");
801 else {
Roland McGrath675d4a62004-09-11 08:12:45 +0000802 tprintf("{%p, ", sev.sigev_value.sival_ptr);
803 if (sev.sigev_notify == SIGEV_SIGNAL)
804 tprintf("%s, ", signame(sev.sigev_signo));
805 else
806 tprintf("%u, ", sev.sigev_signo);
Roland McGrath1e356792003-03-30 23:52:28 +0000807 printxval(sigev_value, sev.sigev_notify+1, "SIGEV_???");
808 tprintf(", ");
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
812 struct. */
813 tprintf("{%d}", sev._sigev_un._pad[0]);
Roland McGrathd4c85eb2004-04-16 21:48:44 +0000814 else if (sev.sigev_notify == SIGEV_THREAD)
815 tprintf("{%p, %p}", sev.sigev_notify_function,
816 sev.sigev_notify_attributes);
Roland McGrath1e356792003-03-30 23:52:28 +0000817 else
818 tprintf("{...}");
819 tprintf("}");
820 }
821}
822
823int
824sys_timer_create(tcp)
825struct tcb *tcp;
826{
827 if (entering(tcp)) {
Roland McGrath675d4a62004-09-11 08:12:45 +0000828 printxval(clocknames, tcp->u_arg[0], "CLOCK_???");
829 tprintf(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000830 printsigevent(tcp, tcp->u_arg[1]);
831 tprintf(", ");
832 } else {
Dmitry V. Levinac518d12006-12-13 17:03:02 +0000833 void *p;
834
835 if (syserror(tcp) || umove(tcp, tcp->u_arg[2], &p) < 0)
Roland McGrath1e356792003-03-30 23:52:28 +0000836 tprintf("%#lx", tcp->u_arg[2]);
Dmitry V. Levinac518d12006-12-13 17:03:02 +0000837 else
Roland McGrath1e356792003-03-30 23:52:28 +0000838 tprintf("{%p}", p);
Roland McGrath1e356792003-03-30 23:52:28 +0000839 }
840 return 0;
841}
842
843int
844sys_timer_settime(tcp)
845struct tcb *tcp;
846{
847 if (entering(tcp)) {
848 tprintf("%#lx, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000849 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Roland McGrath1e356792003-03-30 23:52:28 +0000850 tprintf(", ");
851 printitv(tcp, tcp->u_arg[2]);
852 tprintf(", ");
853 } else {
854 if (syserror(tcp))
855 tprintf("%#lx", tcp->u_arg[3]);
856 else
857 printitv(tcp, tcp->u_arg[3]);
858 }
859 return 0;
860}
861
862int
863sys_timer_gettime(tcp)
864struct tcb *tcp;
865{
866 if (entering(tcp)) {
867 tprintf("%#lx, ", tcp->u_arg[0]);
868 } else {
869 if (syserror(tcp))
870 tprintf("%#lx", tcp->u_arg[1]);
871 else
872 printitv(tcp, tcp->u_arg[1]);
873 }
874 return 0;
875}
Roland McGrathd83c50b2004-10-06 22:27:43 +0000876
877static void
878print_rtc(tcp, rt)
879struct tcb *tcp;
880const struct rtc_time *rt;
881{
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);
886 if (!abbrev(tcp))
887 tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
888 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
889 else
890 tprintf("...}");
891}
892
893int
894rtc_ioctl(tcp, code, arg)
895struct tcb *tcp;
896long code;
897long arg;
898{
899 switch (code) {
900 case RTC_ALM_SET:
901 case RTC_SET_TIME:
902 if (entering(tcp)) {
903 struct rtc_time rt;
904 if (umove(tcp, arg, &rt) < 0)
905 tprintf(", %#lx", arg);
906 else {
907 tprintf(", ");
908 print_rtc(tcp, &rt);
909 }
910 }
911 break;
912 case RTC_ALM_READ:
913 case RTC_RD_TIME:
914 if (exiting(tcp)) {
915 struct rtc_time rt;
916 if (syserror(tcp) || umove(tcp, arg, &rt) < 0)
917 tprintf(", %#lx", arg);
918 else {
919 tprintf(", ");
920 print_rtc(tcp, &rt);
921 }
922 }
923 break;
924 case RTC_IRQP_SET:
925 case RTC_EPOCH_SET:
926 if (entering(tcp))
927 tprintf(", %lu", arg);
928 break;
929 case RTC_IRQP_READ:
930 case RTC_EPOCH_READ:
931 if (exiting(tcp))
932 tprintf(", %lu", arg);
933 break;
934 case RTC_WKALM_SET:
935 if (entering(tcp)) {
936 struct rtc_wkalrm wk;
937 if (umove(tcp, arg, &wk) < 0)
938 tprintf(", %#lx", arg);
939 else {
940 tprintf(", {enabled=%d, pending=%d, ",
941 wk.enabled, wk.pending);
942 print_rtc(tcp, &wk.time);
943 tprintf("}");
944 }
945 }
946 break;
947 case RTC_WKALM_RD:
948 if (exiting(tcp)) {
949 struct rtc_wkalrm wk;
950 if (syserror(tcp) || umove(tcp, arg, &wk) < 0)
951 tprintf(", %#lx", arg);
952 else {
953 tprintf(", {enabled=%d, pending=%d, ",
954 wk.enabled, wk.pending);
955 print_rtc(tcp, &wk.time);
956 tprintf("}");
957 }
958 }
959 break;
960 default:
961 if (entering(tcp))
962 tprintf(", %#lx", arg);
963 break;
964 }
965 return 1;
966}
Roland McGrathe4662342007-08-02 01:25:34 +0000967
968#ifndef TFD_TIMER_ABSTIME
969#define TFD_TIMER_ABSTIME (1 << 0)
970#endif
971
972static const struct xlat timerfdflags[] = {
973 { TFD_TIMER_ABSTIME, "TFD_TIMER_ABSTIME" },
974 { 0, NULL }
975};
976
977int
978sys_timerfd(tcp)
979struct tcb *tcp;
980{
981 if (entering(tcp)) {
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_???");
985 tprintf(", ");
986 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
987 tprintf(", ");
988 printitv(tcp, tcp->u_arg[3]);
989 }
990 return 0;
991}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000992#endif /* LINUX */