]> granicus.if.org Git - strace/blob - print_timeval.c
Fix the length argument passed from print_iovec to decode_netlink
[strace] / print_timeval.c
1 /*
2  * Copyright (c) 2015-2017 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
28 #include "defs.h"
29
30 #include DEF_MPERS_TYPE(timeval_t)
31
32 typedef struct timeval timeval_t;
33
34 #include MPERS_DEFS
35
36 static const char timeval_fmt[]  = "{tv_sec=%jd, tv_usec=%jd}";
37
38 static void
39 print_timeval_t(const timeval_t *t)
40 {
41         tprintf(timeval_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
42 }
43
44 MPERS_PRINTER_DECL(void, print_struct_timeval, const void *arg)
45 {
46         print_timeval_t(arg);
47 }
48
49 MPERS_PRINTER_DECL(void, print_timeval,
50                    struct tcb *const tcp, const kernel_ulong_t addr)
51 {
52         timeval_t t;
53
54         if (umove_or_printaddr(tcp, addr, &t))
55                 return;
56
57         print_timeval_t(&t);
58 }
59
60 MPERS_PRINTER_DECL(void, print_timeval_utimes,
61                    struct tcb *const tcp, const kernel_ulong_t addr)
62 {
63         timeval_t t[2];
64
65         if (umove_or_printaddr(tcp, addr, &t))
66                 return;
67
68         tprints("[");
69         print_timeval_t(&t[0]);
70         tprints(", ");
71         print_timeval_t(&t[1]);
72         tprints("]");
73 }
74
75 MPERS_PRINTER_DECL(const char *, sprint_timeval,
76                    struct tcb *const tcp, const kernel_ulong_t addr)
77 {
78         timeval_t t;
79         static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
80
81         if (!addr) {
82                 strcpy(buf, "NULL");
83         } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
84                    umove(tcp, addr, &t)) {
85                 snprintf(buf, sizeof(buf), "%#" PRI_klx, addr);
86         } else {
87                 snprintf(buf, sizeof(buf), timeval_fmt,
88                          (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);
89         }
90
91         return buf;
92 }
93
94 MPERS_PRINTER_DECL(void, print_itimerval,
95                    struct tcb *const tcp, const kernel_ulong_t addr)
96 {
97         timeval_t t[2];
98
99         if (umove_or_printaddr(tcp, addr, &t))
100                 return;
101
102         tprints("{it_interval=");
103         print_timeval_t(&t[0]);
104         tprints(", it_value=");
105         print_timeval_t(&t[1]);
106         tprints("}");
107 }
108
109 #ifdef ALPHA
110
111 void
112 print_timeval32_t(const timeval32_t *t)
113 {
114         tprintf(timeval_fmt, (intmax_t) t->tv_sec, (intmax_t) t->tv_usec);
115 }
116
117 void
118 print_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
119 {
120         timeval32_t t;
121
122         if (umove_or_printaddr(tcp, addr, &t))
123                 return;
124
125         print_timeval32_t(&t);
126 }
127
128 void
129 print_timeval32_utimes(struct tcb *const tcp, const kernel_ulong_t addr)
130 {
131         timeval32_t t[2];
132
133         if (umove_or_printaddr(tcp, addr, &t))
134                 return;
135
136         tprints("[");
137         print_timeval32_t(&t[0]);
138         tprints(", ");
139         print_timeval32_t(&t[1]);
140         tprints("]");
141 }
142
143 void
144 print_itimerval32(struct tcb *const tcp, const kernel_ulong_t addr)
145 {
146         timeval32_t t[2];
147
148         if (umove_or_printaddr(tcp, addr, &t))
149                 return;
150
151         tprints("{it_interval=");
152         print_timeval32_t(&t[0]);
153         tprints(", it_value=");
154         print_timeval32_t(&t[1]);
155         tprints("}");
156 }
157
158 const char *
159 sprint_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
160 {
161         timeval32_t t;
162         static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
163
164         if (!addr) {
165                 strcpy(buf, "NULL");
166         } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
167                    umove(tcp, addr, &t)) {
168                 snprintf(buf, sizeof(buf), "%#" PRI_klx, addr);
169         } else {
170                 snprintf(buf, sizeof(buf), timeval_fmt,
171                          (intmax_t) t.tv_sec, (intmax_t) t.tv_usec);
172         }
173
174         return buf;
175 }
176
177 #endif /* ALPHA */