2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
3 * Copyright (c) 2016-2018 The strace developers.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include DEF_MPERS_TYPE(timespec_t)
33 typedef struct timespec timespec_t;
40 # define UTIME_NOW ((1l << 30) - 1l)
43 # define UTIME_OMIT ((1l << 30) - 2l)
46 static const char timespec_fmt[] = "{tv_sec=%lld, tv_nsec=%llu}";
49 print_timespec_t(const timespec_t *t)
51 tprintf(timespec_fmt, (long long) t->tv_sec,
52 zero_extend_signed_to_ull(t->tv_nsec));
56 print_timespec_t_utime(const timespec_t *t)
63 tprints("UTIME_OMIT");
67 tprints_comment(sprinttime_nsec(t->tv_sec,
68 zero_extend_signed_to_ull(t->tv_nsec)));
73 MPERS_PRINTER_DECL(bool, print_struct_timespec_data_size,
74 const void *arg, const size_t size)
76 if (size < sizeof(timespec_t)) {
81 print_timespec_t(arg);
85 MPERS_PRINTER_DECL(bool, print_struct_timespec_array_data_size,
86 const void *arg, const unsigned int nmemb,
89 const timespec_t *ts = arg;
92 if (nmemb > size / sizeof(timespec_t)) {
99 for (i = 0; i < nmemb; i++) {
102 print_timespec_t(&ts[i]);
109 MPERS_PRINTER_DECL(void, print_timespec,
110 struct tcb *const tcp, const kernel_ulong_t addr)
114 if (umove_or_printaddr(tcp, addr, &t))
117 print_timespec_t(&t);
120 MPERS_PRINTER_DECL(const char *, sprint_timespec,
121 struct tcb *const tcp, const kernel_ulong_t addr)
124 static char buf[sizeof(timespec_fmt) + 3 * sizeof(t)];
128 } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
129 umove(tcp, addr, &t)) {
130 xsprintf(buf, "%#" PRI_klx, addr);
132 xsprintf(buf, timespec_fmt,
133 (long long) t.tv_sec,
134 zero_extend_signed_to_ull(t.tv_nsec));
140 MPERS_PRINTER_DECL(void, print_timespec_utime_pair,
141 struct tcb *const tcp, const kernel_ulong_t addr)
145 if (umove_or_printaddr(tcp, addr, &t))
149 print_timespec_t_utime(&t[0]);
151 print_timespec_t_utime(&t[1]);
155 MPERS_PRINTER_DECL(void, print_itimerspec,
156 struct tcb *const tcp, const kernel_ulong_t addr)
160 if (umove_or_printaddr(tcp, addr, &t))
163 tprints("{it_interval=");
164 print_timespec_t(&t[0]);
165 tprints(", it_value=");
166 print_timespec_t(&t[1]);