1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Test sigreturn to an unaligned address, ie. low 2 bits set.
4  * Nothing bad should happen.
5  * This was able to trigger warnings with CONFIG_PPC_RFI_SRR_DEBUG=y.
6  */
7 
8 #include <signal.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <ucontext.h>
13 #include <unistd.h>
14 
15 #include "utils.h"
16 
17 
18 static void sigusr1_handler(int signo, siginfo_t *info, void *ptr)
19 {
20 	ucontext_t *uc = ptr;
21 
22 	UCONTEXT_NIA(uc) |= 3;
23 }
24 
25 static int test_sigreturn_unaligned(void)
26 {
27 	struct sigaction action;
28 
29 	memset(&action, 0, sizeof(action));
30 	action.sa_sigaction = sigusr1_handler;
31 	action.sa_flags = SA_SIGINFO;
32 
33 	FAIL_IF(sigaction(SIGUSR1, &action, NULL) == -1);
34 
35 	raise(SIGUSR1);
36 
37 	return 0;
38 }
39 
40 int main(void)
41 {
42 	return test_harness(test_sigreturn_unaligned, "sigreturn_unaligned");
43 }
44