Browse Source

Implement printers for kernel_timespec32_t

They are going to be used to re-implement parsers of syscalls that deal
with 32-bit timespec.

* defs.h (print_timespec32_data_size, print_timespec32_array_data_size,
print_timespec32, sprint_timespec32, print_timespec32_utime_pair,
print_itimerspec32): New prototypes.
* print_timespec.h: New file based on print_timespec.c.
* print_timespec32.c: New file.
* Makefile.am (strace_SOURCES): Add them.
Dmitry V. Levin 6 months ago
parent
commit
f67026dda4
4 changed files with 189 additions and 0 deletions
  1. 2
    0
      Makefile.am
  2. 11
    0
      defs.h
  3. 153
    0
      print_timespec.h
  4. 23
    0
      print_timespec32.c

+ 2
- 0
Makefile.am View File

@@ -243,6 +243,8 @@ strace_SOURCES =	\
243 243
 	print_struct_stat.c \
244 244
 	print_time.c	\
245 245
 	print_timespec.c \
246
+	print_timespec.h \
247
+	print_timespec32.c \
246 248
 	print_timeval.c	\
247 249
 	print_timex.c	\
248 250
 	print_utils.h	\

+ 11
- 0
defs.h View File

@@ -1109,6 +1109,17 @@ tprint_iov(struct tcb *tcp, kernel_ulong_t len, kernel_ulong_t addr,
1109 1109
 	tprint_iov_upto(tcp, len, addr, decode_iov, -1);
1110 1110
 }
1111 1111
 
1112
+# if HAVE_ARCH_TIME32_SYSCALLS
1113
+extern bool print_timespec32_data_size(const void *arg, size_t size);
1114
+extern bool print_timespec32_array_data_size(const void *arg,
1115
+					     unsigned int nmemb,
1116
+					     size_t size);
1117
+extern int print_timespec32(struct tcb *, kernel_ulong_t);
1118
+extern const char *sprint_timespec32(struct tcb *, kernel_ulong_t);
1119
+extern int print_timespec32_utime_pair(struct tcb *, kernel_ulong_t);
1120
+extern int print_itimerspec32(struct tcb *, kernel_ulong_t);
1121
+# endif /* HAVE_ARCH_TIME32_SYSCALLS */
1122
+
1112 1123
 # ifdef ALPHA
1113 1124
 typedef struct {
1114 1125
 	int tv_sec, tv_usec;

+ 153
- 0
print_timespec.h View File

@@ -0,0 +1,153 @@
1
+/*
2
+ * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
3
+ * Copyright (c) 2016-2019 The strace developers.
4
+ * All rights reserved.
5
+ *
6
+ * SPDX-License-Identifier: LGPL-2.1-or-later
7
+ */
8
+
9
+#include "xstring.h"
10
+
11
+#ifndef UTIME_NOW
12
+# define UTIME_NOW ((1l << 30) - 1l)
13
+#endif
14
+#ifndef UTIME_OMIT
15
+# define UTIME_OMIT ((1l << 30) - 2l)
16
+#endif
17
+
18
+#define TIMESPEC_TO_SEC_NSEC(t_)	\
19
+	((long long) (t_)->tv_sec), zero_extend_signed_to_ull((t_)->tv_nsec)
20
+
21
+static const char timespec_fmt[] = "{tv_sec=%lld, tv_nsec=%llu}";
22
+
23
+static void
24
+print_sec_nsec(long long sec, unsigned long long nsec)
25
+{
26
+	tprintf(timespec_fmt, sec, nsec);
27
+}
28
+
29
+static void
30
+print_timespec_t(const TIMESPEC_T *t)
31
+{
32
+	print_sec_nsec(TIMESPEC_TO_SEC_NSEC(t));
33
+}
34
+
35
+static void
36
+print_timespec_t_utime(const TIMESPEC_T *t)
37
+{
38
+	switch (t->tv_nsec) {
39
+	case UTIME_NOW:
40
+	case UTIME_OMIT:
41
+		if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
42
+			print_timespec_t(t);
43
+		if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
44
+			break;
45
+
46
+		(xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
47
+			? tprints_comment : tprints)(t->tv_nsec == UTIME_NOW
48
+				? "UTIME_NOW" : "UTIME_OMIT");
49
+		break;
50
+	default:
51
+		print_timespec_t(t);
52
+		tprints_comment(sprinttime_nsec(TIMESPEC_TO_SEC_NSEC(t)));
53
+		break;
54
+	}
55
+}
56
+
57
+bool
58
+PRINT_TIMESPEC_DATA_SIZE(const void *arg, const size_t size)
59
+{
60
+	if (size < sizeof(TIMESPEC_T)) {
61
+		tprints("?");
62
+		return false;
63
+	}
64
+
65
+	print_timespec_t(arg);
66
+	return true;
67
+}
68
+
69
+bool
70
+PRINT_TIMESPEC_ARRAY_DATA_SIZE(const void *arg, const unsigned int nmemb,
71
+			       const size_t size)
72
+{
73
+	const TIMESPEC_T *ts = arg;
74
+	unsigned int i;
75
+
76
+	if (nmemb > size / sizeof(TIMESPEC_T)) {
77
+		tprints("?");
78
+		return false;
79
+	}
80
+
81
+	tprints("[");
82
+
83
+	for (i = 0; i < nmemb; i++) {
84
+		if (i)
85
+			tprints(", ");
86
+		print_timespec_t(&ts[i]);
87
+	}
88
+
89
+	tprints("]");
90
+	return true;
91
+}
92
+
93
+int
94
+PRINT_TIMESPEC(struct tcb *const tcp, const kernel_ulong_t addr)
95
+{
96
+	TIMESPEC_T t;
97
+
98
+	if (umove_or_printaddr(tcp, addr, &t))
99
+		return -1;
100
+
101
+	print_timespec_t(&t);
102
+	return 0;
103
+}
104
+
105
+const char *
106
+SPRINT_TIMESPEC(struct tcb *const tcp, const kernel_ulong_t addr)
107
+{
108
+	TIMESPEC_T t;
109
+	static char buf[sizeof(timespec_fmt) + 3 * sizeof(t)];
110
+
111
+	if (!addr) {
112
+		strcpy(buf, "NULL");
113
+	} else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
114
+		   umove(tcp, addr, &t)) {
115
+		xsprintf(buf, "%#" PRI_klx, addr);
116
+	} else {
117
+		xsprintf(buf, timespec_fmt, TIMESPEC_TO_SEC_NSEC(&t));
118
+	}
119
+
120
+	return buf;
121
+}
122
+
123
+int
124
+PRINT_TIMESPEC_UTIME_PAIR(struct tcb *const tcp, const kernel_ulong_t addr)
125
+{
126
+	TIMESPEC_T t[2];
127
+
128
+	if (umove_or_printaddr(tcp, addr, &t))
129
+		return -1;
130
+
131
+	tprints("[");
132
+	print_timespec_t_utime(&t[0]);
133
+	tprints(", ");
134
+	print_timespec_t_utime(&t[1]);
135
+	tprints("]");
136
+	return 0;
137
+}
138
+
139
+int
140
+PRINT_ITIMERSPEC(struct tcb *const tcp, const kernel_ulong_t addr)
141
+{
142
+	TIMESPEC_T t[2];
143
+
144
+	if (umove_or_printaddr(tcp, addr, &t))
145
+		return -1;
146
+
147
+	tprints("{it_interval=");
148
+	print_timespec_t(&t[0]);
149
+	tprints(", it_value=");
150
+	print_timespec_t(&t[1]);
151
+	tprints("}");
152
+	return 0;
153
+}

+ 23
- 0
print_timespec32.c View File

@@ -0,0 +1,23 @@
1
+/*
2
+ * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
3
+ * All rights reserved.
4
+ *
5
+ * SPDX-License-Identifier: LGPL-2.1-or-later
6
+ */
7
+
8
+#include "defs.h"
9
+
10
+#if HAVE_ARCH_TIME32_SYSCALLS
11
+
12
+# define TIMESPEC_T kernel_timespec32_t
13
+# define PRINT_TIMESPEC_DATA_SIZE print_timespec32_data_size
14
+# define PRINT_TIMESPEC_ARRAY_DATA_SIZE print_timespec32_array_data_size
15
+# define PRINT_TIMESPEC print_timespec32
16
+# define SPRINT_TIMESPEC sprint_timespec32
17
+# define PRINT_TIMESPEC_UTIME_PAIR print_timespec32_utime_pair
18
+# define PRINT_ITIMERSPEC print_itimerspec32
19
+
20
+# include "kernel_timespec.h"
21
+# include "print_timespec.h"
22
+
23
+#endif /* HAVE_ARCH_TIME32_SYSCALLS */

Loading…
Cancel
Save