Convert Sigalgs processing to use ints
[openssl.git] / crypto / s390xcap.c
1 /*
2  * Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <setjmp.h>
14 #include <signal.h>
15 #include "internal/cryptlib.h"
16
17 extern unsigned long OPENSSL_s390xcap_P[];
18
19 static sigjmp_buf ill_jmp;
20 static void ill_handler(int sig)
21 {
22     siglongjmp(ill_jmp, sig);
23 }
24
25 unsigned long OPENSSL_s390x_facilities(void);
26
27 void OPENSSL_cpuid_setup(void)
28 {
29     sigset_t oset;
30     struct sigaction ill_act, oact;
31
32     if (OPENSSL_s390xcap_P[0])
33         return;
34
35     OPENSSL_s390xcap_P[0] = 1UL << (8 * sizeof(unsigned long) - 1);
36
37     memset(&ill_act, 0, sizeof(ill_act));
38     ill_act.sa_handler = ill_handler;
39     sigfillset(&ill_act.sa_mask);
40     sigdelset(&ill_act.sa_mask, SIGILL);
41     sigdelset(&ill_act.sa_mask, SIGTRAP);
42     sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
43     sigaction(SIGILL, &ill_act, &oact);
44
45     /* protection against missing store-facility-list-extended */
46     if (sigsetjmp(ill_jmp, 1) == 0)
47         OPENSSL_s390x_facilities();
48
49     sigaction(SIGILL, &oact, NULL);
50     sigprocmask(SIG_SETMASK, &oset, NULL);
51 }