2 * Copyright 2010 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcp
);
29 #ifdef __ASM_USE_THISCALL_WRAPPER
31 #define DEFINE_VTBL_WRAPPER(off) \
32 __ASM_GLOBAL_FUNC(vtbl_wrapper_ ## off, \
36 "movl 0(%ecx), %eax\n\t" \
37 "jmp *" #off "(%eax)\n\t")
39 DEFINE_VTBL_WRAPPER(0);
40 DEFINE_VTBL_WRAPPER(4);
41 DEFINE_VTBL_WRAPPER(8);
42 DEFINE_VTBL_WRAPPER(12);
43 DEFINE_VTBL_WRAPPER(16);
44 DEFINE_VTBL_WRAPPER(20);
45 DEFINE_VTBL_WRAPPER(24);
46 DEFINE_VTBL_WRAPPER(28);
47 DEFINE_VTBL_WRAPPER(32);
48 DEFINE_VTBL_WRAPPER(36);
49 DEFINE_VTBL_WRAPPER(40);
50 DEFINE_VTBL_WRAPPER(44);
51 DEFINE_VTBL_WRAPPER(48);
52 DEFINE_VTBL_WRAPPER(52);
53 DEFINE_VTBL_WRAPPER(56);
57 void* (__cdecl
*MSVCRT_operator_new
)(size_t);
58 void (__cdecl
*MSVCRT_operator_delete
)(void*);
59 void* (__cdecl
*MSVCRT_set_new_handler
)(void*);
62 critical_section
* (__thiscall
*critical_section_ctor
)(critical_section
*);
63 void (__thiscall
*critical_section_dtor
)(critical_section
*);
64 void (__thiscall
*critical_section_lock
)(critical_section
*);
65 void (__thiscall
*critical_section_unlock
)(critical_section
*);
66 bool (__thiscall
*critical_section_trylock
)(critical_section
*);
70 bool (__cdecl
*Context_IsCurrentTaskCollectionCanceling
)(void);
73 #define VERSION_STRING(ver) #ver
75 #define MSVCRT_NAME(ver) "ucrtbase.dll"
76 #define CONCRT_NAME(ver) "concrt" VERSION_STRING(ver) ".dll"
78 #define MSVCRT_NAME(ver) "msvcr" VERSION_STRING(ver) ".dll"
82 static void* __cdecl
operator_new(size_t size
)
89 retval
= malloc(size
);
92 TRACE("(%Iu) returning %p\n", size
, retval
);
95 freed
= _callnewh(size
);
98 TRACE("(%Iu) out of memory\n", size
);
99 throw_exception(EXCEPTION_BAD_ALLOC
, "bad allocation");
103 static void __cdecl
operator_delete(void *mem
)
105 TRACE("(%p)\n", mem
);
109 void __cdecl
_invalid_parameter(const wchar_t *expr
, const wchar_t *func
, const wchar_t *file
, unsigned int line
, uintptr_t arg
)
111 _invalid_parameter_noinfo();
115 static void init_cxx_funcs(void)
117 HMODULE hmod
= GetModuleHandleA( MSVCRT_NAME(_MSVCP_VER
) );
118 #if _MSVCP_VER >= 100
122 if (!hmod
) FIXME( "%s not loaded\n", MSVCRT_NAME(_MSVCP_VER
) );
124 #if _MSVCP_VER >= 140
125 MSVCRT_operator_new
= operator_new
;
126 MSVCRT_operator_delete
= operator_delete
;
127 MSVCRT_set_new_handler
= (void*)GetProcAddress(hmod
, "_set_new_handler");
129 hcon
= LoadLibraryA( CONCRT_NAME(_MSVCP_VER
) );
130 if (!hcon
) FIXME( "%s not loaded\n", CONCRT_NAME(_MSVCP_VER
) );
132 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
134 MSVCRT_operator_new
= (void*)GetProcAddress(hmod
, "??2@YAPEAX_K@Z");
135 MSVCRT_operator_delete
= (void*)GetProcAddress(hmod
, "??3@YAXPEAX@Z");
136 MSVCRT_set_new_handler
= (void*)GetProcAddress(hmod
, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z");
140 MSVCRT_operator_new
= (void*)GetProcAddress(hmod
, "??2@YAPAXI@Z");
141 MSVCRT_operator_delete
= (void*)GetProcAddress(hmod
, "??3@YAXPAX@Z");
142 MSVCRT_set_new_handler
= (void*)GetProcAddress(hmod
, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z");
146 #if _MSVCP_VER >= 110
147 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
149 critical_section_ctor
= (void*)GetProcAddress(hcon
, "??0critical_section@Concurrency@@QEAA@XZ");
150 critical_section_dtor
= (void*)GetProcAddress(hcon
, "??1critical_section@Concurrency@@QEAA@XZ");
151 critical_section_lock
= (void*)GetProcAddress(hcon
, "?lock@critical_section@Concurrency@@QEAAXXZ");
152 critical_section_unlock
= (void*)GetProcAddress(hcon
, "?unlock@critical_section@Concurrency@@QEAAXXZ");
153 critical_section_trylock
= (void*)GetProcAddress(hcon
, "?try_lock@critical_section@Concurrency@@QEAA_NXZ");
158 critical_section_ctor
= (void*)GetProcAddress(hcon
, "??0critical_section@Concurrency@@QAA@XZ");
159 critical_section_dtor
= (void*)GetProcAddress(hcon
, "??1critical_section@Concurrency@@QAA@XZ");
160 critical_section_lock
= (void*)GetProcAddress(hcon
, "?lock@critical_section@Concurrency@@QAAXXZ");
161 critical_section_unlock
= (void*)GetProcAddress(hcon
, "?unlock@critical_section@Concurrency@@QAAXXZ");
162 critical_section_trylock
= (void*)GetProcAddress(hcon
, "?try_lock@critical_section@Concurrency@@QAA_NXZ");
164 critical_section_ctor
= (void*)GetProcAddress(hcon
, "??0critical_section@Concurrency@@QAE@XZ");
165 critical_section_dtor
= (void*)GetProcAddress(hcon
, "??1critical_section@Concurrency@@QAE@XZ");
166 critical_section_lock
= (void*)GetProcAddress(hcon
, "?lock@critical_section@Concurrency@@QAEXXZ");
167 critical_section_unlock
= (void*)GetProcAddress(hcon
, "?unlock@critical_section@Concurrency@@QAEXXZ");
168 critical_section_trylock
= (void*)GetProcAddress(hcon
, "?try_lock@critical_section@Concurrency@@QAE_NXZ");
171 #endif /* _MSVCP_VER >= 110 */
173 #if _MSVCP_VER >= 100
174 Context_IsCurrentTaskCollectionCanceling
= (void*)GetProcAddress(hcon
, "?IsCurrentTaskCollectionCanceling@Context@Concurrency@@SA_NXZ");
178 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
180 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
184 case DLL_PROCESS_ATTACH
:
186 _Init_locks__Init_locks_ctor(NULL
);
187 init_exception(hinstDLL
);
188 init_locale(hinstDLL
);
190 #if _MSVCP_VER >= 100
194 case DLL_PROCESS_DETACH
:
195 if (lpvReserved
) break;
198 _Init_locks__Init_locks_dtor(NULL
);
199 #if _MSVCP_VER >= 100
208 /* ?_BADOFF@std@@3JB -> long const std::_BADOFF */
209 /* ?_BADOFF@std@@3_JB -> __int64 const std::_BADOFF */
210 const streamoff std_BADOFF
= -1;
212 /* ?_BADOFF_func@std@@YAABJXZ -> long const & __cdecl std::_BADOFF_func(void) */
213 /* ?_BADOFF_func@std@@YAAEB_JXZ -> __int64 const & __ptr64 __cdecl std::_BADOFF_func(void) */
214 const streamoff
* __cdecl
std_BADOFF_func(void)
219 /* ?_Fpz@std@@3_JA __int64 std::_Fpz */
222 /* ?_Fpz_func@std@@YAAA_JXZ -> __int64 & __cdecl std::_Fpz_func(void) */
223 /* ?_Fpz_func@std@@YAAEA_JXZ -> __int64 & __ptr64 __cdecl std::_Fpz_func(void) */
224 __int64
* __cdecl
std_Fpz_func(void)