2 * msvcr90 specific functions
4 * Copyright 2010 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #define THISCALL(func) __thiscall_ ## func
32 #define __thiscall __stdcall
33 #define DEFINE_THISCALL_WRAPPER(func,args) \
34 extern void THISCALL(func)(void); \
35 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
39 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
41 extern void *call_thiscall_func
;
42 __ASM_GLOBAL_FUNC(call_thiscall_func
,
49 #define call_func1(func,this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)(func,this)
50 #define call_func2(func,this,a) ((void* (WINAPI*)(void*,void*,const void*))&call_thiscall_func)(func,this,(const void*)(a))
51 #define call_func3(func,this,a,b) ((void* (WINAPI*)(void*,void*,const void*,const void*))&call_thiscall_func)(func,this,(const void*)(a),(const void*)(b))
55 #define __thiscall __cdecl
56 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
58 #define call_func1(func,this) func(this)
59 #define call_func2(func,this,a) func(this,a)
60 #define call_func3(func,this,a,b) func(this,a,b)
64 typedef void (__cdecl
*MSVCRT__se_translator_function
)(unsigned int code
, struct _EXCEPTION_POINTERS
*info
);
66 static void* (__cdecl
*MSVCRT_operator_new
)(size_t);
67 static void (__cdecl
*MSVCRT_operator_delete
)(void*);
68 static MSVCRT__se_translator_function (__cdecl
*MSVCRT__set_se_translator
)(MSVCRT__se_translator_function
);
69 static void* (__thiscall
*MSVCRT_exception_ctor
)(void*, const char**);
70 static void* (__thiscall
*MSVCRT_exception_ctor_noalloc
)(void*, char**, int);
71 static void* (__thiscall
*MSVCRT_exception_copy_ctor
)(void*, const void*);
72 static void (__thiscall
*MSVCRT_exception_dtor
)(void*);
74 static void init_cxx_funcs(void)
76 HMODULE hmod
= GetModuleHandleA("msvcrt.dll");
78 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
80 MSVCRT_operator_new
= (void*)GetProcAddress(hmod
, "??2@YAPEAX_K@Z");
81 MSVCRT_operator_delete
= (void*)GetProcAddress(hmod
, "??3@YAXPEAX@Z");
82 MSVCRT__set_se_translator
= (void*)GetProcAddress(hmod
,
83 "?_set_se_translator@@YAP6AXIPEAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z");
84 MSVCRT_exception_ctor
= (void*)GetProcAddress(hmod
, "??0exception@@QEAA@AEBQEBD@Z");
85 MSVCRT_exception_ctor_noalloc
= (void*)GetProcAddress(hmod
, "??0exception@@QEAA@AEBQEBDH@Z");
86 MSVCRT_exception_copy_ctor
= (void*)GetProcAddress(hmod
, "??0exception@@QEAA@AEBV0@@Z");
87 MSVCRT_exception_dtor
= (void*)GetProcAddress(hmod
, "??1exception@@UEAA@XZ");
91 MSVCRT_operator_new
= (void*)GetProcAddress(hmod
, "??2@YAPAXI@Z");
92 MSVCRT_operator_delete
= (void*)GetProcAddress(hmod
, "??3@YAXPAX@Z");
93 MSVCRT__set_se_translator
= (void*)GetProcAddress(hmod
,
94 "?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z");
95 MSVCRT_exception_ctor
= (void*)GetProcAddress(hmod
, "??0exception@@QAE@ABQBD@Z");
96 MSVCRT_exception_ctor_noalloc
= (void*)GetProcAddress(hmod
, "??0exception@@QAE@ABQBDH@Z");
97 MSVCRT_exception_copy_ctor
= (void*)GetProcAddress(hmod
, "??0exception@@QAE@ABV0@@Z");
98 MSVCRT_exception_dtor
= (void*)GetProcAddress(hmod
, "??1exception@@UAE@XZ");
102 /*********************************************************************
103 * DllMain (MSVCR90.@)
105 BOOL WINAPI
DllMain(HINSTANCE hdll
, DWORD reason
, LPVOID reserved
)
109 case DLL_PROCESS_ATTACH
:
110 DisableThreadLibraryCalls(hdll
);
112 _set_printf_count_output(0);
117 /*********************************************************************
118 * _decode_pointer (MSVCR90.@)
120 * cdecl version of DecodePointer
123 void * CDECL
MSVCR90_decode_pointer(void * ptr
)
125 return DecodePointer(ptr
);
128 /*********************************************************************
129 * _encode_pointer (MSVCR90.@)
131 * cdecl version of EncodePointer
134 void * CDECL
MSVCR90_encode_pointer(void * ptr
)
136 return EncodePointer(ptr
);
139 /*********************************************************************
140 * ??2@YAPAXI@Z (MSVCR90.@)
142 * Naver LINE expects that this function is implemented inside msvcr90
144 void* CDECL
MSVCR90_operator_new(size_t size
)
146 return MSVCRT_operator_new(size
);
149 /*********************************************************************
150 * ??3@YAXPAX@Z (MSVCR90.@)
152 * Naver LINE expects that this function is implemented inside msvcr90
154 void CDECL
MSVCR90_operator_delete(void *ptr
)
156 MSVCRT_operator_delete(ptr
);
159 /*********************************************************************
160 * ?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z (MSVCR90.@)
162 * Naver LINE expects that this function is implemented inside msvcr90
164 MSVCRT__se_translator_function CDECL
MSVCR90__set_se_translator(MSVCRT__se_translator_function func
)
166 return MSVCRT__set_se_translator(func
);
169 /* ??0exception@std@@QAE@ABQBD@Z */
170 /* ??0exception@std@@QEAA@AEBQEBD@Z */
171 DEFINE_THISCALL_WRAPPER(exception_ctor
, 8)
172 void* __thiscall
exception_ctor(void *this, const char **name
)
174 return call_func2(MSVCRT_exception_ctor
, this, name
);
177 /* ??0exception@std@@QAE@ABQBDH@Z */
178 /* ??0exception@std@@QEAA@AEBQEBDH@Z */
179 DEFINE_THISCALL_WRAPPER(exception_ctor_noalloc
, 12)
180 void* __thiscall
exception_ctor_noalloc(void *this, char **name
, int noalloc
)
182 return call_func3(MSVCRT_exception_ctor_noalloc
, this, name
, noalloc
);
185 /* ??0exception@std@@QAE@ABV01@@Z */
186 /* ??0exception@std@@QEAA@AEBV01@@Z */
187 DEFINE_THISCALL_WRAPPER(exception_copy_ctor
, 8)
188 void* __thiscall
exception_copy_ctor(void *this, const void *rhs
)
190 return call_func2(MSVCRT_exception_copy_ctor
, this, rhs
);
193 /* ??1exception@std@@UAE@XZ */
194 /* ??1exception@std@@UEAA@XZ */
195 DEFINE_THISCALL_WRAPPER(exception_dtor
, 4)
196 void __thiscall
exception_dtor(void *this)
198 call_func1(MSVCRT_exception_dtor
, this);