blob: 963d0ea2a9de3097c6c321855e468a737ce1bf84 [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 Akkermand856b992000-10-13 12:47:12 +000033#include <sys/timex.h>
Roland McGrath6afc5652007-07-24 01:57:11 +000034
Dmitry V. Levinf57edf42015-09-18 16:15:49 +000035static void
36print_timezone(struct tcb *tcp, const long addr)
37{
38 struct timezone tz;
39
40 if (umove_or_printaddr(tcp, addr, &tz))
41 return;
42
43 tprintf("{tz_minuteswest=%d, tz_dsttime=%d}",
44 tz.tz_minuteswest, tz.tz_dsttime);
45}
46
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000047SYS_FUNC(gettimeofday)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000048{
49 if (exiting(tcp)) {
Dmitry V. Levinf1e3a322015-09-18 15:16:11 +000050 print_timeval(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020051 tprints(", ");
Dmitry V. Levinf57edf42015-09-18 16:15:49 +000052 print_timezone(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053 }
54 return 0;
55}
56
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000057#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000058SYS_FUNC(osf_gettimeofday)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000059{
Denys Vlasenko1d632462009-04-14 12:51:00 +000060 if (exiting(tcp)) {
Dmitry V. Levinf1e3a322015-09-18 15:16:11 +000061 print_timeval32(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020062 tprints(", ");
Dmitry V. Levinf57edf42015-09-18 16:15:49 +000063 print_timezone(tcp, tcp->u_arg[1]);
Denys Vlasenko1d632462009-04-14 12:51:00 +000064 }
65 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000066}
67#endif
68
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000069SYS_FUNC(settimeofday)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000070{
Dmitry V. Levinf1e3a322015-09-18 15:16:11 +000071 print_timeval(tcp, tcp->u_arg[0]);
Dmitry V. Levin76c8f662015-07-16 21:07:06 +000072 tprints(", ");
Dmitry V. Levinf57edf42015-09-18 16:15:49 +000073 print_timezone(tcp, tcp->u_arg[1]);
Dmitry V. Levin76c8f662015-07-16 21:07:06 +000074
75 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076}
77
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000078#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000079SYS_FUNC(osf_settimeofday)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000080{
Dmitry V. Levinf1e3a322015-09-18 15:16:11 +000081 print_timeval32(tcp, tcp->u_arg[0]);
Dmitry V. Levin76c8f662015-07-16 21:07:06 +000082 tprints(", ");
Dmitry V. Levinf57edf42015-09-18 16:15:49 +000083 print_timezone(tcp, tcp->u_arg[1]);
Dmitry V. Levin76c8f662015-07-16 21:07:06 +000084
85 return RVAL_DECODED;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000086}
87#endif
88
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000089SYS_FUNC(nanosleep)
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +000090{
91 if (entering(tcp)) {
92 print_timespec(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020093 tprints(", ");
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +000094 } else {
Dmitry V. Levin9af94a22015-09-18 01:54:59 +000095
96 /*
97 * Second (returned) timespec is only significant if syscall
98 * was interrupted. On success and in case of other errors we
99 * print only its address, since kernel doesn't modify it,
Denys Vlasenko47932212013-06-30 23:53:49 +0200100 * and printing the value may show uninitialized data.
Denys Vlasenko64acaa12012-01-28 02:29:36 +0100101 */
Dmitry V. Levin9af94a22015-09-18 01:54:59 +0000102 if (is_erestart(tcp)) {
103 temporarily_clear_syserror(tcp);
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000104 print_timespec(tcp, tcp->u_arg[1]);
Dmitry V. Levin9af94a22015-09-18 01:54:59 +0000105 restore_cleared_syserror(tcp);
106 } else {
107 printaddr(tcp->u_arg[1]);
Denys Vlasenko47932212013-06-30 23:53:49 +0200108 }
Dmitry V. Levin2e55ff42008-09-03 01:02:46 +0000109 }
110 return 0;
111}
112
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000113#include "xlat/itimer_which.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000114
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000115SYS_FUNC(getitimer)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000116{
117 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000118 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200119 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000120 } else {
Dmitry V. Levin322be802015-09-17 20:23:31 +0000121 print_itimerval(tcp, tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000122 }
123 return 0;
124}
125
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000126#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000127SYS_FUNC(osf_getitimer)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000128{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000129 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000130 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200131 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000132 } else {
Dmitry V. Levin322be802015-09-17 20:23:31 +0000133 print_itimerval32(tcp, tcp->u_arg[1]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000134 }
135 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000136}
137#endif
138
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000139SYS_FUNC(setitimer)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140{
141 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000142 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200143 tprints(", ");
Dmitry V. Levin322be802015-09-17 20:23:31 +0000144 print_itimerval(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200145 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146 } else {
Dmitry V. Levin322be802015-09-17 20:23:31 +0000147 print_itimerval(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148 }
149 return 0;
150}
151
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000152#ifdef ALPHA
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000153SYS_FUNC(osf_setitimer)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000154{
Denys Vlasenko1d632462009-04-14 12:51:00 +0000155 if (entering(tcp)) {
Dmitry V. Levin297b5942014-04-25 23:39:20 +0000156 printxval(itimer_which, tcp->u_arg[0], "ITIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200157 tprints(", ");
Dmitry V. Levin322be802015-09-17 20:23:31 +0000158 print_itimerval32(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200159 tprints(", ");
Denys Vlasenko1d632462009-04-14 12:51:00 +0000160 } else {
Dmitry V. Levin322be802015-09-17 20:23:31 +0000161 print_itimerval32(tcp, tcp->u_arg[2]);
Denys Vlasenko1d632462009-04-14 12:51:00 +0000162 }
163 return 0;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000164}
165#endif
166
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000167#include "xlat/adjtimex_state.h"
Dmitry V. Levin1a684d62006-12-13 17:42:32 +0000168
Dmitry V. Levin73215472012-03-11 21:25:51 +0000169static int
170do_adjtimex(struct tcb *tcp, long addr)
171{
Dmitry V. Levindad1eef2015-09-16 21:58:36 +0000172 if (print_timex(tcp, addr))
Dmitry V. Levin73215472012-03-11 21:25:51 +0000173 return 0;
Dmitry V. Levin9134aab2016-05-14 21:46:05 +0000174 tcp->auxstr = xlookup(adjtimex_state, (unsigned long) tcp->u_rval);
Dmitry V. Levin73215472012-03-11 21:25:51 +0000175 if (tcp->auxstr)
176 return RVAL_STR;
177 return 0;
178}
179
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000180SYS_FUNC(adjtimex)
Dmitry V. Levin165b15d2006-12-13 17:43:45 +0000181{
Dmitry V. Levin73215472012-03-11 21:25:51 +0000182 if (exiting(tcp))
183 return do_adjtimex(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184 return 0;
185}
Roland McGrath1e356792003-03-30 23:52:28 +0000186
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000187#include "xlat/clockflags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000188#include "xlat/clocknames.h"
Roland McGrath54a4edd2004-08-31 06:52:45 +0000189
Stefan Sørensena5fea902014-02-03 10:01:27 +0100190static void
191printclockname(int clockid)
192{
193#ifdef CLOCKID_TO_FD
Dmitry V. Levind35bdca2014-04-26 18:10:19 +0000194# include "xlat/cpuclocknames.h"
195
Stefan Sørensena5fea902014-02-03 10:01:27 +0100196 if (clockid < 0) {
197 if ((clockid & CLOCKFD_MASK) == CLOCKFD)
198 tprintf("FD_TO_CLOCKID(%d)", CLOCKID_TO_FD(clockid));
199 else {
200 if(CPUCLOCK_PERTHREAD(clockid))
201 tprintf("MAKE_THREAD_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
202 else
203 tprintf("MAKE_PROCESS_CPUCLOCK(%d,", CPUCLOCK_PID(clockid));
204 printxval(cpuclocknames, clockid & CLOCKFD_MASK, "CPUCLOCK_???");
205 tprints(")");
206 }
207 }
208 else
209#endif
210 printxval(clocknames, clockid, "CLOCK_???");
211}
212
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000213SYS_FUNC(clock_settime)
Roland McGrath1e356792003-03-30 23:52:28 +0000214{
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000215 printclockname(tcp->u_arg[0]);
216 tprints(", ");
Dmitry V. Levin59385262015-09-18 15:16:11 +0000217 print_timespec(tcp, tcp->u_arg[1]);
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000218
219 return RVAL_DECODED;
Roland McGrath1e356792003-03-30 23:52:28 +0000220}
221
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000222SYS_FUNC(clock_gettime)
Roland McGrath1e356792003-03-30 23:52:28 +0000223{
224 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100225 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200226 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000227 } else {
Dmitry V. Levin59385262015-09-18 15:16:11 +0000228 print_timespec(tcp, tcp->u_arg[1]);
Roland McGrath1e356792003-03-30 23:52:28 +0000229 }
230 return 0;
231}
232
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000233SYS_FUNC(clock_nanosleep)
Roland McGrath1e356792003-03-30 23:52:28 +0000234{
235 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100236 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200237 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000238 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200239 tprints(", ");
Dmitry V. Levin59385262015-09-18 15:16:11 +0000240 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200241 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000242 } else {
Dmitry V. Levinc648b4a2015-09-18 14:24:51 +0000243 /*
244 * Second (returned) timespec is only significant
245 * if syscall was interrupted and flags is not TIMER_ABSTIME.
246 */
247 if (!tcp->u_arg[1] && is_erestart(tcp)) {
248 temporarily_clear_syserror(tcp);
Dmitry V. Levin59385262015-09-18 15:16:11 +0000249 print_timespec(tcp, tcp->u_arg[3]);
Dmitry V. Levinc648b4a2015-09-18 14:24:51 +0000250 restore_cleared_syserror(tcp);
251 } else {
252 printaddr(tcp->u_arg[3]);
253 }
Roland McGrath1e356792003-03-30 23:52:28 +0000254 }
255 return 0;
256}
257
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000258SYS_FUNC(clock_adjtime)
Dmitry V. Levin73215472012-03-11 21:25:51 +0000259{
260 if (exiting(tcp))
261 return do_adjtimex(tcp, tcp->u_arg[1]);
Stefan Sørensena5fea902014-02-03 10:01:27 +0100262 printclockname(tcp->u_arg[0]);
Dmitry V. Levin73215472012-03-11 21:25:51 +0000263 tprints(", ");
264 return 0;
265}
266
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000267SYS_FUNC(timer_create)
Roland McGrath1e356792003-03-30 23:52:28 +0000268{
269 if (entering(tcp)) {
Stefan Sørensena5fea902014-02-03 10:01:27 +0100270 printclockname(tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200271 tprints(", ");
Dmitry V. Levin6f950cc2015-09-16 16:31:43 +0000272 print_sigevent(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200273 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000274 } else {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000275 printnum_int(tcp, tcp->u_arg[2], "%d");
Roland McGrath1e356792003-03-30 23:52:28 +0000276 }
277 return 0;
278}
279
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000280SYS_FUNC(timer_settime)
Roland McGrath1e356792003-03-30 23:52:28 +0000281{
282 if (entering(tcp)) {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000283 tprintf("%d, ", (int) tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000284 printflags(clockflags, tcp->u_arg[1], "TIMER_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200285 tprints(", ");
Dmitry V. Levin22060852015-09-17 16:47:03 +0000286 print_itimerspec(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200287 tprints(", ");
Roland McGrath1e356792003-03-30 23:52:28 +0000288 } else {
Dmitry V. Levin22060852015-09-17 16:47:03 +0000289 print_itimerspec(tcp, tcp->u_arg[3]);
Roland McGrath1e356792003-03-30 23:52:28 +0000290 }
291 return 0;
292}
293
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000294SYS_FUNC(timer_gettime)
Roland McGrath1e356792003-03-30 23:52:28 +0000295{
296 if (entering(tcp)) {
Dmitry V. Levin71178352015-07-16 18:18:09 +0000297 tprintf("%d, ", (int) tcp->u_arg[0]);
Roland McGrath1e356792003-03-30 23:52:28 +0000298 } else {
Dmitry V. Levin22060852015-09-17 16:47:03 +0000299 print_itimerspec(tcp, tcp->u_arg[1]);
Roland McGrath1e356792003-03-30 23:52:28 +0000300 }
301 return 0;
302}
Roland McGrathd83c50b2004-10-06 22:27:43 +0000303
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000304#include "xlat/timerfdflags.h"
Roland McGrathe4662342007-08-02 01:25:34 +0000305
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000306SYS_FUNC(timerfd_create)
Roland McGrathde328e62008-05-20 04:56:13 +0000307{
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000308 printclockname(tcp->u_arg[0]);
309 tprints(", ");
310 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
311
Dmitry V. Levin07c878a2015-08-02 01:37:19 +0000312 return RVAL_DECODED | RVAL_FD;
Roland McGrathde328e62008-05-20 04:56:13 +0000313}
314
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000315SYS_FUNC(timerfd_settime)
Roland McGrathde328e62008-05-20 04:56:13 +0000316{
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000317 printfd(tcp, tcp->u_arg[0]);
318 tprints(", ");
319 printflags(timerfdflags, tcp->u_arg[1], "TFD_???");
320 tprints(", ");
Dmitry V. Levin22060852015-09-17 16:47:03 +0000321 print_itimerspec(tcp, tcp->u_arg[2]);
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000322 tprints(", ");
Dmitry V. Levin22060852015-09-17 16:47:03 +0000323 print_itimerspec(tcp, tcp->u_arg[3]);
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000324
325 return RVAL_DECODED;
Roland McGrathde328e62008-05-20 04:56:13 +0000326}
327
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000328SYS_FUNC(timerfd_gettime)
Roland McGrathde328e62008-05-20 04:56:13 +0000329{
330 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300331 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200332 tprints(", ");
Dmitry V. Levin76c8f662015-07-16 21:07:06 +0000333 } else {
Dmitry V. Levin22060852015-09-17 16:47:03 +0000334 print_itimerspec(tcp, tcp->u_arg[1]);
Roland McGrathde328e62008-05-20 04:56:13 +0000335 }
336 return 0;
337}