]> granicus.if.org Git - strace/commitdiff
Fix time syscall decoding for some personalities
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 18 Aug 2015 13:25:36 +0000 (13:25 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 18 Aug 2015 15:10:55 +0000 (15:10 +0000)
* time.c (current_time_t_is_int32): Define.
(sys_time): Use it, printnum_int, and printnum_int64 instead
of printnum_long.
* tests/time.c: New file.
* tests/time.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add time.
(TESTS): Add time.test.
* tests/.gitignore: Add time.

tests/.gitignore
tests/Makefile.am
tests/time.c [new file with mode: 0644]
tests/time.test [new file with mode: 0755]
time.c

index d58e73552292858c84660e2d4cd987b1ddaa68c3..f709d7f25c1c3335e170aa7cc5a2796ded863769 100644 (file)
@@ -39,6 +39,7 @@ stack-fcall
 stat
 stat32
 statfs
+time
 uid
 uid16
 uid32
index 6b299d11403b89c4551d0c74f1e5a80d3a056b63..6fa46d3acb0e57463ddb49fc963d366f069733e0 100644 (file)
@@ -50,6 +50,7 @@ check_PROGRAMS = \
        stat \
        stat32 \
        statfs \
+       time \
        uid \
        uid16 \
        uid32 \
@@ -115,6 +116,7 @@ TESTS = \
        pc.test \
        ppoll.test \
        sun_path.test \
+       time.test \
        umovestr.test \
        umovestr2.test \
        unix-yy.test \
diff --git a/tests/time.c b/tests/time.c
new file mode 100644 (file)
index 0000000..2726b2d
--- /dev/null
@@ -0,0 +1,43 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <time.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+
+#ifdef __NR_time
+
+int
+main(void)
+{
+       const size_t page_len = sysconf(_SC_PAGESIZE);
+
+       void *p = mmap(NULL, page_len * 2, PROT_READ | PROT_WRITE,
+                      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+       if (p == MAP_FAILED || mprotect(p + page_len, page_len, PROT_NONE))
+               return 77;
+
+       time_t *p_t = p + page_len - sizeof(time_t);
+       time_t t = syscall(__NR_time, p_t);
+
+       if ((time_t) -1 == t || t != *p_t)
+               return 77;
+
+       printf("time\\(\\[%jd\\]\\) += %jd\n", (intmax_t) t, (intmax_t) t);
+
+       return 0;
+}
+
+#else
+
+int
+main(void)
+{
+       return 77;
+}
+
+#endif
diff --git a/tests/time.test b/tests/time.test
new file mode 100755 (executable)
index 0000000..90b1bfb
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# Check time syscall decoding.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+OUT="$LOG.out"
+run_strace -etime $args > "$OUT"
+match_grep "$LOG" "$OUT"
+rm -f "$OUT"
+
+exit 0
diff --git a/time.c b/time.c
index dfddc45673cbcb809dd110d0cf4ebbee40f67656..920abdf3cb98a877f9640899cc06f43068d4e100 100644 (file)
--- a/time.c
+++ b/time.c
 # else
 #  define current_time_t_is_compat (current_wordsize == 4)
 # endif
+# define current_time_t_is_int32 current_time_t_is_compat
 #else
 # define current_time_t_is_compat 0
+# define current_time_t_is_int32 (sizeof(time_t) == 4)
 #endif
 
 struct timeval32
@@ -160,7 +162,10 @@ sprint_timespec(char *buf, struct tcb *tcp, long addr)
 SYS_FUNC(time)
 {
        if (exiting(tcp)) {
-               printnum_long(tcp, tcp->u_arg[0], "%ld");
+               if (current_time_t_is_int32)
+                       printnum_int(tcp, tcp->u_arg[0], "%d");
+               else
+                       printnum_int64(tcp, tcp->u_arg[0], "%" PRId64);
        }
        return 0;
 }