2005-05-17 00:08:28 +00:00
|
|
|
#if (defined(_WIN64) || defined(_WIN32_WCE)) && !defined(UNICODE)
|
2004-05-25 20:31:03 +00:00
|
|
|
#define UNICODE
|
|
|
|
#endif
|
|
|
|
#if defined(UNICODE) && !defined(_UNICODE)
|
|
|
|
#define _UNICODE
|
|
|
|
#endif
|
|
|
|
#if defined(_UNICODE) && !defined(UNICODE)
|
|
|
|
#define UNICODE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "uplink.h"
|
2005-05-17 00:08:28 +00:00
|
|
|
void OPENSSL_showfatal(const char *,...);
|
2004-05-25 20:31:03 +00:00
|
|
|
|
|
|
|
static TCHAR msg[128];
|
|
|
|
|
2005-05-17 00:08:28 +00:00
|
|
|
static void unimplemented (void)
|
|
|
|
{ OPENSSL_showfatal (sizeof(TCHAR)==sizeof(char)?"%s\n":"%S\n",msg);
|
2004-05-25 20:31:03 +00:00
|
|
|
ExitProcess (1);
|
|
|
|
}
|
|
|
|
|
2005-05-17 00:08:28 +00:00
|
|
|
void OPENSSL_Uplink (volatile void **table, int index)
|
|
|
|
{ static HMODULE volatile apphandle=NULL;
|
|
|
|
static void ** volatile applinktable=NULL;
|
2004-05-25 20:31:03 +00:00
|
|
|
int len;
|
2005-05-17 00:08:28 +00:00
|
|
|
void (*func)(void)=unimplemented;
|
|
|
|
HANDLE h;
|
|
|
|
void **p;
|
|
|
|
|
|
|
|
/* Note that the below code is not MT-safe in respect to msg
|
|
|
|
* buffer, but what's the worst thing that can happen? Error
|
|
|
|
* message might be misleading or corrupted. As error condition
|
|
|
|
* is fatal and should never be risen, I accept the risk... */
|
|
|
|
/* One can argue that I should have used InterlockedExchangePointer
|
|
|
|
* or something to update static variables and table[]. Well,
|
|
|
|
* store instructions are as atomic as they can get and assigned
|
|
|
|
* values are effectively constant... So that volatile qualifier
|
|
|
|
* should be sufficient [it prohibits compiler to reorder memory
|
|
|
|
* access instructions]. */
|
|
|
|
do {
|
|
|
|
len = _stprintf (msg,_T("OPENSSL_Uplink(%p,%02X): "),table,index);
|
|
|
|
_tcscpy (msg+len,_T("unimplemented function"));
|
|
|
|
|
|
|
|
if ((h=apphandle)==NULL)
|
|
|
|
{ if ((h=GetModuleHandle(NULL))==NULL)
|
|
|
|
{ apphandle=(HMODULE)-1;
|
|
|
|
_tcscpy (msg+len,_T("no host application"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
apphandle = h;
|
2004-05-25 20:31:03 +00:00
|
|
|
}
|
2005-05-17 00:08:28 +00:00
|
|
|
if ((h=apphandle)==(HMODULE)-1) /* revalidate */
|
|
|
|
break;
|
|
|
|
|
2004-05-25 20:31:03 +00:00
|
|
|
if (applinktable==NULL)
|
2005-05-17 00:08:28 +00:00
|
|
|
{ void**(*applink)();
|
|
|
|
|
|
|
|
applink=(void**(*)())GetProcAddress(h,"OPENSSL_Applink");
|
|
|
|
if (applink==NULL)
|
|
|
|
{ apphandle=(HMODULE)-1;
|
|
|
|
_tcscpy (msg+len,_T("no OPENSSL_Applink"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = (*applink)();
|
|
|
|
if (p==NULL)
|
|
|
|
{ apphandle=(HMODULE)-1;
|
|
|
|
_tcscpy (msg+len,_T("no ApplinkTable"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
applinktable = p;
|
2004-05-25 20:31:03 +00:00
|
|
|
}
|
2006-09-18 19:44:23 +00:00
|
|
|
else
|
|
|
|
p = applinktable;
|
2004-05-25 20:31:03 +00:00
|
|
|
|
2005-05-17 00:08:28 +00:00
|
|
|
if (index > (int)p[0])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (p[index]) func = p[index];
|
|
|
|
} while (0);
|
2004-05-25 20:31:03 +00:00
|
|
|
|
2005-05-17 00:08:28 +00:00
|
|
|
table[index] = func;
|
2004-05-25 20:31:03 +00:00
|
|
|
}
|
|
|
|
|
2005-05-17 00:08:28 +00:00
|
|
|
#if defined(_MSC_VER) && defined(_M_IX86) && !defined(OPENSSL_NO_INLINE_ASM)
|
2004-05-25 20:31:03 +00:00
|
|
|
#define LAZY(i) \
|
2005-05-17 00:08:28 +00:00
|
|
|
__declspec(naked) static void lazy##i (void) { \
|
2004-05-25 20:31:03 +00:00
|
|
|
_asm push i \
|
|
|
|
_asm push OFFSET OPENSSL_UplinkTable \
|
|
|
|
_asm call OPENSSL_Uplink \
|
|
|
|
_asm add esp,8 \
|
|
|
|
_asm jmp OPENSSL_UplinkTable+4*i }
|
|
|
|
|
2005-05-17 00:08:28 +00:00
|
|
|
#if APPLINK_MAX>25
|
2004-05-25 20:31:03 +00:00
|
|
|
#error "Add more stubs..."
|
|
|
|
#endif
|
|
|
|
/* make some in advance... */
|
|
|
|
LAZY(1) LAZY(2) LAZY(3) LAZY(4) LAZY(5)
|
|
|
|
LAZY(6) LAZY(7) LAZY(8) LAZY(9) LAZY(10)
|
|
|
|
LAZY(11) LAZY(12) LAZY(13) LAZY(14) LAZY(15)
|
|
|
|
LAZY(16) LAZY(17) LAZY(18) LAZY(19) LAZY(20)
|
2005-05-17 00:08:28 +00:00
|
|
|
LAZY(21) LAZY(22) LAZY(23) LAZY(24) LAZY(25)
|
2004-05-25 20:31:03 +00:00
|
|
|
void *OPENSSL_UplinkTable[] = {
|
|
|
|
(void *)APPLINK_MAX,
|
|
|
|
lazy1, lazy2, lazy3, lazy4, lazy5,
|
|
|
|
lazy6, lazy7, lazy8, lazy9, lazy10,
|
|
|
|
lazy11,lazy12,lazy13,lazy14,lazy15,
|
|
|
|
lazy16,lazy17,lazy18,lazy19,lazy20,
|
2005-05-17 00:08:28 +00:00
|
|
|
lazy21,lazy22,lazy23,lazy24,lazy25,
|
2004-05-25 20:31:03 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SELFTEST
|
|
|
|
main() { UP_fprintf(UP_stdout,"hello, world!\n"); }
|
|
|
|
#endif
|