]>
Commit | Line | Data |
---|---|---|
b1322259 | 1 | /* |
bc4e831c | 2 | * Copyright 2010-2017 The OpenSSL Project Authors. All Rights Reserved. |
b1322259 RS |
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 | ||
91fdacb2 AP |
10 | #include <stdio.h> |
11 | #include <stdlib.h> | |
12 | #include <string.h> | |
13 | #include <setjmp.h> | |
14 | #include <signal.h> | |
c0dba2cc | 15 | #include "internal/cryptlib.h" |
bc4e831c | 16 | #include "s390x_arch.h" |
91fdacb2 AP |
17 | |
18 | static sigjmp_buf ill_jmp; | |
0f113f3e MC |
19 | static void ill_handler(int sig) |
20 | { | |
21 | siglongjmp(ill_jmp, sig); | |
22 | } | |
91fdacb2 | 23 | |
bc4e831c PS |
24 | void OPENSSL_s390x_facilities(void); |
25 | void OPENSSL_vx_probe(void); | |
26 | ||
27 | struct OPENSSL_s390xcap_st OPENSSL_s390xcap_P; | |
91fdacb2 AP |
28 | |
29 | void OPENSSL_cpuid_setup(void) | |
0f113f3e MC |
30 | { |
31 | sigset_t oset; | |
32 | struct sigaction ill_act, oact; | |
33 | ||
bc4e831c | 34 | if (OPENSSL_s390xcap_P.stfle[0]) |
0f113f3e MC |
35 | return; |
36 | ||
bc4e831c PS |
37 | /* set a bit that will not be tested later */ |
38 | OPENSSL_s390xcap_P.stfle[0] |= S390X_CAPBIT(0); | |
0f113f3e MC |
39 | |
40 | memset(&ill_act, 0, sizeof(ill_act)); | |
41 | ill_act.sa_handler = ill_handler; | |
42 | sigfillset(&ill_act.sa_mask); | |
43 | sigdelset(&ill_act.sa_mask, SIGILL); | |
bc4e831c | 44 | sigdelset(&ill_act.sa_mask, SIGFPE); |
0f113f3e MC |
45 | sigdelset(&ill_act.sa_mask, SIGTRAP); |
46 | sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset); | |
47 | sigaction(SIGILL, &ill_act, &oact); | |
bc4e831c | 48 | sigaction(SIGFPE, &ill_act, &oact); |
0f113f3e MC |
49 | |
50 | /* protection against missing store-facility-list-extended */ | |
51 | if (sigsetjmp(ill_jmp, 1) == 0) | |
52 | OPENSSL_s390x_facilities(); | |
53 | ||
bc4e831c PS |
54 | /* protection against disabled vector facility */ |
55 | if ((OPENSSL_s390xcap_P.stfle[2] & S390X_CAPBIT(S390X_VX)) | |
56 | && (sigsetjmp(ill_jmp, 1) == 0)) { | |
57 | OPENSSL_vx_probe(); | |
58 | } else { | |
59 | OPENSSL_s390xcap_P.stfle[2] &= ~(S390X_CAPBIT(S390X_VX) | |
60 | | S390X_CAPBIT(S390X_VXD) | |
61 | | S390X_CAPBIT(S390X_VXE)); | |
62 | } | |
63 | ||
64 | sigaction(SIGFPE, &oact, NULL); | |
0f113f3e MC |
65 | sigaction(SIGILL, &oact, NULL); |
66 | sigprocmask(SIG_SETMASK, &oset, NULL); | |
67 | } |