2
0

s390xcap.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2010-2019 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. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <setjmp.h>
  13. #include <signal.h>
  14. #include "internal/cryptlib.h"
  15. #include "s390x_arch.h"
  16. static sigjmp_buf ill_jmp;
  17. static void ill_handler(int sig)
  18. {
  19. siglongjmp(ill_jmp, sig);
  20. }
  21. void OPENSSL_s390x_facilities(void);
  22. void OPENSSL_vx_probe(void);
  23. struct OPENSSL_s390xcap_st OPENSSL_s390xcap_P;
  24. void OPENSSL_cpuid_setup(void)
  25. {
  26. sigset_t oset;
  27. struct sigaction ill_act, oact_ill, oact_fpe;
  28. if (OPENSSL_s390xcap_P.stfle[0])
  29. return;
  30. /* set a bit that will not be tested later */
  31. OPENSSL_s390xcap_P.stfle[0] |= S390X_CAPBIT(0);
  32. memset(&ill_act, 0, sizeof(ill_act));
  33. ill_act.sa_handler = ill_handler;
  34. sigfillset(&ill_act.sa_mask);
  35. sigdelset(&ill_act.sa_mask, SIGILL);
  36. sigdelset(&ill_act.sa_mask, SIGFPE);
  37. sigdelset(&ill_act.sa_mask, SIGTRAP);
  38. sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
  39. sigaction(SIGILL, &ill_act, &oact_ill);
  40. sigaction(SIGFPE, &ill_act, &oact_fpe);
  41. /* protection against missing store-facility-list-extended */
  42. if (sigsetjmp(ill_jmp, 1) == 0)
  43. OPENSSL_s390x_facilities();
  44. /* protection against disabled vector facility */
  45. if ((OPENSSL_s390xcap_P.stfle[2] & S390X_CAPBIT(S390X_VX))
  46. && (sigsetjmp(ill_jmp, 1) == 0)) {
  47. OPENSSL_vx_probe();
  48. } else {
  49. OPENSSL_s390xcap_P.stfle[2] &= ~(S390X_CAPBIT(S390X_VX)
  50. | S390X_CAPBIT(S390X_VXD)
  51. | S390X_CAPBIT(S390X_VXE));
  52. }
  53. sigaction(SIGFPE, &oact_fpe, NULL);
  54. sigaction(SIGILL, &oact_ill, NULL);
  55. sigprocmask(SIG_SETMASK, &oset, NULL);
  56. }