s390xcap.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2010-2022 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. #if defined(__GNUC__) && defined(__linux)
  25. __attribute__ ((visibility("hidden")))
  26. #endif
  27. void OPENSSL_cpuid_setup(void)
  28. {
  29. sigset_t oset;
  30. struct sigaction ill_act, oact_ill, oact_fpe;
  31. if (OPENSSL_s390xcap_P.stfle[0])
  32. return;
  33. /* set a bit that will not be tested later */
  34. OPENSSL_s390xcap_P.stfle[0] |= S390X_CAPBIT(0);
  35. memset(&ill_act, 0, sizeof(ill_act));
  36. ill_act.sa_handler = ill_handler;
  37. sigfillset(&ill_act.sa_mask);
  38. sigdelset(&ill_act.sa_mask, SIGILL);
  39. sigdelset(&ill_act.sa_mask, SIGFPE);
  40. sigdelset(&ill_act.sa_mask, SIGTRAP);
  41. sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
  42. sigaction(SIGILL, &ill_act, &oact_ill);
  43. sigaction(SIGFPE, &ill_act, &oact_fpe);
  44. /* protection against missing store-facility-list-extended */
  45. if (sigsetjmp(ill_jmp, 1) == 0)
  46. OPENSSL_s390x_facilities();
  47. /* protection against disabled vector facility */
  48. if ((OPENSSL_s390xcap_P.stfle[2] & S390X_CAPBIT(S390X_VX))
  49. && (sigsetjmp(ill_jmp, 1) == 0)) {
  50. OPENSSL_vx_probe();
  51. } else {
  52. OPENSSL_s390xcap_P.stfle[2] &= ~(S390X_CAPBIT(S390X_VX)
  53. | S390X_CAPBIT(S390X_VXD)
  54. | S390X_CAPBIT(S390X_VXE));
  55. }
  56. sigaction(SIGFPE, &oact_fpe, NULL);
  57. sigaction(SIGILL, &oact_ill, NULL);
  58. sigprocmask(SIG_SETMASK, &oset, NULL);
  59. }