diff options
author | djm <> | 2011-11-03 02:32:23 +0000 |
---|---|---|
committer | djm <> | 2011-11-03 02:32:23 +0000 |
commit | 113f799ec7d1728f0a5d7ab5b0e3b42e3de56407 (patch) | |
tree | 26d712b25a8fa580b8f2dfc6df470ba5ffea9eb7 /src/lib/libcrypto/sparcv9cap.c | |
parent | 829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2 (diff) | |
download | openbsd-113f799ec7d1728f0a5d7ab5b0e3b42e3de56407.tar.gz openbsd-113f799ec7d1728f0a5d7ab5b0e3b42e3de56407.tar.bz2 openbsd-113f799ec7d1728f0a5d7ab5b0e3b42e3de56407.zip |
import OpenSSL 1.0.0e
Diffstat (limited to 'src/lib/libcrypto/sparcv9cap.c')
-rw-r--r-- | src/lib/libcrypto/sparcv9cap.c | 97 |
1 files changed, 90 insertions, 7 deletions
diff --git a/src/lib/libcrypto/sparcv9cap.c b/src/lib/libcrypto/sparcv9cap.c index 5f31d20bd0..ed195ab402 100644 --- a/src/lib/libcrypto/sparcv9cap.c +++ b/src/lib/libcrypto/sparcv9cap.c | |||
@@ -1,6 +1,8 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include <setjmp.h> | ||
5 | #include <signal.h> | ||
4 | #include <sys/time.h> | 6 | #include <sys/time.h> |
5 | #include <openssl/bn.h> | 7 | #include <openssl/bn.h> |
6 | 8 | ||
@@ -9,6 +11,7 @@ | |||
9 | #define SPARCV9_VIS1 (1<<2) | 11 | #define SPARCV9_VIS1 (1<<2) |
10 | #define SPARCV9_VIS2 (1<<3) /* reserved */ | 12 | #define SPARCV9_VIS2 (1<<3) /* reserved */ |
11 | #define SPARCV9_FMADD (1<<4) /* reserved for SPARC64 V */ | 13 | #define SPARCV9_FMADD (1<<4) /* reserved for SPARC64 V */ |
14 | |||
12 | static int OPENSSL_sparcv9cap_P=SPARCV9_TICK_PRIVILEGED; | 15 | static int OPENSSL_sparcv9cap_P=SPARCV9_TICK_PRIVILEGED; |
13 | 16 | ||
14 | int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num) | 17 | int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num) |
@@ -23,10 +26,14 @@ int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_U | |||
23 | return bn_mul_mont_int(rp,ap,bp,np,n0,num); | 26 | return bn_mul_mont_int(rp,ap,bp,np,n0,num); |
24 | } | 27 | } |
25 | 28 | ||
29 | unsigned long _sparcv9_rdtick(void); | ||
30 | void _sparcv9_vis1_probe(void); | ||
31 | unsigned long _sparcv9_vis1_instrument(void); | ||
32 | void _sparcv9_vis2_probe(void); | ||
33 | void _sparcv9_fmadd_probe(void); | ||
34 | |||
26 | unsigned long OPENSSL_rdtsc(void) | 35 | unsigned long OPENSSL_rdtsc(void) |
27 | { | 36 | { |
28 | unsigned long _sparcv9_rdtick(void); | ||
29 | |||
30 | if (OPENSSL_sparcv9cap_P&SPARCV9_TICK_PRIVILEGED) | 37 | if (OPENSSL_sparcv9cap_P&SPARCV9_TICK_PRIVILEGED) |
31 | #if defined(__sun) && defined(__SVR4) | 38 | #if defined(__sun) && defined(__SVR4) |
32 | return gethrtime(); | 39 | return gethrtime(); |
@@ -37,8 +44,11 @@ unsigned long OPENSSL_rdtsc(void) | |||
37 | return _sparcv9_rdtick(); | 44 | return _sparcv9_rdtick(); |
38 | } | 45 | } |
39 | 46 | ||
40 | #if defined(__sun) && defined(__SVR4) | 47 | #if 0 && defined(__sun) && defined(__SVR4) |
41 | 48 | /* This code path is disabled, because of incompatibility of | |
49 | * libdevinfo.so.1 and libmalloc.so.1 (see below for details) | ||
50 | */ | ||
51 | #include <malloc.h> | ||
42 | #include <dlfcn.h> | 52 | #include <dlfcn.h> |
43 | #include <libdevinfo.h> | 53 | #include <libdevinfo.h> |
44 | #include <sys/systeminfo.h> | 54 | #include <sys/systeminfo.h> |
@@ -110,7 +120,21 @@ void OPENSSL_cpuid_setup(void) | |||
110 | return; | 120 | return; |
111 | } | 121 | } |
112 | } | 122 | } |
113 | 123 | #ifdef M_KEEP | |
124 | /* | ||
125 | * Solaris libdevinfo.so.1 is effectively incomatible with | ||
126 | * libmalloc.so.1. Specifically, if application is linked with | ||
127 | * -lmalloc, it crashes upon startup with SIGSEGV in | ||
128 | * free(3LIBMALLOC) called by di_fini. Prior call to | ||
129 | * mallopt(M_KEEP,0) somehow helps... But not always... | ||
130 | */ | ||
131 | if ((h = dlopen(NULL,RTLD_LAZY))) | ||
132 | { | ||
133 | union { void *p; int (*f)(int,int); } sym; | ||
134 | if ((sym.p = dlsym(h,"mallopt"))) (*sym.f)(M_KEEP,0); | ||
135 | dlclose(h); | ||
136 | } | ||
137 | #endif | ||
114 | if ((h = dlopen("libdevinfo.so.1",RTLD_LAZY))) do | 138 | if ((h = dlopen("libdevinfo.so.1",RTLD_LAZY))) do |
115 | { | 139 | { |
116 | di_init_t di_init; | 140 | di_init_t di_init; |
@@ -137,9 +161,19 @@ void OPENSSL_cpuid_setup(void) | |||
137 | 161 | ||
138 | #else | 162 | #else |
139 | 163 | ||
164 | static sigjmp_buf common_jmp; | ||
165 | static void common_handler(int sig) { siglongjmp(common_jmp,sig); } | ||
166 | |||
140 | void OPENSSL_cpuid_setup(void) | 167 | void OPENSSL_cpuid_setup(void) |
141 | { | 168 | { |
142 | char *e; | 169 | char *e; |
170 | struct sigaction common_act,ill_oact,bus_oact; | ||
171 | sigset_t all_masked,oset; | ||
172 | int sig; | ||
173 | static int trigger=0; | ||
174 | |||
175 | if (trigger) return; | ||
176 | trigger=1; | ||
143 | 177 | ||
144 | if ((e=getenv("OPENSSL_sparcv9cap"))) | 178 | if ((e=getenv("OPENSSL_sparcv9cap"))) |
145 | { | 179 | { |
@@ -147,8 +181,57 @@ void OPENSSL_cpuid_setup(void) | |||
147 | return; | 181 | return; |
148 | } | 182 | } |
149 | 183 | ||
150 | /* For now we assume that the rest supports UltraSPARC-I* only */ | 184 | /* Initial value, fits UltraSPARC-I&II... */ |
151 | OPENSSL_sparcv9cap_P |= SPARCV9_PREFER_FPU|SPARCV9_VIS1; | 185 | OPENSSL_sparcv9cap_P = SPARCV9_PREFER_FPU|SPARCV9_TICK_PRIVILEGED; |
186 | |||
187 | sigfillset(&all_masked); | ||
188 | sigdelset(&all_masked,SIGILL); | ||
189 | sigdelset(&all_masked,SIGTRAP); | ||
190 | #ifdef SIGEMT | ||
191 | sigdelset(&all_masked,SIGEMT); | ||
192 | #endif | ||
193 | sigdelset(&all_masked,SIGFPE); | ||
194 | sigdelset(&all_masked,SIGBUS); | ||
195 | sigdelset(&all_masked,SIGSEGV); | ||
196 | sigprocmask(SIG_SETMASK,&all_masked,&oset); | ||
197 | |||
198 | memset(&common_act,0,sizeof(common_act)); | ||
199 | common_act.sa_handler = common_handler; | ||
200 | common_act.sa_mask = all_masked; | ||
201 | |||
202 | sigaction(SIGILL,&common_act,&ill_oact); | ||
203 | sigaction(SIGBUS,&common_act,&bus_oact);/* T1 fails 16-bit ldda [on Linux] */ | ||
204 | |||
205 | if (sigsetjmp(common_jmp,1) == 0) | ||
206 | { | ||
207 | _sparcv9_rdtick(); | ||
208 | OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED; | ||
209 | } | ||
210 | |||
211 | if (sigsetjmp(common_jmp,1) == 0) | ||
212 | { | ||
213 | _sparcv9_vis1_probe(); | ||
214 | OPENSSL_sparcv9cap_P |= SPARCV9_VIS1; | ||
215 | /* detect UltraSPARC-Tx, see sparccpud.S for details... */ | ||
216 | if (_sparcv9_vis1_instrument() >= 12) | ||
217 | OPENSSL_sparcv9cap_P &= ~(SPARCV9_VIS1|SPARCV9_PREFER_FPU); | ||
218 | else | ||
219 | { | ||
220 | _sparcv9_vis2_probe(); | ||
221 | OPENSSL_sparcv9cap_P |= SPARCV9_VIS2; | ||
222 | } | ||
223 | } | ||
224 | |||
225 | if (sigsetjmp(common_jmp,1) == 0) | ||
226 | { | ||
227 | _sparcv9_fmadd_probe(); | ||
228 | OPENSSL_sparcv9cap_P |= SPARCV9_FMADD; | ||
229 | } | ||
230 | |||
231 | sigaction(SIGBUS,&bus_oact,NULL); | ||
232 | sigaction(SIGILL,&ill_oact,NULL); | ||
233 | |||
234 | sigprocmask(SIG_SETMASK,&oset,NULL); | ||
152 | } | 235 | } |
153 | 236 | ||
154 | #endif | 237 | #endif |