xref: /openbmc/qemu/tests/tcg/s390x/pgm-specification-user.c (revision 4c6f44644d08f6f712474288d61deba601421988)
1*e902126cSIlya Leoshkevich /*
2*e902126cSIlya Leoshkevich  * Common user code for specification exception testing.
3*e902126cSIlya Leoshkevich  *
4*e902126cSIlya Leoshkevich  * SPDX-License-Identifier: GPL-2.0-or-later
5*e902126cSIlya Leoshkevich  */
6*e902126cSIlya Leoshkevich #include <assert.h>
7*e902126cSIlya Leoshkevich #include <signal.h>
8*e902126cSIlya Leoshkevich #include <stdlib.h>
9*e902126cSIlya Leoshkevich #include <string.h>
10*e902126cSIlya Leoshkevich #include <unistd.h>
11*e902126cSIlya Leoshkevich 
12*e902126cSIlya Leoshkevich extern void test(void);
13*e902126cSIlya Leoshkevich extern long expected_old_psw[2];
14*e902126cSIlya Leoshkevich 
handle_sigill(int sig,siginfo_t * info,void * ucontext)15*e902126cSIlya Leoshkevich static void handle_sigill(int sig, siginfo_t *info, void *ucontext)
16*e902126cSIlya Leoshkevich {
17*e902126cSIlya Leoshkevich     if ((long)info->si_addr != expected_old_psw[1]) {
18*e902126cSIlya Leoshkevich         _exit(EXIT_FAILURE);
19*e902126cSIlya Leoshkevich     }
20*e902126cSIlya Leoshkevich     _exit(EXIT_SUCCESS);
21*e902126cSIlya Leoshkevich }
22*e902126cSIlya Leoshkevich 
main(void)23*e902126cSIlya Leoshkevich int main(void)
24*e902126cSIlya Leoshkevich {
25*e902126cSIlya Leoshkevich     struct sigaction act;
26*e902126cSIlya Leoshkevich     int err;
27*e902126cSIlya Leoshkevich 
28*e902126cSIlya Leoshkevich     memset(&act, 0, sizeof(act));
29*e902126cSIlya Leoshkevich     act.sa_sigaction = handle_sigill;
30*e902126cSIlya Leoshkevich     act.sa_flags = SA_SIGINFO;
31*e902126cSIlya Leoshkevich     err = sigaction(SIGILL, &act, NULL);
32*e902126cSIlya Leoshkevich     assert(err == 0);
33*e902126cSIlya Leoshkevich 
34*e902126cSIlya Leoshkevich     test();
35*e902126cSIlya Leoshkevich 
36*e902126cSIlya Leoshkevich     return EXIT_FAILURE;
37*e902126cSIlya Leoshkevich }
38