120 #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
121 static double SSLeay_MSVC5_hack=0.0;
170 #if CRYPTO_NUM_LOCKS != 41
171 # error "Inconsistency between crypto.h and cryptlib.c"
186 const char *
file,
int line)=0;
187 static int (
MS_FAR *add_lock_callback)(
int *pointer,
int amount,
188 int type,
const char *
file,
int line)=0;
189 #ifndef OPENSSL_NO_DEPRECATED
190 static unsigned long (
MS_FAR *id_callback)(
void)=0;
193 static struct CRYPTO_dynlock_value *(
MS_FAR *dynlock_create_callback)
194 (
const char *
file,
int line)=0;
195 static void (
MS_FAR *dynlock_lock_callback)(
int mode,
196 struct CRYPTO_dynlock_value *l,
const char *
file,
int line)=0;
197 static void (
MS_FAR *dynlock_destroy_callback)(
struct CRYPTO_dynlock_value *l,
198 const char *
file,
int line)=0;
205 #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
210 SSLeay_MSVC5_hack=(double)name[0]*(
double)name[1];
241 if (dynlock_create_callback == NULL)
247 if ((dyn_locks == NULL)
263 pointer->
data = dynlock_create_callback(__FILE__,__LINE__);
264 if (pointer->
data == NULL)
289 dynlock_destroy_callback(pointer->
data,__FILE__,__LINE__);
302 if (dynlock_destroy_callback == NULL)
319 fprintf(stderr,
"CRYPTO_destroy_dynlockid, bad reference count\n");
335 dynlock_destroy_callback(pointer->
data,__FILE__,__LINE__);
356 return pointer->
data;
361 (
const char *file,
int line)
363 return(dynlock_create_callback);
367 struct CRYPTO_dynlock_value *l,
const char *
file,
int line)
369 return(dynlock_lock_callback);
373 (
struct CRYPTO_dynlock_value *l,
const char *
file,
int line)
375 return(dynlock_destroy_callback);
379 (
const char *file,
int line))
381 dynlock_create_callback=
func;
385 struct CRYPTO_dynlock_value *l,
const char *file,
int line))
387 dynlock_lock_callback=
func;
391 (
struct CRYPTO_dynlock_value *l,
const char *file,
int line))
393 dynlock_destroy_callback=
func;
400 return(locking_callback);
404 const char *
file,
int line)
406 return(add_lock_callback);
410 const char *file,
int line))
416 locking_callback=
func;
420 const char *file,
int line))
422 add_lock_callback=
func;
430 memset(
id, 0,
sizeof(*
id));
434 static const unsigned char hash_coeffs[] = { 3, 5, 7, 11, 13, 17, 19, 23 };
437 unsigned char *dest = (
void *)&id->
val;
438 unsigned int accum = 0;
439 unsigned char dnum =
sizeof(id->
val);
441 memset(
id, 0,
sizeof(*
id));
443 if (
sizeof(id->
val) >=
sizeof(id->
ptr))
446 id->val = (
unsigned long)id->
ptr;
461 const unsigned char *src = (
void *)&id->
ptr;
462 unsigned char snum =
sizeof(id->
ptr);
464 accum += *(src++) * hash_coeffs[(snum + dnum) & 7];
466 *(dest++) = accum & 255;
472 if (threadid_callback)
474 threadid_callback =
func;
480 return threadid_callback;
485 if (threadid_callback)
487 threadid_callback(
id);
490 #ifndef OPENSSL_NO_DEPRECATED
499 #ifdef OPENSSL_SYS_WIN16
501 #elif defined(OPENSSL_SYS_WIN32)
503 #elif defined(OPENSSL_SYS_BEOS)
513 return memcmp(a, b,
sizeof(*a));
518 memcpy(dest, src,
sizeof(*src));
526 #ifndef OPENSSL_NO_DEPRECATED
541 if (id_callback == NULL)
543 #ifdef OPENSSL_SYS_WIN16
544 ret=(
unsigned long)GetCurrentTask();
545 #elif defined(OPENSSL_SYS_WIN32)
546 ret=(
unsigned long)GetCurrentThreadId();
547 #elif defined(GETPID_IS_MEANINGLESS)
549 #elif defined(OPENSSL_SYS_BEOS)
550 ret=(
unsigned long)find_thread(NULL);
552 ret=(
unsigned long)getpid();
566 char *rw_text,*operation_text;
569 operation_text=
"lock ";
571 operation_text=
"unlock";
573 operation_text=
"ERROR ";
583 fprintf(stderr,
"lock:%08lx:(%s)%s %-18s %s:%d\n",
590 if (dynlock_lock_callback != NULL)
592 struct CRYPTO_dynlock_value *pointer
597 dynlock_lock_callback(mode, pointer, file, line);
603 if (locking_callback != NULL)
604 locking_callback(mode,type,file,line);
612 if (add_lock_callback != NULL)
615 int before= *pointer;
618 ret=add_lock_callback(pointer,amount,type,file,line);
623 fprintf(stderr,
"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
634 ret= *pointer+amount;
639 fprintf(stderr,
"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
657 return(lock_names[type]);
664 #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
665 defined(__INTEL__) || \
666 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
670 {
if (
sizeof(
long)==4)
676 OPENSSL_ia32cap_P[1]=0;
677 return (
unsigned long *)OPENSSL_ia32cap_P;
680 #if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY)
681 #define OPENSSL_CPUID_SETUP
683 typedef unsigned __int64 IA32CAP;
685 typedef unsigned long long IA32CAP;
688 {
static int trigger=0;
689 IA32CAP OPENSSL_ia32_cpuid(
void);
696 if ((env=getenv(
"OPENSSL_ia32cap"))) {
697 int off = (env[0]==
'~')?1:0;
699 if (!sscanf(env+off,
"%I64i",&vec)) vec = strtoul(env+off,NULL,0);
701 if (!sscanf(env+off,
"%lli",(
long long *)&vec)) vec = strtoul(env+off,NULL,0);
703 if (off) vec = OPENSSL_ia32_cpuid()&~vec;
706 vec = OPENSSL_ia32_cpuid();
712 OPENSSL_ia32cap_P[0] = (
unsigned int)vec|(1<<10);
713 OPENSSL_ia32cap_P[1] = (
unsigned int)(vec>>32);
721 #if !defined(OPENSSL_CPUID_SETUP) && !defined(OPENSSL_CPUID_OBJ)
725 #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(_WINDLL)
736 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
741 case DLL_PROCESS_ATTACH:
743 #if defined(_WIN32_WINNT)
745 IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)hinstDLL;
746 IMAGE_NT_HEADERS *nt_headers;
748 if (dos_header->e_magic==IMAGE_DOS_SIGNATURE)
750 nt_headers = (IMAGE_NT_HEADERS *)((
char *)dos_header
751 + dos_header->e_lfanew);
752 if (nt_headers->Signature==IMAGE_NT_SIGNATURE &&
753 hinstDLL!=(HINSTANCE)(nt_headers->OptionalHeader.ImageBase))
754 OPENSSL_NONPIC_relocated=1;
759 case DLL_THREAD_ATTACH:
761 case DLL_THREAD_DETACH:
763 case DLL_PROCESS_DETACH:
770 #if defined(_WIN32) && !defined(__CYGWIN__)
774 #if defined(_UNICODE) || defined(__UNICODE__)
775 #define _vsntprintf _vsnwprintf
777 #define _vsntprintf _vsnprintf
781 #define alloca _alloca
784 #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
789 static union {
void *
p; int (*
f)(
void); } _OPENSSL_isservice = { NULL };
791 if (_OPENSSL_isservice.p == NULL) {
792 HANDLE h = GetModuleHandle(NULL);
794 _OPENSSL_isservice.p = GetProcAddress(h,
"_OPENSSL_isservice");
795 if (_OPENSSL_isservice.p == NULL)
796 _OPENSSL_isservice.p = (
void *)-1;
799 if (_OPENSSL_isservice.p != (
void *)-1)
800 return (*_OPENSSL_isservice.f)();
802 (
void)GetDesktopWindow();
804 h = GetProcessWindowStation();
805 if (h==NULL)
return -1;
807 if (GetUserObjectInformationW (h,UOI_NAME,NULL,0,&len) ||
808 GetLastError() != ERROR_INSUFFICIENT_BUFFER)
811 if (len>512)
return -1;
813 name=(WCHAR *)alloca(len+
sizeof(WCHAR));
814 if (!GetUserObjectInformationW (h,UOI_NAME,name,len,&len))
818 name[len/
sizeof(WCHAR)]=L
'\0';
823 if (wcsstr(name,L
"Service-0x"))
return 1;
826 if (!wcsstr(name,L
"WinSta0"))
return 1;
838 #ifdef STD_ERROR_HANDLE
841 if ((h=GetStdHandle(STD_ERROR_HANDLE)) != NULL &&
842 GetFileType(h)!=FILE_TYPE_UNKNOWN)
845 vfprintf (stderr,fmta,ap);
851 if (
sizeof(TCHAR)==
sizeof(
char))
852 fmt=(
const TCHAR *)fmta;
855 size_t len_0=strlen(fmta)+1,i;
858 fmtw = (WCHAR *)alloca(len_0*
sizeof(WCHAR));
859 if (fmtw == NULL) { fmt=(
const TCHAR *)L
"no stack?";
break; }
861 #ifndef OPENSSL_NO_MULTIBYTE
862 if (!MultiByteToWideChar(CP_ACP,0,fmta,len_0,fmtw,len_0))
864 for (i=0;i<len_0;i++) fmtw[i]=(WCHAR)fmta[i];
866 for (i=0;i<len_0;i++)
867 {
if (fmtw[i]==L
'%')
do
870 {
case L
'0':
case L
'1':
case L
'2':
case L
'3':
case L
'4':
871 case L
'5':
case L
'6':
case L
'7':
case L
'8':
case L
'9':
872 case L
'.':
case L
'*':
873 case L
'-': i++; keepgoing=1;
break;
874 case L
's': fmtw[i+1]=L
'S';
break;
875 case L
'S': fmtw[i+1]=L
's';
break;
876 case L
'c': fmtw[i+1]=L
'C';
break;
877 case L
'C': fmtw[i+1]=L
'c';
break;
881 fmt = (
const TCHAR *)fmtw;
885 _vsntprintf (buf,
sizeof(buf)/
sizeof(TCHAR)-1,fmt,ap);
886 buf [
sizeof(buf)/
sizeof(TCHAR)-1] = _T(
'\0');
889 #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
892 { HANDLE h = RegisterEventSource(0,_T(
"OPENSSL"));
893 const TCHAR *pmsg=buf;
894 ReportEvent(h,EVENTLOG_ERROR_TYPE,0,0,0,1,0,&pmsg,0);
895 DeregisterEventSource(h);
899 MessageBox (NULL,buf,_T(
"OpenSSL: FATAL"),MB_OK|MB_ICONSTOP);
906 vfprintf (stderr,fmta,ap);
912 void OpenSSLDie(
const char *file,
int line,
const char *assertion)
915 "%s(%d): OpenSSL internal error, assertion failed: %s\n",
916 file,line,assertion);
917 #if !defined(_WIN32) || defined(__CYGWIN__)