Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 28 | #include "defs.h" |
| 29 | |
Dmitry V. Levin | ba40d85 | 2015-09-17 16:10:53 +0000 | [diff] [blame] | 30 | #include DEF_MPERS_TYPE(time_t) |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 31 | #include DEF_MPERS_TYPE(timespec_t) |
| 32 | #include DEF_MPERS_TYPE(timeval_t) |
| 33 | |
| 34 | typedef struct timespec timespec_t; |
| 35 | typedef struct timeval timeval_t; |
| 36 | |
| 37 | #include MPERS_DEFS |
| 38 | |
| 39 | #ifndef UTIME_NOW |
| 40 | # define UTIME_NOW ((1l << 30) - 1l) |
| 41 | #endif |
| 42 | #ifndef UTIME_OMIT |
| 43 | # define UTIME_OMIT ((1l << 30) - 2l) |
| 44 | #endif |
| 45 | |
Dmitry V. Levin | 207ba11 | 2015-09-17 16:47:03 +0000 | [diff] [blame] | 46 | static const char time_fmt[] = "{%jd, %jd}"; |
| 47 | |
| 48 | static void |
| 49 | print_timespec_t(const timespec_t *t) |
| 50 | { |
| 51 | tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_nsec); |
| 52 | } |
| 53 | |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 54 | static void |
Dmitry V. Levin | 5eb2362 | 2015-09-17 15:12:42 +0000 | [diff] [blame] | 55 | print_timespec_t_utime(const timespec_t *t) |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 56 | { |
| 57 | switch (t->tv_nsec) { |
| 58 | case UTIME_NOW: |
| 59 | tprints("UTIME_NOW"); |
| 60 | break; |
| 61 | case UTIME_OMIT: |
| 62 | tprints("UTIME_OMIT"); |
| 63 | break; |
| 64 | default: |
Dmitry V. Levin | 207ba11 | 2015-09-17 16:47:03 +0000 | [diff] [blame] | 65 | print_timespec_t(t); |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 66 | break; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | static void |
Dmitry V. Levin | 5eb2362 | 2015-09-17 15:12:42 +0000 | [diff] [blame] | 71 | print_timeval_t(const timeval_t *t) |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 72 | { |
Dmitry V. Levin | 207ba11 | 2015-09-17 16:47:03 +0000 | [diff] [blame] | 73 | tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec); |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 74 | } |
| 75 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 76 | MPERS_PRINTER_DECL(void, print_timespec, |
| 77 | struct tcb *tcp, const long addr) |
Dmitry V. Levin | 5938526 | 2015-09-18 15:16:11 +0000 | [diff] [blame] | 78 | { |
| 79 | timespec_t t; |
| 80 | |
| 81 | if (umove_or_printaddr(tcp, addr, &t)) |
| 82 | return; |
| 83 | |
| 84 | print_timespec_t(&t); |
| 85 | } |
| 86 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 87 | MPERS_PRINTER_DECL(const char *, sprint_timespec, |
| 88 | struct tcb *tcp, const long addr) |
Dmitry V. Levin | 2950de3 | 2015-09-18 17:44:16 +0000 | [diff] [blame] | 89 | { |
| 90 | timespec_t t; |
| 91 | static char buf[sizeof(time_fmt) + 3 * sizeof(t)]; |
| 92 | |
| 93 | if (!addr) { |
| 94 | strcpy(buf, "NULL"); |
| 95 | } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) || |
| 96 | umove(tcp, addr, &t)) { |
| 97 | snprintf(buf, sizeof(buf), "%#lx", addr); |
| 98 | } else { |
| 99 | snprintf(buf, sizeof(buf), time_fmt, |
| 100 | (intmax_t) t.tv_sec, (intmax_t) t.tv_nsec); |
| 101 | } |
| 102 | |
| 103 | return buf; |
| 104 | } |
| 105 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 106 | MPERS_PRINTER_DECL(void, print_timespec_utime_pair, |
| 107 | struct tcb *tcp, const long addr) |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 108 | { |
| 109 | timespec_t t[2]; |
| 110 | |
| 111 | if (umove_or_printaddr(tcp, addr, &t)) |
| 112 | return; |
| 113 | |
| 114 | tprints("["); |
Dmitry V. Levin | 5eb2362 | 2015-09-17 15:12:42 +0000 | [diff] [blame] | 115 | print_timespec_t_utime(&t[0]); |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 116 | tprints(", "); |
Dmitry V. Levin | 5eb2362 | 2015-09-17 15:12:42 +0000 | [diff] [blame] | 117 | print_timespec_t_utime(&t[1]); |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 118 | tprints("]"); |
| 119 | } |
| 120 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 121 | MPERS_PRINTER_DECL(void, print_itimerspec, |
| 122 | struct tcb *tcp, const long addr) |
Dmitry V. Levin | 2206085 | 2015-09-17 16:47:03 +0000 | [diff] [blame] | 123 | { |
| 124 | timespec_t t[2]; |
| 125 | |
| 126 | if (umove_or_printaddr(tcp, addr, &t)) |
| 127 | return; |
| 128 | |
| 129 | tprints("{it_interval="); |
| 130 | print_timespec_t(&t[0]); |
| 131 | tprints(", it_value="); |
| 132 | print_timespec_t(&t[1]); |
| 133 | tprints("}"); |
| 134 | } |
| 135 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 136 | MPERS_PRINTER_DECL(void, print_timeval, |
| 137 | struct tcb *tcp, const long addr) |
Dmitry V. Levin | f1e3a32 | 2015-09-18 15:16:11 +0000 | [diff] [blame] | 138 | { |
| 139 | timeval_t t; |
| 140 | |
| 141 | if (umove_or_printaddr(tcp, addr, &t)) |
| 142 | return; |
| 143 | |
| 144 | print_timeval_t(&t); |
| 145 | } |
| 146 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 147 | MPERS_PRINTER_DECL(void, print_timeval_pair, |
| 148 | struct tcb *tcp, const long addr) |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 149 | { |
| 150 | timeval_t t[2]; |
| 151 | |
| 152 | if (umove_or_printaddr(tcp, addr, &t)) |
| 153 | return; |
| 154 | |
| 155 | tprints("["); |
Dmitry V. Levin | 5eb2362 | 2015-09-17 15:12:42 +0000 | [diff] [blame] | 156 | print_timeval_t(&t[0]); |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 157 | tprints(", "); |
Dmitry V. Levin | 5eb2362 | 2015-09-17 15:12:42 +0000 | [diff] [blame] | 158 | print_timeval_t(&t[1]); |
Dmitry V. Levin | b5a23ed | 2015-08-04 01:52:40 +0300 | [diff] [blame] | 159 | tprints("]"); |
| 160 | } |
Dmitry V. Levin | ba40d85 | 2015-09-17 16:10:53 +0000 | [diff] [blame] | 161 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 162 | MPERS_PRINTER_DECL(const char *, sprint_timeval, |
| 163 | struct tcb *tcp, const long addr) |
Dmitry V. Levin | 4cb5ccc | 2015-09-18 18:02:50 +0000 | [diff] [blame] | 164 | { |
| 165 | timeval_t t; |
| 166 | static char buf[sizeof(time_fmt) + 3 * sizeof(t)]; |
| 167 | |
| 168 | if (!addr) { |
| 169 | strcpy(buf, "NULL"); |
| 170 | } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) || |
| 171 | umove(tcp, addr, &t)) { |
| 172 | snprintf(buf, sizeof(buf), "%#lx", addr); |
| 173 | } else { |
| 174 | snprintf(buf, sizeof(buf), time_fmt, |
| 175 | (intmax_t) t.tv_sec, (intmax_t) t.tv_usec); |
| 176 | } |
| 177 | |
| 178 | return buf; |
| 179 | } |
| 180 | |
Dmitry V. Levin | a8fce09 | 2016-05-21 22:53:06 +0000 | [diff] [blame] | 181 | MPERS_PRINTER_DECL(void, print_itimerval, |
| 182 | struct tcb *tcp, const long addr) |
Dmitry V. Levin | 322be80 | 2015-09-17 20:23:31 +0000 | [diff] [blame] | 183 | { |
| 184 | timeval_t t[2]; |
| 185 | |
| 186 | if (umove_or_printaddr(tcp, addr, &t)) |
| 187 | return; |
| 188 | |
| 189 | tprints("{it_interval="); |
| 190 | print_timeval_t(&t[0]); |
| 191 | tprints(", it_value="); |
| 192 | print_timeval_t(&t[1]); |
| 193 | tprints("}"); |
| 194 | } |
| 195 | |
Dmitry V. Levin | ba40d85 | 2015-09-17 16:10:53 +0000 | [diff] [blame] | 196 | SYS_FUNC(time) |
| 197 | { |
| 198 | if (exiting(tcp)) { |
| 199 | time_t t; |
| 200 | |
| 201 | if (!umove_or_printaddr(tcp, tcp->u_arg[0], &t)) |
| 202 | tprintf("[%jd]", (intmax_t) t); |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
Dmitry V. Levin | 322be80 | 2015-09-17 20:23:31 +0000 | [diff] [blame] | 207 | |
| 208 | #ifdef ALPHA |
| 209 | |
| 210 | typedef struct { |
| 211 | int tv_sec, tv_usec; |
| 212 | } timeval32_t; |
| 213 | |
| 214 | static void |
| 215 | print_timeval32_t(const timeval32_t *t) |
| 216 | { |
| 217 | tprintf(time_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec); |
| 218 | } |
| 219 | |
| 220 | void |
Dmitry V. Levin | f1e3a32 | 2015-09-18 15:16:11 +0000 | [diff] [blame] | 221 | print_timeval32(struct tcb *tcp, const long addr) |
| 222 | { |
| 223 | timeval32_t t; |
| 224 | |
| 225 | if (umove_or_printaddr(tcp, addr, &t)) |
| 226 | return; |
| 227 | |
| 228 | print_timeval32_t(&t); |
| 229 | } |
| 230 | |
| 231 | void |
| 232 | print_timeval32_pair(struct tcb *tcp, const long addr) |
| 233 | { |
| 234 | timeval32_t t[2]; |
| 235 | |
| 236 | if (umove_or_printaddr(tcp, addr, &t)) |
| 237 | return; |
| 238 | |
| 239 | tprints("["); |
| 240 | print_timeval32_t(&t[0]); |
| 241 | tprints(", "); |
| 242 | print_timeval32_t(&t[1]); |
| 243 | tprints("]"); |
| 244 | } |
| 245 | |
| 246 | void |
Dmitry V. Levin | 322be80 | 2015-09-17 20:23:31 +0000 | [diff] [blame] | 247 | print_itimerval32(struct tcb *tcp, const long addr) |
| 248 | { |
| 249 | timeval32_t t[2]; |
| 250 | |
| 251 | if (umove_or_printaddr(tcp, addr, &t)) |
| 252 | return; |
| 253 | |
| 254 | tprints("{it_interval="); |
| 255 | print_timeval32_t(&t[0]); |
| 256 | tprints(", it_value="); |
| 257 | print_timeval32_t(&t[1]); |
| 258 | tprints("}"); |
| 259 | } |
| 260 | |
Dmitry V. Levin | 4cb5ccc | 2015-09-18 18:02:50 +0000 | [diff] [blame] | 261 | const char * |
| 262 | sprint_timeval32(struct tcb *tcp, const long addr) |
| 263 | { |
| 264 | timeval32_t t; |
| 265 | static char buf[sizeof(time_fmt) + 3 * sizeof(t)]; |
| 266 | |
| 267 | if (!addr) { |
| 268 | strcpy(buf, "NULL"); |
| 269 | } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) || |
| 270 | umove(tcp, addr, &t)) { |
| 271 | snprintf(buf, sizeof(buf), "%#lx", addr); |
| 272 | } else { |
| 273 | snprintf(buf, sizeof(buf), time_fmt, |
| 274 | (intmax_t) t.tv_sec, (intmax_t) t.tv_usec); |
| 275 | } |
| 276 | |
| 277 | return buf; |
| 278 | } |
| 279 | |
Dmitry V. Levin | 322be80 | 2015-09-17 20:23:31 +0000 | [diff] [blame] | 280 | #endif /* ALPHA */ |