2 * Check decoding of clock_nanosleep and clock_gettime syscalls.
4 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2015-2017 The strace developers.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <asm/unistd.h>
53 .ts.tv_nsec = 0xc0de1,
54 .pad = { 0xdeadbeef, 0xbadc0ded }
56 .ts = { .tv_sec = 0xc0de2, .tv_nsec = 0xc0de3 },
57 .pad = { 0xdeadbeef, 0xbadc0ded }
59 const sigset_t set = {};
60 const struct sigaction act = { .sa_handler = handler };
61 const struct itimerval itv = {
62 .it_interval.tv_usec = 222222,
63 .it_value.tv_usec = 111111
66 if (syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0, &req.ts, NULL))
67 perror_msg_and_skip("clock_nanosleep CLOCK_REALTIME");
68 printf("clock_nanosleep(CLOCK_REALTIME, 0"
69 ", {tv_sec=%lld, tv_nsec=%llu}, NULL) = 0\n",
70 (long long) req.ts.tv_sec,
71 zero_extend_signed_to_ull(req.ts.tv_nsec));
73 assert(syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0,
74 NULL, &rem.ts) == -1);
75 printf("clock_nanosleep(CLOCK_REALTIME, 0, NULL, %p)"
76 " = -1 EFAULT (%m)\n", &rem.ts);
78 assert(syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0,
79 &req.ts, &rem.ts) == 0);
80 printf("clock_nanosleep(CLOCK_REALTIME, 0"
81 ", {tv_sec=%lld, tv_nsec=%llu}, %p) = 0\n",
82 (long long) req.ts.tv_sec,
83 zero_extend_signed_to_ull(req.ts.tv_nsec), &rem.ts);
85 req.ts.tv_nsec = 999999999 + 1;
86 assert(syscall(__NR_clock_nanosleep, CLOCK_MONOTONIC, 0,
87 &req.ts, &rem.ts) == -1);
88 printf("clock_nanosleep(CLOCK_MONOTONIC, 0"
89 ", {tv_sec=%lld, tv_nsec=%llu}, %p) = -1 EINVAL (%m)\n",
90 (long long) req.ts.tv_sec,
91 zero_extend_signed_to_ull(req.ts.tv_nsec), &rem.ts);
93 req.ts.tv_sec = 0xdeadbeefU;
94 req.ts.tv_nsec = 0xfacefeedU;
95 assert(syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0,
96 &req.ts, &rem.ts) == -1);
97 printf("clock_nanosleep(CLOCK_REALTIME, 0"
98 ", {tv_sec=%lld, tv_nsec=%llu}, %p) = -1 EINVAL (%m)\n",
99 (long long) req.ts.tv_sec,
100 zero_extend_signed_to_ull(req.ts.tv_nsec), &rem.ts);
102 req.ts.tv_sec = (time_t) 0xcafef00ddeadbeefLL;
103 req.ts.tv_nsec = (long) 0xbadc0dedfacefeedLL;
104 assert(syscall(__NR_clock_nanosleep, CLOCK_MONOTONIC, 0,
105 &req.ts, &rem.ts) == -1);
106 printf("clock_nanosleep(CLOCK_MONOTONIC, 0"
107 ", {tv_sec=%lld, tv_nsec=%llu}, %p) = -1 EINVAL (%m)\n",
108 (long long) req.ts.tv_sec,
109 zero_extend_signed_to_ull(req.ts.tv_nsec), &rem.ts);
111 assert(sigaction(SIGALRM, &act, NULL) == 0);
112 assert(sigprocmask(SIG_SETMASK, &set, NULL) == 0);
114 if (setitimer(ITIMER_REAL, &itv, NULL))
115 perror_msg_and_skip("setitimer");
118 req.ts.tv_nsec = 999999999;
119 assert(syscall(__NR_clock_nanosleep, CLOCK_REALTIME, 0,
120 &req.ts, &rem.ts) == -1);
121 printf("clock_nanosleep(CLOCK_REALTIME, 0"
122 ", {tv_sec=%lld, tv_nsec=%llu}, {tv_sec=%lld, tv_nsec=%llu})"
123 " = ? ERESTART_RESTARTBLOCK (Interrupted by signal)\n",
124 (long long) req.ts.tv_sec,
125 zero_extend_signed_to_ull(req.ts.tv_nsec),
126 (long long) rem.ts.tv_sec,
127 zero_extend_signed_to_ull(rem.ts.tv_nsec));
128 puts("--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---");
130 assert(syscall(__NR_clock_gettime, CLOCK_REALTIME, &req.ts) == 0);
131 printf("clock_gettime(CLOCK_REALTIME, {tv_sec=%lld, tv_nsec=%llu}) = 0\n",
132 (long long) req.ts.tv_sec,
133 zero_extend_signed_to_ull(req.ts.tv_nsec));
136 rem.ts.tv_sec = 0xc0de4;
137 rem.ts.tv_nsec = 0xc0de5;
138 assert(syscall(__NR_clock_nanosleep, CLOCK_REALTIME, TIMER_ABSTIME,
139 &req.ts, &rem.ts) == -1);
140 printf("clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME"
141 ", {tv_sec=%lld, tv_nsec=%llu}, %p)"
142 " = ? ERESTARTNOHAND (To be restarted if no handler)\n",
143 (long long) req.ts.tv_sec,
144 zero_extend_signed_to_ull(req.ts.tv_nsec), &rem.ts);
145 puts("--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---");
147 puts("+++ exited with 0 +++");