2 * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #if (defined(_WIN64) || defined(_WIN32_WCE)) && !defined(UNICODE)
13 #if defined(UNICODE) && !defined(_UNICODE)
16 #if defined(_UNICODE) && !defined(UNICODE)
24 void OPENSSL_showfatal(const char *, ...);
26 static TCHAR msg[128];
28 static void unimplemented(void)
30 OPENSSL_showfatal(sizeof(TCHAR) == sizeof(char) ? "%s\n" : "%S\n", msg);
34 void OPENSSL_Uplink(volatile void **table, int index)
36 static HMODULE volatile apphandle = NULL;
37 static void **volatile applinktable = NULL;
39 void (*func) (void) = unimplemented;
44 * Note that the below code is not MT-safe in respect to msg buffer, but
45 * what's the worst thing that can happen? Error message might be
46 * misleading or corrupted. As error condition is fatal and should never
47 * be risen, I accept the risk...
50 * One can argue that I should have used InterlockedExchangePointer or
51 * something to update static variables and table[]. Well, store
52 * instructions are as atomic as they can get and assigned values are
53 * effectively constant... So that volatile qualifier should be
54 * sufficient [it prohibits compiler to reorder memory access
58 len = _sntprintf(msg, sizeof(msg) / sizeof(TCHAR),
59 _T("OPENSSL_Uplink(%p,%02X): "), table, index);
60 _tcscpy(msg + len, _T("unimplemented function"));
62 if ((h = apphandle) == NULL) {
63 if ((h = GetModuleHandle(NULL)) == NULL) {
64 apphandle = (HMODULE) - 1;
65 _tcscpy(msg + len, _T("no host application"));
70 if ((h = apphandle) == (HMODULE) - 1) /* revalidate */
73 if (applinktable == NULL) {
76 applink = (void **(*)())GetProcAddress(h, "OPENSSL_Applink");
77 if (applink == NULL) {
78 apphandle = (HMODULE) - 1;
79 _tcscpy(msg + len, _T("no OPENSSL_Applink"));
84 apphandle = (HMODULE) - 1;
85 _tcscpy(msg + len, _T("no ApplinkTable"));
92 if (index > (int)p[0])
102 #if defined(_MSC_VER) && defined(_M_IX86)
104 __declspec(naked) static void lazy##i (void) { \
106 _asm push OFFSET OPENSSL_UplinkTable \
107 _asm call OPENSSL_Uplink \
109 _asm jmp OPENSSL_UplinkTable+4*i }
112 # error "Add more stubs..."
114 /* make some in advance... */
115 LAZY(1) LAZY(2) LAZY(3) LAZY(4) LAZY(5)
116 LAZY(6) LAZY(7) LAZY(8) LAZY(9) LAZY(10)
117 LAZY(11) LAZY(12) LAZY(13) LAZY(14) LAZY(15)
118 LAZY(16) LAZY(17) LAZY(18) LAZY(19) LAZY(20)
119 LAZY(21) LAZY(22) LAZY(23) LAZY(24) LAZY(25)
120 void *OPENSSL_UplinkTable[] = {
122 lazy1, lazy2, lazy3, lazy4, lazy5,
123 lazy6, lazy7, lazy8, lazy9, lazy10,
124 lazy11, lazy12, lazy13, lazy14, lazy15,
125 lazy16, lazy17, lazy18, lazy19, lazy20,
126 lazy21, lazy22, lazy23, lazy24, lazy25,
133 UP_fprintf(UP_stdout, "hello, world!\n");