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
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msvcp
);
33 #define DEFINE_VTBL_WRAPPER(off) \
34 __ASM_GLOBAL_FUNC(vtbl_wrapper_ ## off, \
38 "movl 0(%ecx), %eax\n\t" \
39 "jmp *" #off "(%eax)\n\t")
41 DEFINE_VTBL_WRAPPER(0);
42 DEFINE_VTBL_WRAPPER(4);
43 DEFINE_VTBL_WRAPPER(8);
44 DEFINE_VTBL_WRAPPER(12);
45 DEFINE_VTBL_WRAPPER(16);
46 DEFINE_VTBL_WRAPPER(20);
47 DEFINE_VTBL_WRAPPER(24);
48 DEFINE_VTBL_WRAPPER(28);
49 DEFINE_VTBL_WRAPPER(32);
50 DEFINE_VTBL_WRAPPER(36);
51 DEFINE_VTBL_WRAPPER(40);
52 DEFINE_VTBL_WRAPPER(44);
53 DEFINE_VTBL_WRAPPER(48);
54 DEFINE_VTBL_WRAPPER(52);
55 DEFINE_VTBL_WRAPPER(56);
59 void* (__cdecl
*MSVCRT_operator_new
)(MSVCP_size_t
);
60 void (__cdecl
*MSVCRT_operator_delete
)(void*);
61 void* (__cdecl
*MSVCRT_set_new_handler
)(void*);
64 int* (__cdecl
*UCRTBASE___processing_throw
)(void);
68 critical_section
* (__thiscall
*critical_section_ctor
)(critical_section
*);
69 void (__thiscall
*critical_section_dtor
)(critical_section
*);
70 void (__thiscall
*critical_section_lock
)(critical_section
*);
71 void (__thiscall
*critical_section_unlock
)(critical_section
*);
72 MSVCP_bool (__thiscall
*critical_section_trylock
)(critical_section
*);
76 MSVCP_bool (__cdecl
*Context_IsCurrentTaskCollectionCanceling
)(void);
79 #define VERSION_STRING(ver) #ver
81 #define MSVCRT_NAME(ver) "ucrtbase.dll"
82 #define CONCRT_NAME(ver) "concrt" VERSION_STRING(ver) ".dll"
84 #define MSVCRT_NAME(ver) "msvcr" VERSION_STRING(ver) ".dll"
88 static void* __cdecl
operator_new(MSVCP_size_t size
)
95 retval
= malloc(size
);
98 TRACE("(%ld) returning %p\n", size
, retval
);
101 freed
= _callnewh(size
);
104 TRACE("(%ld) out of memory\n", size
);
105 throw_exception(EXCEPTION_BAD_ALLOC
, "bad allocation");
109 static void __cdecl
operator_delete(void *mem
)
111 TRACE("(%p)\n", mem
);
115 void __cdecl
_invalid_parameter(const wchar_t *expr
, const wchar_t *func
, const wchar_t *file
, unsigned int line
, uintptr_t arg
)
117 _invalid_parameter_noinfo();
120 int WINAPIV
_scprintf(const char* fmt
, ...)
124 __ms_va_start(valist
, fmt
);
125 ret
= __stdio_common_vsprintf(UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
, NULL
, 0, fmt
, NULL
, valist
);
130 int WINAPIV
sprintf(char *buf
, const char *fmt
, ...)
134 __ms_va_start(valist
, fmt
);
135 ret
= __stdio_common_vsprintf(UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR
, buf
, -1, fmt
, NULL
, valist
);
141 static void init_cxx_funcs(void)
143 HMODULE hmod
= GetModuleHandleA( MSVCRT_NAME(_MSVCP_VER
) );
144 #if _MSVCP_VER >= 100
148 if (!hmod
) FIXME( "%s not loaded\n", MSVCRT_NAME(_MSVCP_VER
) );
150 #if _MSVCP_VER >= 140
151 MSVCRT_operator_new
= operator_new
;
152 MSVCRT_operator_delete
= operator_delete
;
153 MSVCRT_set_new_handler
= (void*)GetProcAddress(hmod
, "_set_new_handler");
154 UCRTBASE___processing_throw
= (void*)GetProcAddress(hmod
, "__processing_throw");
156 hcon
= LoadLibraryA( CONCRT_NAME(_MSVCP_VER
) );
157 if (!hcon
) FIXME( "%s not loaded\n", CONCRT_NAME(_MSVCP_VER
) );
159 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
161 MSVCRT_operator_new
= (void*)GetProcAddress(hmod
, "??2@YAPEAX_K@Z");
162 MSVCRT_operator_delete
= (void*)GetProcAddress(hmod
, "??3@YAXPEAX@Z");
163 MSVCRT_set_new_handler
= (void*)GetProcAddress(hmod
, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z");
167 MSVCRT_operator_new
= (void*)GetProcAddress(hmod
, "??2@YAPAXI@Z");
168 MSVCRT_operator_delete
= (void*)GetProcAddress(hmod
, "??3@YAXPAX@Z");
169 MSVCRT_set_new_handler
= (void*)GetProcAddress(hmod
, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z");
173 #if _MSVCP_VER >= 110
174 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
176 critical_section_ctor
= (void*)GetProcAddress(hcon
, "??0critical_section@Concurrency@@QEAA@XZ");
177 critical_section_dtor
= (void*)GetProcAddress(hcon
, "??1critical_section@Concurrency@@QEAA@XZ");
178 critical_section_lock
= (void*)GetProcAddress(hcon
, "?lock@critical_section@Concurrency@@QEAAXXZ");
179 critical_section_unlock
= (void*)GetProcAddress(hcon
, "?unlock@critical_section@Concurrency@@QEAAXXZ");
180 critical_section_trylock
= (void*)GetProcAddress(hcon
, "?try_lock@critical_section@Concurrency@@QEAA_NXZ");
185 critical_section_ctor
= (void*)GetProcAddress(hcon
, "??0critical_section@Concurrency@@QAA@XZ");
186 critical_section_dtor
= (void*)GetProcAddress(hcon
, "??1critical_section@Concurrency@@QAA@XZ");
187 critical_section_lock
= (void*)GetProcAddress(hcon
, "?lock@critical_section@Concurrency@@QAAXXZ");
188 critical_section_unlock
= (void*)GetProcAddress(hcon
, "?unlock@critical_section@Concurrency@@QAAXXZ");
189 critical_section_trylock
= (void*)GetProcAddress(hcon
, "?try_lock@critical_section@Concurrency@@QAA_NXZ");
191 critical_section_ctor
= (void*)GetProcAddress(hcon
, "??0critical_section@Concurrency@@QAE@XZ");
192 critical_section_dtor
= (void*)GetProcAddress(hcon
, "??1critical_section@Concurrency@@QAE@XZ");
193 critical_section_lock
= (void*)GetProcAddress(hcon
, "?lock@critical_section@Concurrency@@QAEXXZ");
194 critical_section_unlock
= (void*)GetProcAddress(hcon
, "?unlock@critical_section@Concurrency@@QAEXXZ");
195 critical_section_trylock
= (void*)GetProcAddress(hcon
, "?try_lock@critical_section@Concurrency@@QAE_NXZ");
198 #endif /* _MSVCP_VER >= 110 */
200 #if _MSVCP_VER >= 100
201 Context_IsCurrentTaskCollectionCanceling
= (void*)GetProcAddress(hcon
, "?IsCurrentTaskCollectionCanceling@Context@Concurrency@@SA_NXZ");
205 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
207 TRACE("(0x%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
211 case DLL_PROCESS_ATTACH
:
214 init_exception(hinstDLL
);
215 init_locale(hinstDLL
);
217 #if _MSVCP_VER >= 100
221 case DLL_PROCESS_DETACH
:
222 if (lpvReserved
) break;
226 #if _MSVCP_VER >= 100
235 /* ?_BADOFF@std@@3JB -> long const std::_BADOFF */
236 /* ?_BADOFF@std@@3_JB -> __int64 const std::_BADOFF */
237 const streamoff std_BADOFF
= -1;
239 /* ?_BADOFF_func@std@@YAABJXZ -> long const & __cdecl std::_BADOFF_func(void) */
240 /* ?_BADOFF_func@std@@YAAEB_JXZ -> __int64 const & __ptr64 __cdecl std::_BADOFF_func(void) */
241 const streamoff
* __cdecl
std_BADOFF_func(void)
246 /* ?_Fpz@std@@3_JA __int64 std::_Fpz */
249 /* ?_Fpz_func@std@@YAAA_JXZ -> __int64 & __cdecl std::_Fpz_func(void) */
250 /* ?_Fpz_func@std@@YAAEA_JXZ -> __int64 & __ptr64 __cdecl std::_Fpz_func(void) */
251 __int64
* __cdecl
std_Fpz_func(void)
256 #if defined(__MINGW32__) && _MSVCP_VER >= 80 && _MSVCP_VER <= 90
257 /* Hack: prevent Mingw from importing mingw_helpers.o which conflicts with encode/decode_pointer */
258 int mingw_app_type
= 0;