components/openssl/openssl-1.0.1/patches/38_remove_illegal_instruction_calls.patch
branchs11u2-sru8-backport
changeset 4020 8e3f49e23eaa
parent 3285 78460de60ed1
equal deleted inserted replaced
3862:0e46f6a07b7f 4020:8e3f49e23eaa
     1 #
     1 #
     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.1h/crypto/sparcv9cap.c.~1~	Tue Aug  5 14:40:03 2014
     5 --- openssl-1.0.1g/crypto/sparcv9cap.c.~1~	Thu May  1 13:07:00 2014
     6 +++ openssl-1.0.1h/crypto/sparcv9cap.c	Tue Aug  5 15:05:26 2014
     6 +++ openssl-1.0.1g/crypto/sparcv9cap.c	Thu May  1 13:11:33 2014
     7 @@ -6,6 +6,7 @@
     7 @@ -2,10 +2,10 @@
       
     8  #include <stdlib.h>
       
     9  #include <string.h>
       
    10  #include <setjmp.h>
       
    11 -#include <signal.h>
     8  #include <sys/time.h>
    12  #include <sys/time.h>
     9  #include <unistd.h>
    13  #include <unistd.h>
    10  #include <openssl/bn.h>
    14  #include <openssl/bn.h>
    11 +#include <sys/auxv.h>
    15 +#include <sys/auxv.h>
    12  
    16  
    13  #include "sparc_arch.h"
    17  #include "sparc_arch.h"
    14  
    18  
    15 @@ -59,10 +60,8 @@
    19 @@ -59,13 +59,8 @@
    16  void		_sparcv9_vis1_probe(void);
    20  }
    17  unsigned long	_sparcv9_vis1_instrument(void);
    21  
    18  void		_sparcv9_vis2_probe(void);
    22  unsigned long _sparcv9_rdtick(void);
    19 -void		_sparcv9_fmadd_probe(void);
    23 -void _sparcv9_vis1_probe(void);
    20  unsigned long	_sparcv9_rdcfr(void);
    24  unsigned long _sparcv9_vis1_instrument(void);
    21  void		_sparcv9_vis3_probe(void);
    25 -void _sparcv9_vis2_probe(void);
    22 -unsigned long	_sparcv9_random(void);
    26 -void _sparcv9_fmadd_probe(void);
       
    27  unsigned long _sparcv9_rdcfr(void);
       
    28 -void _sparcv9_vis3_probe(void);
       
    29 -unsigned long _sparcv9_random(void);
    23  #ifndef _BOOT
    30  #ifndef _BOOT
    24  size_t 	_sparcv9_vis1_instrument_bus(unsigned int *,size_t);
    31  size_t _sparcv9_vis1_instrument_bus(unsigned int *,size_t);
    25  size_t		_sparcv9_vis1_instrument_bus2(unsigned int *,size_t,size_t);
    32  size_t _sparcv9_vis1_instrument_bus2(unsigned int *,size_t,size_t);
    26 @@ -236,6 +235,7 @@
    33 @@ -235,18 +235,11 @@
    27  	struct sigaction	common_act,ill_oact,bus_oact;
    34 
    28  	sigset_t		all_masked,oset;
    35  #else
    29  	static int trigger=0;
    36 
    30 +	uint_t ui = 0;
    37 -static sigjmp_buf common_jmp;
    31  
    38 -static void common_handler(int sig)
    32  	if (trigger) return;
    39 -{
    33  	trigger=1;
    40 -    siglongjmp(common_jmp, sig);
    34 @@ -250,6 +250,7 @@
    41 -}
    35  
    42 -
    36  	/* Initial value, fits UltraSPARC-I&II... */
    43  void OPENSSL_cpuid_setup(void)
    37  	OPENSSL_sparcv9cap_P[0] = SPARCV9_PREFER_FPU|SPARCV9_TICK_PRIVILEGED;
    44  {
    38 +	(void) getisax(&ui, 1);
    45      char *e;
    39  
    46 -    struct sigaction common_act, ill_oact, bus_oact;
    40  	sigfillset(&all_masked);
    47 -    sigset_t all_masked, oset;
    41  	sigdelset(&all_masked,SIGILL);
    48      static int trigger = 0;
    42 @@ -289,11 +290,8 @@
    49 +    uint_t ui = 0;
    43  			}
    50 
    44  		}
    51      if (trigger)
    45  
    52          return;
    46 -	if (sigsetjmp(common_jmp,1) == 0)
    53 @@ -259,80 +247,40 @@
    47 -		{
    54          return;
    48 -		_sparcv9_fmadd_probe();
    55      }
    49 +	if (ui & AV_SPARC_FMAF)
    56  
    50  		OPENSSL_sparcv9cap_P[0] |= SPARCV9_FMADD;
    57 +    (void) getisax(&ui, 1);
    51 -		}
    58 +
    52  
    59      /* Initial value, fits UltraSPARC-I&II... */
    53  	/*
    60 -    OPENSSL_sparcv9cap_P[0] = SPARCV9_PREFER_FPU | SPARCV9_TICK_PRIVILEGED;
    54  	 * VIS3 flag is tested independently from VIS1, unlike VIS2 that is,
    61 +    OPENSSL_sparcv9cap_P[0] = SPARCV9_BLK;
    55 @@ -305,11 +303,9 @@
    62  
    56  		OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS3;
    63 -    sigfillset(&all_masked);
    57  		}
    64 -    sigdelset(&all_masked, SIGILL);
    58  
    65 -    sigdelset(&all_masked, SIGTRAP);
    59 -	if (sigsetjmp(common_jmp,1) == 0)
    66 -# ifdef SIGEMT
    60 -		{
    67 -    sigdelset(&all_masked, SIGEMT);
    61 -		(void)_sparcv9_random();
    68 -# endif
    62 -		OPENSSL_sparcv9cap_P[0] |= SPARCV9_RANDOM;
    69 -    sigdelset(&all_masked, SIGFPE);
    63 -		}
    70 -    sigdelset(&all_masked, SIGBUS);
    64 +#define	AV_T4_MECHS	(AV_SPARC_AES | AV_SPARC_DES | AV_SPARC_KASUMI | \
    71 -    sigdelset(&all_masked, SIGSEGV);
    65 +			AV_SPARC_CAMELLIA | AV_SPARC_MD5 | AV_SPARC_SHA1 | \
    72 -    sigprocmask(SIG_SETMASK, &all_masked, &oset);
    66 +			AV_SPARC_SHA256 | AV_SPARC_SHA512 | AV_SPARC_MPMUL | AV_SPARC_CRC32C)
    73 -
    67  
    74 -    memset(&common_act, 0, sizeof(common_act));
    68  	/*
    75 -    common_act.sa_handler = common_handler;
    69  	 * In wait for better solution _sparcv9_rdcfr is masked by
    76 -    common_act.sa_mask = all_masked;
    70 @@ -318,10 +314,8 @@
    77 -
    71  	 * different on Linux...
    78 -    sigaction(SIGILL, &common_act, &ill_oact);
    72  	 */
    79 -    sigaction(SIGBUS, &common_act, &bus_oact); /* T1 fails 16-bit ldda [on
    73  	if ((OPENSSL_sparcv9cap_P[0]&SPARCV9_VIS3) &&
    80 -                                                * Linux] */
    74 -	    sigsetjmp(common_jmp,1) == 0)
    81 -
    75 -		{
    82 -    if (sigsetjmp(common_jmp, 1) == 0) {
    76 +		(ui & AV_T4_MECHS))
    83 -        _sparcv9_rdtick();
    77  		OPENSSL_sparcv9cap_P[1] = (unsigned int)_sparcv9_rdcfr();
    84 -        OPENSSL_sparcv9cap_P[0] &= ~SPARCV9_TICK_PRIVILEGED;
    78 -		}
    85 -    }
    79  
    86 -
    80  	sigaction(SIGBUS,&bus_oact,NULL);
    87 -    if (sigsetjmp(common_jmp, 1) == 0) {
    81  	sigaction(SIGILL,&ill_oact,NULL);
    88 -        _sparcv9_vis1_probe();
    82 --- openssl-1.0.1h/crypto/sparccpuid.S.~1~	Mon Aug  4 14:45:58 2014
    89 -        OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS1 | SPARCV9_BLK;
    83 +++ openssl-1.0.1h/crypto/sparccpuid.S	Mon Aug  4 14:51:53 2014
    90 +    if (ui & AV_SPARC_VIS) {
    84 @@ -315,16 +315,6 @@
    91          /* detect UltraSPARC-Tx, see sparccpud.S for details... */
    85  .type	_sparcv9_vis2_probe,#function
    92 -        if (_sparcv9_vis1_instrument() >= 12)
    86  .size	_sparcv9_vis2_probe,.-_sparcv9_vis2_probe
    93 -            OPENSSL_sparcv9cap_P[0] &= ~(SPARCV9_VIS1 | SPARCV9_PREFER_FPU);
    87  
    94 -        else {
       
    95 -            _sparcv9_vis2_probe();
       
    96 -            OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS2;
       
    97 -        }
       
    98 +        if (_sparcv9_vis1_instrument() < 7)
       
    99 +            OPENSSL_sparcv9cap_P[0] |= SPARCV9_TICK_PRIVILEGED;
       
   100 +        if (_sparcv9_vis1_instrument() < 12) {
       
   101 +            OPENSSL_sparcv9cap_P[0] |= (SPARCV9_VIS1 | SPARCV9_PREFER_FPU);
       
   102 +            if (ui & AV_SPARC_VIS2)
       
   103 +                OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS2;
       
   104 +         }
       
   105      }
       
   106  
       
   107 -    if (sigsetjmp(common_jmp, 1) == 0) {
       
   108 -        _sparcv9_fmadd_probe();
       
   109 +    if (ui & AV_SPARC_FMAF)
       
   110          OPENSSL_sparcv9cap_P[0] |= SPARCV9_FMADD;
       
   111 -    }
       
   112  
       
   113      /*
       
   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 -    }
       
   121 +    if (ui & AV_SPARC_VIS3)
       
   122 +            OPENSSL_sparcv9cap_P[0] |= SPARCV9_VIS3;
       
   123  
       
   124 -    if (sigsetjmp(common_jmp,1) == 0) {
       
   125 -        (void)_sparcv9_random();
       
   126 -        OPENSSL_sparcv9cap_P[0] |= SPARCV9_RANDOM;
       
   127 -    }
       
   128 +#define AV_T4_MECHS     (AV_SPARC_AES | AV_SPARC_DES | AV_SPARC_KASUMI | \
       
   129 +                         AV_SPARC_CAMELLIA | AV_SPARC_MD5 | AV_SPARC_SHA1 | \
       
   130 +                         AV_SPARC_SHA256 | AV_SPARC_SHA512 | AV_SPARC_MPMUL | \
       
   131 +                         AV_SPARC_CRC32C)
       
   132  
       
   133 -    /*
       
   134 -     * In wait for better solution _sparcv9_rdcfr is masked by
       
   135 -     * VIS3 flag, because it goes to uninterruptable endless
       
   136 -     * loop on UltraSPARC II running Solaris. Things might be
       
   137 -     * different on Linux...
       
   138 -     */
       
   139 -    if ((OPENSSL_sparcv9cap_P[0]&SPARCV9_VIS3) &&
       
   140 -        sigsetjmp(common_jmp, 1) == 0) {
       
   141 +    if ((OPENSSL_sparcv9cap_P[0]&SPARCV9_VIS3) && (ui & AV_T4_MECHS))
       
   142          OPENSSL_sparcv9cap_P[1] = (unsigned int)_sparcv9_rdcfr();
       
   143 -    }
       
   144  
       
   145 -    sigaction(SIGBUS, &bus_oact, NULL);
       
   146 -    sigaction(SIGILL, &ill_oact, NULL);
       
   147 -
       
   148 -    sigprocmask(SIG_SETMASK, &oset, NULL);
       
   149 -
       
   150      if (sizeof(size_t) == 8)
       
   151          OPENSSL_sparcv9cap_P[0] |= SPARCV9_64BIT_STACK;
       
   152  #ifdef __linux
       
   153 --- openssl-1.0.1g/crypto/sparccpuid.S.~1~      Thu May  1 13:07:00 2014
       
   154 +++ openssl-1.0.1g/crypto/sparccpuid.S  Thu May  1 13:11:33 2014
       
   155 @@ -236,16 +236,6 @@
       
   156  .type	_sparcv9_rdtick,#function
       
   157  .size	_sparcv9_rdtick,.-_sparcv9_rdtick
       
   158  
       
   159 -.global	_sparcv9_vis1_probe
       
   160 -.align	8
       
   161 -_sparcv9_vis1_probe:
       
   162 -	.word	0x81b00d80	!fxor	%f0,%f0,%f0
       
   163 -	add	%sp,BIAS+2,%o1
       
   164 -	retl
       
   165 -	.word	0xc19a5a40	!ldda	[%o1]ASI_FP16_P,%f0
       
   166 -.type	_sparcv9_vis1_probe,#function
       
   167 -.size	_sparcv9_vis1_probe,.-_sparcv9_vis1_probe
       
   168 -
       
   169  ! Probe and instrument VIS1 instruction. Output is number of cycles it
       
   170  ! takes to execute rdtick and pair of VIS1 instructions. US-Tx VIS unit
       
   171  ! is slow (documented to be 6 cycles on T2) and the core is in-order
       
   172 @@ -307,24 +297,6 @@
       
   173  .type	_sparcv9_vis1_instrument,#function
       
   174  .size	_sparcv9_vis1_instrument,.-_sparcv9_vis1_instrument
       
   175  
       
   176 -.global	_sparcv9_vis2_probe
       
   177 -.align	8
       
   178 -_sparcv9_vis2_probe:
       
   179 -	retl
       
   180 -	.word	0x81b00980	!bshuffle	%f0,%f0,%f0
       
   181 -.type	_sparcv9_vis2_probe,#function
       
   182 -.size	_sparcv9_vis2_probe,.-_sparcv9_vis2_probe
       
   183 -
    88 -.global	_sparcv9_fmadd_probe
   184 -.global	_sparcv9_fmadd_probe
    89 -.align	8
   185 -.align	8
    90 -_sparcv9_fmadd_probe:
   186 -_sparcv9_fmadd_probe:
    91 -	.word	0x81b00d80	!fxor	%f0,%f0,%f0
   187 -	.word	0x81b00d80	!fxor	%f0,%f0,%f0
    92 -	.word	0x85b08d82	!fxor	%f2,%f2,%f2
   188 -	.word	0x85b08d82	!fxor	%f2,%f2,%f2
    96 -.size	_sparcv9_fmadd_probe,.-_sparcv9_fmadd_probe
   192 -.size	_sparcv9_fmadd_probe,.-_sparcv9_fmadd_probe
    97 -
   193 -
    98  .global	_sparcv9_rdcfr
   194  .global	_sparcv9_rdcfr
    99  .align	8
   195  .align	8
   100  _sparcv9_rdcfr:
   196  _sparcv9_rdcfr:
   101 @@ -341,14 +331,6 @@
   197 @@ -333,22 +305,6 @@
   102  .type	_sparcv9_vis3_probe,#function
   198  .type	_sparcv9_rdcfr,#function
   103  .size	_sparcv9_vis3_probe,.-_sparcv9_vis3_probe
   199  .size	_sparcv9_rdcfr,.-_sparcv9_rdcfr
   104  
   200  
       
   201 -.global	_sparcv9_vis3_probe
       
   202 -.align	8
       
   203 -_sparcv9_vis3_probe:
       
   204 -	retl
       
   205 -	.word	0x81b022a0	!xmulx	%g0,%g0,%g0
       
   206 -.type	_sparcv9_vis3_probe,#function
       
   207 -.size	_sparcv9_vis3_probe,.-_sparcv9_vis3_probe
       
   208 -
   105 -.global	_sparcv9_random
   209 -.global	_sparcv9_random
   106 -.align	8
   210 -.align	8
   107 -_sparcv9_random:
   211 -_sparcv9_random:
   108 -	retl
   212 -	retl
   109 -	.word	0x91b002a0	!random	%o0
   213 -	.word	0x91b002a0	!random	%o0