1*cf84ac9aSAndroid Build Coastguard Worker /*
2*cf84ac9aSAndroid Build Coastguard Worker * Copyright (c) 2015-2016 Dmitry V. Levin <[email protected]>
3*cf84ac9aSAndroid Build Coastguard Worker * Copyright (c) 2015-2017 The strace developers.
4*cf84ac9aSAndroid Build Coastguard Worker * All rights reserved.
5*cf84ac9aSAndroid Build Coastguard Worker *
6*cf84ac9aSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without
7*cf84ac9aSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions
8*cf84ac9aSAndroid Build Coastguard Worker * are met:
9*cf84ac9aSAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright
10*cf84ac9aSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer.
11*cf84ac9aSAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright
12*cf84ac9aSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the
13*cf84ac9aSAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution.
14*cf84ac9aSAndroid Build Coastguard Worker * 3. The name of the author may not be used to endorse or promote products
15*cf84ac9aSAndroid Build Coastguard Worker * derived from this software without specific prior written permission.
16*cf84ac9aSAndroid Build Coastguard Worker *
17*cf84ac9aSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18*cf84ac9aSAndroid Build Coastguard Worker * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19*cf84ac9aSAndroid Build Coastguard Worker * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*cf84ac9aSAndroid Build Coastguard Worker * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21*cf84ac9aSAndroid Build Coastguard Worker * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22*cf84ac9aSAndroid Build Coastguard Worker * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23*cf84ac9aSAndroid Build Coastguard Worker * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24*cf84ac9aSAndroid Build Coastguard Worker * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25*cf84ac9aSAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26*cf84ac9aSAndroid Build Coastguard Worker * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*cf84ac9aSAndroid Build Coastguard Worker */
28*cf84ac9aSAndroid Build Coastguard Worker
29*cf84ac9aSAndroid Build Coastguard Worker #include "tests.h"
30*cf84ac9aSAndroid Build Coastguard Worker #include <assert.h>
31*cf84ac9aSAndroid Build Coastguard Worker #include <stdio.h>
32*cf84ac9aSAndroid Build Coastguard Worker #include <stdint.h>
33*cf84ac9aSAndroid Build Coastguard Worker #include <signal.h>
34*cf84ac9aSAndroid Build Coastguard Worker #include <time.h>
35*cf84ac9aSAndroid Build Coastguard Worker #include <sys/time.h>
36*cf84ac9aSAndroid Build Coastguard Worker
37*cf84ac9aSAndroid Build Coastguard Worker int
main(void)38*cf84ac9aSAndroid Build Coastguard Worker main(void)
39*cf84ac9aSAndroid Build Coastguard Worker {
40*cf84ac9aSAndroid Build Coastguard Worker #if defined __x86_64__ && defined __ILP32__
41*cf84ac9aSAndroid Build Coastguard Worker /*
42*cf84ac9aSAndroid Build Coastguard Worker * x32 is broken from the beginning:
43*cf84ac9aSAndroid Build Coastguard Worker * https://lkml.org/lkml/2015/11/30/790
44*cf84ac9aSAndroid Build Coastguard Worker */
45*cf84ac9aSAndroid Build Coastguard Worker error_msg_and_skip("x32 is broken");
46*cf84ac9aSAndroid Build Coastguard Worker #else
47*cf84ac9aSAndroid Build Coastguard Worker const sigset_t set = {};
48*cf84ac9aSAndroid Build Coastguard Worker const struct sigaction act = { .sa_handler = SIG_IGN };
49*cf84ac9aSAndroid Build Coastguard Worker const struct itimerval itv = { .it_value.tv_usec = 111111 };
50*cf84ac9aSAndroid Build Coastguard Worker struct timespec req = { .tv_nsec = 222222222 }, rem;
51*cf84ac9aSAndroid Build Coastguard Worker
52*cf84ac9aSAndroid Build Coastguard Worker assert(sigaction(SIGALRM, &act, NULL) == 0);
53*cf84ac9aSAndroid Build Coastguard Worker assert(sigprocmask(SIG_SETMASK, &set, NULL) == 0);
54*cf84ac9aSAndroid Build Coastguard Worker if (setitimer(ITIMER_REAL, &itv, NULL))
55*cf84ac9aSAndroid Build Coastguard Worker perror_msg_and_skip("setitimer");
56*cf84ac9aSAndroid Build Coastguard Worker if (nanosleep(&req, &rem))
57*cf84ac9aSAndroid Build Coastguard Worker perror_msg_and_fail("nanosleep");
58*cf84ac9aSAndroid Build Coastguard Worker
59*cf84ac9aSAndroid Build Coastguard Worker printf("nanosleep\\(\\{tv_sec=%lld, tv_nsec=%llu\\}"
60*cf84ac9aSAndroid Build Coastguard Worker ", \\{tv_sec=%lld, tv_nsec=%llu\\}\\)"
61*cf84ac9aSAndroid Build Coastguard Worker " = \\? ERESTART_RESTARTBLOCK \\(Interrupted by signal\\)\n",
62*cf84ac9aSAndroid Build Coastguard Worker (long long) req.tv_sec, zero_extend_signed_to_ull(req.tv_nsec),
63*cf84ac9aSAndroid Build Coastguard Worker (long long) rem.tv_sec, zero_extend_signed_to_ull(rem.tv_nsec));
64*cf84ac9aSAndroid Build Coastguard Worker puts("--- SIGALRM \\{si_signo=SIGALRM, si_code=SI_KERNEL\\} ---");
65*cf84ac9aSAndroid Build Coastguard Worker #ifdef __arm__
66*cf84ac9aSAndroid Build Coastguard Worker /* old kernels used to overwrite ARM_r0 with -EINTR */
67*cf84ac9aSAndroid Build Coastguard Worker # define ALTERNATIVE_NANOSLEEP_REQ "0xfffffffc|"
68*cf84ac9aSAndroid Build Coastguard Worker #else
69*cf84ac9aSAndroid Build Coastguard Worker # define ALTERNATIVE_NANOSLEEP_REQ ""
70*cf84ac9aSAndroid Build Coastguard Worker #endif
71*cf84ac9aSAndroid Build Coastguard Worker printf("(nanosleep\\((%s\\{tv_sec=%lld, tv_nsec=%llu\\})"
72*cf84ac9aSAndroid Build Coastguard Worker ", %p|restart_syscall\\(<\\.\\.\\."
73*cf84ac9aSAndroid Build Coastguard Worker " resuming interrupted nanosleep \\.\\.\\.>)\\) = 0\n",
74*cf84ac9aSAndroid Build Coastguard Worker ALTERNATIVE_NANOSLEEP_REQ,
75*cf84ac9aSAndroid Build Coastguard Worker (long long) req.tv_sec, zero_extend_signed_to_ull(req.tv_nsec),
76*cf84ac9aSAndroid Build Coastguard Worker &rem);
77*cf84ac9aSAndroid Build Coastguard Worker
78*cf84ac9aSAndroid Build Coastguard Worker puts("\\+\\+\\+ exited with 0 \\+\\+\\+");
79*cf84ac9aSAndroid Build Coastguard Worker return 0;
80*cf84ac9aSAndroid Build Coastguard Worker #endif
81*cf84ac9aSAndroid Build Coastguard Worker }
82