blob: 91e091584272b876c1158bf509bbf90a344a5842 [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000028 */
29
30#include "defs.h"
Mike Frysingerf1639d82014-12-30 19:08:50 -050031#include <fcntl.h>
Dmitry V. Levin0e946ab2015-07-17 23:56:54 +000032#include <signal.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000033#include <linux/version.h>
Wichert Akkermand856b992000-10-13 12:47:12 +000034#include <sys/timex.h>
Roland McGrath6afc5652007-07-24 01:57:11 +000035
36#ifndef UTIME_NOW
37#define UTIME_NOW ((1l << 30) - 1l)
38#endif
39#ifndef UTIME_OMIT
40#define UTIME_OMIT ((1l << 30) - 2l)
41#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042
Dmitry V. Levine61086f2015-02-27 21:46:42 +000043#if SUPPORTED_PERSONALITIES > 1
44# if defined X86_64 || defined X32
45# define current_time_t_is_compat (current_personality == 1)
46# else
47# define current_time_t_is_compat (current_wordsize == 4)
48# endif
Dmitry V. Levinf9b455c2015-08-18 13:25:36 +000049# define current_time_t_is_int32 current_time_t_is_compat
Dmitry V. Levine61086f2015-02-27 21:46:42 +000050#else
51# define current_time_t_is_compat 0
Dmitry V. Levinf9b455c2015-08-18 13:25:36 +000052# define current_time_t_is_int32 (sizeof(time_t) == 4)
Dmitry V. Levine61086f2015-02-27 21:46:42 +000053#endif
54
Dmitry V. Levina7945a32006-12-13 17:10:11 +000055struct timeval32
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056{
Dmitry V. Levina7945a32006-12-13 17:10:11 +000057 u_int32_t tv_sec, tv_usec;
58};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +000060static void
61tprint_timeval32(struct tcb *tcp, const struct timeval32 *tv)
62{
63 tprintf("{%u, %u}", tv->tv_sec, tv->tv_usec);
64}
65
66static void
67tprint_timeval(struct tcb *tcp, const struct timeval *tv)
68{
Dmitry V. Levine61086f2015-02-27 21:46:42 +000069 tprintf("{%ju, %ju}", (uintmax_t) tv->tv_sec, (uintmax_t) tv->tv_usec);
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +000070}
71
Dmitry V. Levina7945a32006-12-13 17:10:11 +000072void
Roland McGrath6afc5652007-07-24 01:57:11 +000073printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
Dmitry V. Levina7945a32006-12-13 17:10:11 +000074{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +010075 char buf[TIMEVAL_TEXT_BUFSIZE];
76 sprinttv(buf, tcp, addr, bitness, special);
77 tprints(buf);
Dmitry V. Levina7945a32006-12-13 17:10:11 +000078}
Wichert Akkerman221f54f1999-11-18 17:26:45 +000079
Dmitry V. Levinee21a5b2014-12-26 23:55:38 +000080static char *
Dmitry V. Levine61086f2015-02-27 21:46:42 +000081do_sprinttv(char *buf, const uintmax_t sec, const uintmax_t usec,
Dmitry V. Levinee21a5b2014-12-26 23:55:38 +000082 const int special)
83{
84 if (special) {
85 switch (usec) {
86 case UTIME_NOW:
87 return stpcpy(buf, "UTIME_NOW");
88 case UTIME_OMIT:
89 return stpcpy(buf, "UTIME_OMIT");
90 }
91 }
Dmitry V. Levine61086f2015-02-27 21:46:42 +000092 return buf + sprintf(buf, "{%ju, %ju}", sec, usec);
Dmitry V. Levinee21a5b2014-12-26 23:55:38 +000093}
94
Denys Vlasenko2fb4db32011-08-31 12:26:03 +020095char *
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +010096sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000097{
Dmitry V. Levina7945a32006-12-13 17:10:11 +000098 if (addr == 0)
Denys Vlasenko2fb4db32011-08-31 12:26:03 +020099 return stpcpy(buf, "NULL");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000100
Dmitry V. Levin9f702732015-07-16 16:22:07 +0000101 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
Denys Vlasenkob9c7ae62011-09-01 11:40:40 +0200102 return buf + sprintf(buf, "%#lx", addr);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200103
Dmitry V. Levine61086f2015-02-27 21:46:42 +0000104 if (bitness == BITNESS_32 || current_time_t_is_compat)
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200105 {
106 struct timeval32 tv;
107
Dmitry V. Levinee21a5b2014-12-26 23:55:38 +0000108 if (umove(tcp, addr, &tv) >= 0)
109 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200110 } else {
111 struct timeval tv;
112
Dmitry V. Levinee21a5b2014-12-26 23:55:38 +0000113 if (umove(tcp, addr, &tv) >= 0)
114 return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200115 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200116
Dmitry V. Levin9f702732015-07-16 16:22:07 +0000117 return buf + sprintf(buf, "%#lx", addr);
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000118}
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000119
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100120void
121print_timespec(struct tcb *tcp, long addr)
Roland McGrath6bc09da2007-11-01 21:50:54 +0000122{
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100123 char buf[TIMESPEC_TEXT_BUFSIZE];
124 sprint_timespec(buf, tcp, addr);
125 tprints(buf);
Roland McGrath6bc09da2007-11-01 21:50:54 +0000126}
127
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100128void
129sprint_timespec(char *buf, struct tcb *tcp, long addr)
Roland McGrath6bc09da2007-11-01 21:50:54 +0000130{
131 if (addr == 0)
132 strcpy(buf, "NULL");
133 else if (!verbose(tcp))
134 sprintf(buf, "%#lx", addr);
135 else {
Denys Vlasenko1d632462009-04-14 12:51:00 +0000136 int rc;
Roland McGrath6bc09da2007-11-01 21:50:54 +0000137
Denys Vlasenko84703742012-02-25 02:38:52 +0100138#if SUPPORTED_PERSONALITIES > 1
Dmitry V. Levine61086f2015-02-27 21:46:42 +0000139 if (current_time_t_is_compat) {
Roland McGrath6bc09da2007-11-01 21:50:54 +0000140 struct timeval32 tv;
141
Denys Vlasenko5d645812011-08-20 12:48:18 +0200142 rc = umove(tcp, addr, &tv);
143 if (rc >= 0)
Roland McGrath6bc09da2007-11-01 21:50:54 +0000144 sprintf(buf, "{%u, %u}",
145 tv.tv_sec, tv.tv_usec);
146 } else
Roland McGrath6bc09da2007-11-01 21:50:54 +0000147#endif
Denys Vlasenko1d632462009-04-14 12:51:00 +0000148 {
Roland McGrath6bc09da2007-11-01 21:50:54 +0000149 struct timespec ts;
150
Denys Vlasenko5d645812011-08-20 12:48:18 +0200151 rc = umove(tcp, addr, &ts);
152 if (rc >= 0)
Dmitry V. Levine61086f2015-02-27 21:46:42 +0000153 sprintf(buf, "{%ju, %ju}",
154 (uintmax_t) ts.tv_sec,
155 (uintmax_t) ts.tv_nsec);
Roland McGrath6bc09da2007-11-01 21:50:54 +0000156 }
Roland McGrath6bc09da2007-11-01 21:50:54 +0000157 if (rc < 0)
158 strcpy(buf, "{...}");
159 }
160}
161
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000162SYS_FUNC(time)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163{
164 if (exiting(tcp)) {
Dmitry V. Levinf9b455c2015-08-18 13:25:36 +0000165 if (current_time_t_is_int32)
166 printnum_int(tcp, tcp->u_arg[0], "%d");
167 else
168 printnum_int64(tcp, tcp->u_arg[0], "%" PRId64);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169 }
170 return 0;
171}
172
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000173SYS_FUNC(gettimeofday)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174{
175 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176 printtv(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200177 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000178 printtv(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179 }
180 return 0;
181}
182
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000183#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000184SYS_FUNC(osf_gettimeofday)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000185{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000186 if (exiting(tcp)) {
Denys Vlasenko1d632462009-04-14 12:51:00 +0000187 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200188 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000189 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000190 }
191 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000192}
193#endif
194
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000195SYS_FUNC(settimeofday)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196{
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000197 printtv(tcp, tcp->u_arg[0]);
198 tprints(", ");
199 printtv(tcp, tcp->u_arg[1]);
200
201 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000202}
203
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000204#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000205SYS_FUNC(osf_settimeofday)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000206{
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000207 printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
208 tprints(", ");
209 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
210
211 return RVAL_DECODED;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000212}
213#endif
214
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000215SYS_FUNC(adjtime)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000216{
217 if (entering(tcp)) {
218 printtv(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200219 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000220 } else {
Dmitry V. Levin9f702732015-07-16 16:22:07 +0000221 printtv(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 }
223 return 0;
224}
225
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000226SYS_FUNC(nanosleep)
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000227{
228 if (entering(tcp)) {
229 print_timespec(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200230 tprints(", ");
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000231 } else {
Denys Vlasenko64acaa12012-01-28 02:29:36 +0100232 /* Second (returned) timespec is only significant
Denys Vlasenko47932212013-06-30 23:53:49 +0200233 * if syscall was interrupted. On success, we print
234 * only its address, since kernel doesn't modify it,
235 * and printing the value may show uninitialized data.
Denys Vlasenko64acaa12012-01-28 02:29:36 +0100236 */
Denys Vlasenko47932212013-06-30 23:53:49 +0200237 switch (tcp->u_error) {
238 default:
239 /* Not interrupted (slept entire interval) */
Dmitry V. Levin71178352015-07-16 18:18:09 +0000240 printaddr(tcp->u_arg[1]);
241 break;
Denys Vlasenko47932212013-06-30 23:53:49 +0200242 case ERESTARTSYS:
243 case ERESTARTNOINTR:
244 case ERESTARTNOHAND:
245 case ERESTART_RESTARTBLOCK:
246 /* Interrupted */
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000247 print_timespec(tcp, tcp->u_arg[1]);
Denys Vlasenko47932212013-06-30 23:53:49 +0200248 }
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000249 }
250 return 0;
251}
252
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000253#include "xlat/itimer_which.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000254
255static void
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000256printitv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257{
Dmitry V. Levin71178352015-07-16 18:18:09 +0000258 if (bitness == BITNESS_32 || current_time_t_is_compat) {
259 struct {
260 struct timeval32 it_interval, it_value;
261 } itv;
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000262
Dmitry V. Levin71178352015-07-16 18:18:09 +0000263 if (!umove_or_printaddr(tcp, addr, &itv)) {
264 tprints("{it_interval=");
265 tprint_timeval32(tcp, &itv.it_interval);
266 tprints(", it_value=");
267 tprint_timeval32(tcp, &itv.it_value);
268 tprints("}");
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000269 }
Dmitry V. Levin71178352015-07-16 18:18:09 +0000270 } else {
271 struct itimerval itv;
272
273 if (!umove_or_printaddr(tcp, addr, &itv)) {
274 tprints("{it_interval=");
275 tprint_timeval(tcp, &itv.it_interval);
276 tprints(", it_value=");
277 tprint_timeval(tcp, &itv.it_value);
278 tprints("}");
279 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280 }
281}
282
Dmitry V. Levin1cad25d2006-12-13 17:14:36 +0000283#define printitv(tcp, addr) \
284 printitv_bitness((tcp), (addr), BITNESS_CURRENT)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000285
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000286SYS_FUNC(getitimer)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000287{
288 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000289 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200290 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291 } else {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000292 printitv(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293 }
294 return 0;
295}
296
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000297#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000298SYS_FUNC(osf_getitimer)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000299{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000300 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000301 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200302 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000303 } else {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000304 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000305 }
306 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000307}
308#endif
309
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000310SYS_FUNC(setitimer)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311{
312 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000313 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200314 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000315 printitv(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200316 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317 } else {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000318 printitv(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319 }
320 return 0;
321}
322
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000323#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000324SYS_FUNC(osf_setitimer)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000325{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000326 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000327 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200328 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000329 printitv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200330 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000331 } else {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000332 printitv_bitness(tcp, tcp->u_arg[2], BITNESS_32);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000333 }
334 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000335}
336#endif
337
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000338#include "xlat/adjtimex_modes.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000339#include "xlat/adjtimex_status.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000340#include "xlat/adjtimex_state.h"
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000341
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000342#if SUPPORTED_PERSONALITIES > 1
343static int
344tprint_timex32(struct tcb *tcp, long addr)
345{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000346 struct {
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000347 unsigned int modes;
348 int offset;
349 int freq;
350 int maxerror;
351 int esterror;
352 int status;
353 int constant;
354 int precision;
355 int tolerance;
356 struct timeval32 time;
357 int tick;
358 int ppsfreq;
359 int jitter;
360 int shift;
361 int stabil;
362 int jitcnt;
363 int calcnt;
364 int errcnt;
365 int stbcnt;
366 } tx;
367
Dmitry V. Levin71178352015-07-16 18:18:09 +0000368 if (umove_or_printaddr(tcp, addr, &tx))
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000369 return -1;
370
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200371 tprints("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000372 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000373 tprintf(", offset=%d, freq=%d, maxerror=%d, ",
374 tx.offset, tx.freq, tx.maxerror);
375 tprintf("esterror=%u, status=", tx.esterror);
376 printflags(adjtimex_status, tx.status, "STA_???");
377 tprintf(", constant=%d, precision=%u, ",
378 tx.constant, tx.precision);
379 tprintf("tolerance=%d, time=", tx.tolerance);
380 tprint_timeval32(tcp, &tx.time);
381 tprintf(", tick=%d, ppsfreq=%d, jitter=%d",
382 tx.tick, tx.ppsfreq, tx.jitter);
383 tprintf(", shift=%d, stabil=%d, jitcnt=%d",
384 tx.shift, tx.stabil, tx.jitcnt);
385 tprintf(", calcnt=%d, errcnt=%d, stbcnt=%d",
386 tx.calcnt, tx.errcnt, tx.stbcnt);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200387 tprints("}");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000388 return 0;
389}
390#endif /* SUPPORTED_PERSONALITIES > 1 */
391
392static int
393tprint_timex(struct tcb *tcp, long addr)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394{
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000395 struct timex tx;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000397#if SUPPORTED_PERSONALITIES > 1
Dmitry V. Levine61086f2015-02-27 21:46:42 +0000398 if (current_time_t_is_compat)
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000399 return tprint_timex32(tcp, addr);
400#endif
Dmitry V. Levin71178352015-07-16 18:18:09 +0000401 if (umove_or_printaddr(tcp, addr, &tx))
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000402 return -1;
403
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200404 tprints("{modes=");
Dmitry V. Levin71d70892007-01-13 11:17:38 +0000405 printflags(adjtimex_modes, tx.modes, "ADJ_???");
Dmitry V. Levine61086f2015-02-27 21:46:42 +0000406 tprintf(", offset=%jd, freq=%jd, maxerror=%ju, esterror=%ju, status=",
407 (intmax_t) tx.offset, (intmax_t) tx.freq,
408 (uintmax_t) tx.maxerror, (uintmax_t) tx.esterror);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000409 printflags(adjtimex_status, tx.status, "STA_???");
Dmitry V. Levine61086f2015-02-27 21:46:42 +0000410 tprintf(", constant=%jd, precision=%ju, tolerance=%jd, time=",
411 (intmax_t) tx.constant, (uintmax_t) tx.precision,
412 (intmax_t) tx.tolerance);
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000413 tprint_timeval(tcp, &tx.time);
Dmitry V. Levine61086f2015-02-27 21:46:42 +0000414 tprintf(", tick=%jd, ppsfreq=%jd, jitter=%jd",
415 (intmax_t) tx.tick, (intmax_t) tx.ppsfreq, (intmax_t) tx.jitter);
416 tprintf(", shift=%d, stabil=%jd, jitcnt=%jd",
417 tx.shift, (intmax_t) tx.stabil, (intmax_t) tx.jitcnt);
418 tprintf(", calcnt=%jd, errcnt=%jd, stbcnt=%jd",
419 (intmax_t) tx.calcnt, (intmax_t) tx.errcnt, (intmax_t) tx.stbcnt);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200420 tprints("}");
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000421 return 0;
422}
423
Dmitry V. Levin73215472012-03-11 21:25:51 +0000424static int
425do_adjtimex(struct tcb *tcp, long addr)
426{
Dmitry V. Levin71178352015-07-16 18:18:09 +0000427 if (tprint_timex(tcp, addr))
Dmitry V. Levin73215472012-03-11 21:25:51 +0000428 return 0;
429 tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
430 if (tcp->auxstr)
431 return RVAL_STR;
432 return 0;
433}
434
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000435SYS_FUNC(adjtimex)
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000436{
Dmitry V. Levin73215472012-03-11 21:25:51 +0000437 if (exiting(tcp))
438 return do_adjtimex(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439 return 0;
440}
Roland McGrath1e356792003-03-30 23:52:28 +0000441
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000442#include "xlat/clockflags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000443#include "xlat/clocknames.h"
Roland McGrath54a4edd2004-08-31 06:52:45 +0000444
Stefan Sørensena5fea902014-02-03 10:01:27 +0100445static void
446printclockname(int clockid)
447{
448#ifdef CLOCKID_TO_FD
Dmitry V. Levind35bdca2014-04-26 18:10:19 +0000449# include "xlat/cpuclocknames.h"
450
Stefan Sørensena5fea902014-02-03 10:01:27 +0100451 if (clockid < 0) {
452 if ((clockid & CLOCKFD_MASK) == CLOCKFD)
453 tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
454 else {
455 if(CPUCLOCK_PERTHREAD(clockid))
456 tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
457 else
458 tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
459 printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
460 tprints(")");
461 }
462 }
463 else
464#endif
465 printxval(clocknames, clockid, "CLOCK_???");
466}
467
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000468SYS_FUNC(clock_settime)
Roland McGrath1e356792003-03-30 23:52:28 +0000469{
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000470 printclockname(tcp->u_arg[0]);
471 tprints(", ");
472 printtv(tcp, tcp->u_arg[1]);
473
474 return RVAL_DECODED;
Roland McGrath1e356792003-03-30 23:52:28 +0000475}
476
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000477SYS_FUNC(clock_gettime)
Roland McGrath1e356792003-03-30 23:52:28 +0000478{
479 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100480 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200481 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000482 } else {
Dmitry V. Levin9f702732015-07-16 16:22:07 +0000483 printtv(tcp, tcp->u_arg[1]);
Roland McGrath1e356792003-03-30 23:52:28 +0000484 }
485 return 0;
486}
487
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000488SYS_FUNC(clock_nanosleep)
Roland McGrath1e356792003-03-30 23:52:28 +0000489{
490 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100491 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200492 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000493 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200494 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000495 printtv(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200496 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000497 } else {
Dmitry V. Levin9f702732015-07-16 16:22:07 +0000498 printtv(tcp, tcp->u_arg[3]);
Roland McGrath1e356792003-03-30 23:52:28 +0000499 }
500 return 0;
501}
502
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000503SYS_FUNC(clock_adjtime)
Dmitry V. Levin73215472012-03-11 21:25:51 +0000504{
505 if (exiting(tcp))
506 return do_adjtimex(tcp, tcp->u_arg[1]);
Stefan Sørensena5fea902014-02-03 10:01:27 +0100507 printclockname(tcp->u_arg[0]);
Dmitry V. Levin73215472012-03-11 21:25:51 +0000508 tprints(", ");
509 return 0;
510}
511
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000512SYS_FUNC(timer_create)
Roland McGrath1e356792003-03-30 23:52:28 +0000513{
514 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100515 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200516 tprints(", ");
Dmitry V. Levin6f950cc2015-09-16 16:31:43 +0000517 print_sigevent(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200518 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000519 } else {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000520 printnum_int(tcp, tcp->u_arg[2], "%d");
Roland McGrath1e356792003-03-30 23:52:28 +0000521 }
522 return 0;
523}
524
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000525SYS_FUNC(timer_settime)
Roland McGrath1e356792003-03-30 23:52:28 +0000526{
527 if (entering(tcp)) {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000528 tprintf("%d, ", (int) tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000529 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200530 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000531 printitv(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200532 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000533 } else {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000534 printitv(tcp, tcp->u_arg[3]);
Roland McGrath1e356792003-03-30 23:52:28 +0000535 }
536 return 0;
537}
538
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000539SYS_FUNC(timer_gettime)
Roland McGrath1e356792003-03-30 23:52:28 +0000540{
541 if (entering(tcp)) {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000542 tprintf("%d, ", (int) tcp->u_arg[0]);
Roland McGrath1e356792003-03-30 23:52:28 +0000543 } else {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000544 printitv(tcp, tcp->u_arg[1]);
Roland McGrath1e356792003-03-30 23:52:28 +0000545 }
546 return 0;
547}
Roland McGrathd83c50b2004-10-06 22:27:43 +0000548
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000549#include "xlat/timerfdflags.h"
Roland McGrathe4662342007-08-02 01:25:34 +0000550
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000551SYS_FUNC(timerfd)
Roland McGrathe4662342007-08-02 01:25:34 +0000552{
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000553 /* It does not matter that the kernel uses itimerspec. */
554 tprintf("%ld, ", tcp->u_arg[0]);
555 printclockname(tcp->u_arg[0]);
556 tprints(", ");
557 printflags(timerfdflags, tcp->u_arg[2], "TFD_???");
558 tprints(", ");
559 printitv(tcp, tcp->u_arg[3]);
560
Dmitry V. Levin07c878a2015-08-02 01:37:19 +0000561 return RVAL_DECODED | RVAL_FD;
Roland McGrathe4662342007-08-02 01:25:34 +0000562}
Roland McGrathde328e62008-05-20 04:56:13 +0000563
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000564SYS_FUNC(timerfd_create)
Roland McGrathde328e62008-05-20 04:56:13 +0000565{
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000566 printclockname(tcp->u_arg[0]);
567 tprints(", ");
568 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
569
Dmitry V. Levin07c878a2015-08-02 01:37:19 +0000570 return RVAL_DECODED | RVAL_FD;
Roland McGrathde328e62008-05-20 04:56:13 +0000571}
572
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000573SYS_FUNC(timerfd_settime)
Roland McGrathde328e62008-05-20 04:56:13 +0000574{
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000575 printfd(tcp, tcp->u_arg[0]);
576 tprints(", ");
577 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
578 tprints(", ");
579 printitv(tcp, tcp->u_arg[2]);
580 tprints(", ");
581 printitv(tcp, tcp->u_arg[3]);
582
583 return RVAL_DECODED;
Roland McGrathde328e62008-05-20 04:56:13 +0000584}
585
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000586SYS_FUNC(timerfd_gettime)
Roland McGrathde328e62008-05-20 04:56:13 +0000587{
588 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300589 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200590 tprints(", ");
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000591 } else {
Roland McGrathde328e62008-05-20 04:56:13 +0000592 printitv(tcp, tcp->u_arg[1]);
593 }
594 return 0;
595}