components/openssl/common/patches/038-remove_illegal_instruction_calls.patch
changeset 4822 1fb8a14c6702
parent 4370 7043c27399f1
equal deleted inserted replaced
4821:54dafbe33fdb 4822:1fb8a14c6702
     2 # This patch was developed in house.
     2 # This patch was developed in house.
     3 # This is Solaris-specific: not suitable for upstream.
     3 # This is Solaris-specific: not suitable for upstream.
     4 #
     4 #
     5 --- openssl-1.0.1g/crypto/sparcv9cap.c.~1~	Thu May  1 13:07:00 2014
     5 --- openssl-1.0.1g/crypto/sparcv9cap.c.~1~	Thu May  1 13:07:00 2014
     6 +++ openssl-1.0.1g/crypto/sparcv9cap.c	Thu May  1 13:11:33 2014
     6 +++ openssl-1.0.1g/crypto/sparcv9cap.c	Thu May  1 13:11:33 2014
     7 @@ -2,9 +2,9 @@
     7 @@ -2,10 +2,10 @@
     8  #include <stdlib.h>
     8  #include <stdlib.h>
     9  #include <string.h>
     9  #include <string.h>
    10  #include <setjmp.h>
    10  #include <setjmp.h>
    11 -#include <signal.h>
    11 -#include <signal.h>
    12  #include <sys/time.h>
    12  #include <sys/time.h>
       
    13  #include <unistd.h>
    13  #include <openssl/bn.h>
    14  #include <openssl/bn.h>
    14 +#include <sys/auxv.h>
    15 +#include <sys/auxv.h>
    15  
    16  
    16  #define SPARCV9_TICK_PRIVILEGED (1<<0)
    17  #include "sparc_arch.h"
    17  #define SPARCV9_PREFER_FPU      (1<<1)
    18  
    18 @@ -11,6 +11,7 @@
    19 @@ -69,13 +69,8 @@
    19  #define SPARCV9_VIS1            (1<<2)
       
    20  #define SPARCV9_VIS2            (1<<3) /* reserved */
       
    21  #define SPARCV9_FMADD           (1<<4) /* reserved for SPARC64 V */
       
    22 +#define SPARCV9_BLK             (1<<5)
       
    23  
       
    24  static int OPENSSL_sparcv9cap_P = SPARCV9_TICK_PRIVILEGED;
       
    25  
       
    26 @@ -31,10 +31,7 @@
       
    27  }
    20  }
    28 
    21 
    29  unsigned long _sparcv9_rdtick(void);
    22  unsigned long _sparcv9_rdtick(void);
    30 -void _sparcv9_vis1_probe(void);
    23 -void _sparcv9_vis1_probe(void);
    31  unsigned long _sparcv9_vis1_instrument(void);
    24  unsigned long _sparcv9_vis1_instrument(void);
    32 -void _sparcv9_vis2_probe(void);
    25 -void _sparcv9_vis2_probe(void);
    33 -void _sparcv9_fmadd_probe(void);
    26 -void _sparcv9_fmadd_probe(void);
    34  
    27  unsigned long _sparcv9_rdcfr(void);
    35  unsigned long OPENSSL_rdtsc(void)
    28 -void _sparcv9_vis3_probe(void);
    36  {
    29 -unsigned long _sparcv9_random(void);
    37 @@ -170,18 +167,11 @@
    30  size_t _sparcv9_vis1_instrument_bus(unsigned int *, size_t);
       
    31  size_t _sparcv9_vis1_instrument_bus2(unsigned int *, size_t, size_t);
       
    32  
       
    33 @@ -231,18 +227,11 @@
    38 
    34 
    39  #else
    35  #else
    40 
    36 
    41 -static sigjmp_buf common_jmp;
    37 -static sigjmp_buf common_jmp;
    42 -static void common_handler(int sig)
    38 -static void common_handler(int sig)
    52      static int trigger = 0;
    48      static int trigger = 0;
    53 +    uint_t ui = 0;
    49 +    uint_t ui = 0;
    54 
    50 
    55      if (trigger)
    51      if (trigger)
    56          return;
    52          return;
    57 @@ -192,54 +182,24 @@
    53 @@ -255,47 +255,23 @@
    58          return;
    54          return;
    59      }
    55      }
    60  
    56  
    61 +    (void) getisax(&ui, 1);
    57 +    (void) getisax(&ui, 1);
    62 +
    58 +
    63      /* Initial value, fits UltraSPARC-I&II... */
    59      /* Initial value, fits UltraSPARC-I&II... */
    64 -    OPENSSL_sparcv9cap_P = SPARCV9_PREFER_FPU | SPARCV9_TICK_PRIVILEGED;
    60 -    OPENSSL_sparcv9cap_P[0] = SPARCV9_PREFER_FPU | SPARCV9_TICK_PRIVILEGED;
    65 +    OPENSSL_sparcv9cap_P = SPARCV9_BLK;
    61 +    OPENSSL_sparcv9cap_P[0] = SPARCV9_BLK;
    66  
    62  
    67 -    sigfillset(&all_masked);
    63 -    sigfillset(&all_masked);
    68 -    sigdelset(&all_masked, SIGILL);
    64 -    sigdelset(&all_masked, SIGILL);
    69 -    sigdelset(&all_masked, SIGTRAP);
    65 -    sigdelset(&all_masked, SIGTRAP);
    70 -# ifdef SIGEMT
    66 -# ifdef SIGEMT
    83 -    sigaction(SIGBUS, &common_act, &bus_oact); /* T1 fails 16-bit ldda [on
    79 -    sigaction(SIGBUS, &common_act, &bus_oact); /* T1 fails 16-bit ldda [on
    84 -                                                * Linux] */
    80 -                                                * Linux] */
    85 -
    81 -
    86 -    if (sigsetjmp(common_jmp, 1) == 0) {
    82 -    if (sigsetjmp(common_jmp, 1) == 0) {
    87 -        _sparcv9_rdtick();
    83 -        _sparcv9_rdtick();
    88 -        OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
    84 -        OPENSSL_sparcv9cap_P[0] &= ~SPARCV9_TICK_PRIVILEGED;
    89 -    }
    85 -    }
    90 -
    86 -
    91 -    if (sigsetjmp(common_jmp, 1) == 0) {
    87 -    if (sigsetjmp(common_jmp, 1) == 0) {
    92 -        _sparcv9_vis1_probe();
    88 -        _sparcv9_vis1_probe();
    93 -        OPENSSL_sparcv9cap_P |= SPARCV9_VIS1;
    89 -        OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS1 | SPARCV9_BLK;
    94 -        /* detect UltraSPARC-Tx, see sparccpud.S for details... */
    90 -        /* detect UltraSPARC-Tx, see sparccpud.S for details... */
    95 -        if (_sparcv9_vis1_instrument() >= 12)
    91 -        if (_sparcv9_vis1_instrument() >= 12)
    96 -            OPENSSL_sparcv9cap_P &= ~(SPARCV9_VIS1 | SPARCV9_PREFER_FPU);
    92 -            OPENSSL_sparcv9cap_P[0] &= ~(SPARCV9_VIS1 | SPARCV9_PREFER_FPU);
    97 -        else {
    93 -        else {
    98 -            _sparcv9_vis2_probe();
    94 -            _sparcv9_vis2_probe();
    99 -            OPENSSL_sparcv9cap_P |= SPARCV9_VIS2;
    95 -            OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS2;
   100 +    if (ui & AV_SPARC_VIS) {
    96 +    if (ui & AV_SPARC_VIS) {
   101 +        /* detect UltraSPARC-Tx, see sparccpuid.S for details... */
    97 +        /* detect UltraSPARC-Tx, see sparccpuid.S for details... */
   102 +        if (_sparcv9_vis1_instrument() < 7)
    98 +        if (_sparcv9_vis1_instrument() < 7)
   103 +            OPENSSL_sparcv9cap_P |= SPARCV9_TICK_PRIVILEGED;
    99 +            OPENSSL_sparcv9cap_P[0] |= SPARCV9_TICK_PRIVILEGED;
   104 +        if (_sparcv9_vis1_instrument() < 12) {
   100 +        if (_sparcv9_vis1_instrument() < 12) {
   105 +            OPENSSL_sparcv9cap_P |= SPARCV9_VIS1|SPARCV9_PREFER_FPU;
   101 +            OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS1|SPARCV9_PREFER_FPU;
   106 +            if (ui & AV_SPARC_VIS2)
   102 +            if (ui & AV_SPARC_VIS2)
   107 +                OPENSSL_sparcv9cap_P |= SPARCV9_VIS2;
   103 +                OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS2;
   108          }
   104          }
   109      }
   105      }
   110  
   106  
   111 -    if (sigsetjmp(common_jmp, 1) == 0) {
   107 -    if (sigsetjmp(common_jmp, 1) == 0) {
   112 -        _sparcv9_fmadd_probe();
   108 -        _sparcv9_fmadd_probe();
   113 +    if (ui & AV_SPARC_FMAF)
   109 +    if (ui & AV_SPARC_FMAF) {
   114          OPENSSL_sparcv9cap_P |= SPARCV9_FMADD;
   110          OPENSSL_sparcv9cap_P[0] |= SPARCV9_FMADD;
       
   111      }
       
   112  
       
   113 @@ -303,36 +279,23 @@
       
   114       * VIS3 flag is tested independently from VIS1, unlike VIS2 that is,
       
   115       * because VIS3 defines even integer instructions.
       
   116       */
       
   117 -    if (sigsetjmp(common_jmp, 1) == 0) {
       
   118 -        _sparcv9_vis3_probe();
       
   119 -        OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS3;
       
   120 +    if (ui & AV_SPARC_VIS3) {
       
   121 +            OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS3;
       
   122      }
       
   123 -# if 0                          /* was planned at some point but never
       
   124 -                                 * implemented in hardware */
       
   125 -    if (sigsetjmp(common_jmp, 1) == 0) {
       
   126 -        (void)_sparcv9_random();
       
   127 -        OPENSSL_sparcv9cap_P[0] |= SPARCV9_RANDOM;
   115 -    }
   128 -    }
   116 -
   129 -# endif
       
   130  
       
   131 -    /*
       
   132 -     * In wait for better solution _sparcv9_rdcfr is masked by
       
   133 -     * VIS3 flag, because it goes to uninterruptable endless
       
   134 -     * loop on UltraSPARC II running Solaris. Things might be
       
   135 -     * different on Linux...
       
   136 -     */
       
   137 -    if ((OPENSSL_sparcv9cap_P[0] & SPARCV9_VIS3) &&
       
   138 -        sigsetjmp(common_jmp, 1) == 0) {
       
   139 +#define AV_T4_MECHS     (AV_SPARC_AES | AV_SPARC_DES | AV_SPARC_KASUMI | \
       
   140 +                         AV_SPARC_CAMELLIA | AV_SPARC_MD5 | AV_SPARC_SHA1 | \
       
   141 +                         AV_SPARC_SHA256 | AV_SPARC_SHA512 | AV_SPARC_MPMUL | \
       
   142 +                         AV_SPARC_CRC32C)
       
   143 +
       
   144 +    if ((OPENSSL_sparcv9cap_P[0]&SPARCV9_VIS3) && (ui & AV_T4_MECHS)) {
       
   145          OPENSSL_sparcv9cap_P[1] = (unsigned int)_sparcv9_rdcfr();
       
   146      }
       
   147  
   117 -    sigaction(SIGBUS, &bus_oact, NULL);
   148 -    sigaction(SIGBUS, &bus_oact, NULL);
   118 -    sigaction(SIGILL, &ill_oact, NULL);
   149 -    sigaction(SIGILL, &ill_oact, NULL);
   119 -
   150 +    if (sizeof(size_t) == 8) {
       
   151 +        OPENSSL_sparcv9cap_P[0] |= SPARCV9_64BIT_STACK;
       
   152 +    }
       
   153  
   120 -    sigprocmask(SIG_SETMASK, &oset, NULL);
   154 -    sigprocmask(SIG_SETMASK, &oset, NULL);
   121  }
   155 -
   122  
   156 -    if (sizeof(size_t) == 8)
   123  #endif
   157 -        OPENSSL_sparcv9cap_P[0] |= SPARCV9_64BIT_STACK;
       
   158  # ifdef __linux
       
   159      else {
       
   160          int ret = syscall(340);
   124 --- openssl-1.0.1g/crypto/sparccpuid.S.~1~      Thu May  1 13:07:00 2014
   161 --- openssl-1.0.1g/crypto/sparccpuid.S.~1~      Thu May  1 13:07:00 2014
   125 +++ openssl-1.0.1g/crypto/sparccpuid.S  Thu May  1 13:11:33 2014
   162 +++ openssl-1.0.1g/crypto/sparccpuid.S  Thu May  1 13:11:33 2014
   126 @@ -232,16 +232,6 @@
   163 @@ -232,16 +232,6 @@
   127  .type	_sparcv9_rdtick,#function
   164  .type	_sparcv9_rdtick,#function
   128  .size	_sparcv9_rdtick,.-_sparcv9_rdtick
   165  .size	_sparcv9_rdtick,.-_sparcv9_rdtick
   138 -.size	_sparcv9_vis1_probe,.-_sparcv9_vis1_probe
   175 -.size	_sparcv9_vis1_probe,.-_sparcv9_vis1_probe
   139 -
   176 -
   140  ! Probe and instrument VIS1 instruction. Output is number of cycles it
   177  ! Probe and instrument VIS1 instruction. Output is number of cycles it
   141  ! takes to execute rdtick and pair of VIS1 instructions. US-Tx VIS unit
   178  ! takes to execute rdtick and pair of VIS1 instructions. US-Tx VIS unit
   142  ! is slow (documented to be 6 cycles on T2) and the core is in-order
   179  ! is slow (documented to be 6 cycles on T2) and the core is in-order
   143 @@ -296,24 +286,6 @@
   180 @@ -303,24 +293,6 @@
   144  .type	_sparcv9_vis1_instrument,#function
   181  .type	_sparcv9_vis1_instrument,#function
   145  .size	_sparcv9_vis1_instrument,.-_sparcv9_vis1_instrument
   182  .size	_sparcv9_vis1_instrument,.-_sparcv9_vis1_instrument
   146  
   183  
   147 -.global	_sparcv9_vis2_probe
   184 -.global	_sparcv9_vis2_probe
   148 -.align	8
   185 -.align	8
   160 -	retl
   197 -	retl
   161 -	.word	0x81b80440	!fmaddd	%f0,%f0,%f2,%f0
   198 -	.word	0x81b80440	!fmaddd	%f0,%f0,%f2,%f0
   162 -.type	_sparcv9_fmadd_probe,#function
   199 -.type	_sparcv9_fmadd_probe,#function
   163 -.size	_sparcv9_fmadd_probe,.-_sparcv9_fmadd_probe
   200 -.size	_sparcv9_fmadd_probe,.-_sparcv9_fmadd_probe
   164 -
   201 -
   165  .global	OPENSSL_cleanse
   202  .global	_sparcv9_rdcfr
   166  .align	32
   203  .align	8
   167  OPENSSL_cleanse:
   204  _sparcv9_rdcfr: