s390xcap.c 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <setjmp.h>
  5. #include <signal.h>
  6. extern unsigned long OPENSSL_s390xcap_P[];
  7. static sigjmp_buf ill_jmp;
  8. static void ill_handler(int sig)
  9. {
  10. siglongjmp(ill_jmp, sig);
  11. }
  12. unsigned long OPENSSL_s390x_facilities(void);
  13. void OPENSSL_cpuid_setup(void)
  14. {
  15. sigset_t oset;
  16. struct sigaction ill_act, oact;
  17. if (OPENSSL_s390xcap_P[0])
  18. return;
  19. OPENSSL_s390xcap_P[0] = 1UL << (8 * sizeof(unsigned long) - 1);
  20. memset(&ill_act, 0, sizeof(ill_act));
  21. ill_act.sa_handler = ill_handler;
  22. sigfillset(&ill_act.sa_mask);
  23. sigdelset(&ill_act.sa_mask, SIGILL);
  24. sigdelset(&ill_act.sa_mask, SIGTRAP);
  25. sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
  26. sigaction(SIGILL, &ill_act, &oact);
  27. /* protection against missing store-facility-list-extended */
  28. if (sigsetjmp(ill_jmp, 1) == 0)
  29. OPENSSL_s390x_facilities();
  30. sigaction(SIGILL, &oact, NULL);
  31. sigprocmask(SIG_SETMASK, &oset, NULL);
  32. }