Constify X509|X509_CRL|X509_REVOKED_get_ext
[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
16 extern unsigned long OPENSSL_s390xcap_P[];
17
18 static sigjmp_buf ill_jmp;
19 static void ill_handler(int sig)
20 {
21     siglongjmp(ill_jmp, sig);
22 }
23
24 unsigned long OPENSSL_s390x_facilities(void);
25
26 void OPENSSL_cpuid_setup(void)
27 {
28     sigset_t oset;
29     struct sigaction ill_act, oact;
30
31     if (OPENSSL_s390xcap_P[0])
32         return;
33
34     OPENSSL_s390xcap_P[0] = 1UL << (8 * sizeof(unsigned long) - 1);
35
36     memset(&ill_act, 0, sizeof(ill_act));
37     ill_act.sa_handler = ill_handler;
38     sigfillset(&ill_act.sa_mask);
39     sigdelset(&ill_act.sa_mask, SIGILL);
40     sigdelset(&ill_act.sa_mask, SIGTRAP);
41     sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
42     sigaction(SIGILL, &ill_act, &oact);
43
44     /* protection against missing store-facility-list-extended */
45     if (sigsetjmp(ill_jmp, 1) == 0)
46         OPENSSL_s390x_facilities();
47
48     sigaction(SIGILL, &oact, NULL);
49     sigprocmask(SIG_SETMASK, &oset, NULL);
50 }