2010-07-20 23:22:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Piotr Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2010-07-22 09:40:19 +02:00
|
|
|
#include "msvcp90.h"
|
|
|
|
|
2010-07-20 23:22:16 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2012-08-14 10:51:34 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
|
2010-07-20 23:22:16 +02:00
|
|
|
|
2011-12-20 15:56:42 +01:00
|
|
|
#ifdef __i386__
|
|
|
|
|
|
|
|
#define DEFINE_VTBL_WRAPPER(off) \
|
|
|
|
__ASM_GLOBAL_FUNC(vtbl_wrapper_ ## off, \
|
|
|
|
"popl %eax\n\t" \
|
|
|
|
"popl %ecx\n\t" \
|
|
|
|
"pushl %eax\n\t" \
|
|
|
|
"movl 0(%ecx), %eax\n\t" \
|
|
|
|
"jmp *" #off "(%eax)\n\t")
|
|
|
|
|
|
|
|
DEFINE_VTBL_WRAPPER(0);
|
2011-12-20 15:57:08 +01:00
|
|
|
DEFINE_VTBL_WRAPPER(4);
|
2011-12-20 15:57:19 +01:00
|
|
|
DEFINE_VTBL_WRAPPER(8);
|
|
|
|
DEFINE_VTBL_WRAPPER(12);
|
|
|
|
DEFINE_VTBL_WRAPPER(16);
|
|
|
|
DEFINE_VTBL_WRAPPER(20);
|
|
|
|
DEFINE_VTBL_WRAPPER(24);
|
|
|
|
DEFINE_VTBL_WRAPPER(28);
|
|
|
|
DEFINE_VTBL_WRAPPER(32);
|
|
|
|
DEFINE_VTBL_WRAPPER(36);
|
|
|
|
DEFINE_VTBL_WRAPPER(40);
|
2011-12-22 18:24:21 +01:00
|
|
|
DEFINE_VTBL_WRAPPER(44);
|
|
|
|
DEFINE_VTBL_WRAPPER(48);
|
|
|
|
DEFINE_VTBL_WRAPPER(52);
|
|
|
|
DEFINE_VTBL_WRAPPER(56);
|
2011-12-20 15:56:42 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-05-27 14:56:18 +02:00
|
|
|
void* (__cdecl *MSVCRT_operator_new)(MSVCP_size_t);
|
2010-07-25 12:23:22 +02:00
|
|
|
void (__cdecl *MSVCRT_operator_delete)(void*);
|
2011-09-13 10:30:29 +02:00
|
|
|
void* (__cdecl *MSVCRT_set_new_handler)(void*);
|
|
|
|
|
2018-03-20 15:37:00 +01:00
|
|
|
#if _MSVCP_VER >= 140
|
|
|
|
int* (__cdecl *UCRTBASE___processing_throw)(void);
|
|
|
|
#endif
|
|
|
|
|
2014-06-26 13:46:09 +02:00
|
|
|
#if _MSVCP_VER >= 110
|
|
|
|
critical_section* (__thiscall *critical_section_ctor)(critical_section*);
|
|
|
|
void (__thiscall *critical_section_dtor)(critical_section*);
|
|
|
|
void (__thiscall *critical_section_lock)(critical_section*);
|
|
|
|
void (__thiscall *critical_section_unlock)(critical_section*);
|
|
|
|
MSVCP_bool (__thiscall *critical_section_trylock)(critical_section*);
|
|
|
|
#endif
|
|
|
|
|
2017-03-24 12:45:10 +01:00
|
|
|
#if _MSVCP_VER >= 100
|
|
|
|
MSVCP_bool (__cdecl *Context_IsCurrentTaskCollectionCanceling)(void);
|
|
|
|
#endif
|
|
|
|
|
2013-12-26 23:43:03 +01:00
|
|
|
#define VERSION_STRING(ver) #ver
|
2015-11-03 22:54:34 +01:00
|
|
|
#if _MSVCP_VER >= 140
|
|
|
|
#define MSVCRT_NAME(ver) "ucrtbase.dll"
|
2016-05-27 02:49:43 +02:00
|
|
|
#define CONCRT_NAME(ver) "concrt" VERSION_STRING(ver) ".dll"
|
2015-11-03 22:54:34 +01:00
|
|
|
#else
|
2013-12-26 23:43:03 +01:00
|
|
|
#define MSVCRT_NAME(ver) "msvcr" VERSION_STRING(ver) ".dll"
|
2015-11-03 22:54:34 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if _MSVCP_VER >= 140
|
|
|
|
static void* __cdecl operator_new(MSVCP_size_t size)
|
|
|
|
{
|
|
|
|
void *retval;
|
|
|
|
int freed;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
retval = malloc(size);
|
|
|
|
if (retval)
|
|
|
|
{
|
|
|
|
TRACE("(%ld) returning %p\n", size, retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
freed = _callnewh(size);
|
|
|
|
} while (freed);
|
|
|
|
|
|
|
|
TRACE("(%ld) out of memory\n", size);
|
|
|
|
throw_exception(EXCEPTION_BAD_ALLOC, "bad allocation");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __cdecl operator_delete(void *mem)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", mem);
|
|
|
|
free(mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file, unsigned int line, uintptr_t arg)
|
|
|
|
{
|
|
|
|
_invalid_parameter_noinfo();
|
|
|
|
}
|
|
|
|
|
2017-11-02 10:19:18 +01:00
|
|
|
int WINAPIV _scprintf(const char* fmt, ...)
|
2015-11-03 22:54:34 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, fmt);
|
|
|
|
ret = __stdio_common_vsprintf(UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, NULL, 0, fmt, NULL, valist);
|
|
|
|
__ms_va_end(valist);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-04-09 01:14:28 +02:00
|
|
|
|
2017-11-02 10:19:18 +01:00
|
|
|
int WINAPIV sprintf(char *buf, const char *fmt, ...)
|
2016-04-09 01:14:28 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, fmt);
|
|
|
|
ret = __stdio_common_vsprintf(UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, buf, -1, fmt, NULL, valist);
|
|
|
|
__ms_va_end(valist);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-04-02 16:47:01 +02:00
|
|
|
|
|
|
|
int __cdecl _vsnprintf( char *buf, size_t size, const char *fmt, __ms_va_list args )
|
|
|
|
{
|
|
|
|
return __stdio_common_vsprintf( UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR,
|
|
|
|
buf, size, fmt, NULL, args );
|
|
|
|
}
|
2015-11-03 22:54:34 +01:00
|
|
|
#endif
|
2013-12-26 23:43:03 +01:00
|
|
|
|
2010-08-26 13:03:54 +02:00
|
|
|
static void init_cxx_funcs(void)
|
2010-07-22 09:40:19 +02:00
|
|
|
{
|
2013-12-26 23:43:03 +01:00
|
|
|
HMODULE hmod = GetModuleHandleA( MSVCRT_NAME(_MSVCP_VER) );
|
2017-03-24 12:45:10 +01:00
|
|
|
#if _MSVCP_VER >= 100
|
2016-05-27 02:49:43 +02:00
|
|
|
HMODULE hcon = hmod;
|
|
|
|
#endif
|
2013-12-26 23:43:03 +01:00
|
|
|
|
|
|
|
if (!hmod) FIXME( "%s not loaded\n", MSVCRT_NAME(_MSVCP_VER) );
|
2010-07-22 09:40:19 +02:00
|
|
|
|
2015-11-03 22:54:34 +01:00
|
|
|
#if _MSVCP_VER >= 140
|
|
|
|
MSVCRT_operator_new = operator_new;
|
|
|
|
MSVCRT_operator_delete = operator_delete;
|
|
|
|
MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "_set_new_handler");
|
2018-03-20 15:37:00 +01:00
|
|
|
UCRTBASE___processing_throw = (void*)GetProcAddress(hmod, "__processing_throw");
|
2016-05-27 02:49:43 +02:00
|
|
|
|
|
|
|
hcon = LoadLibraryA( CONCRT_NAME(_MSVCP_VER) );
|
|
|
|
if (!hcon) FIXME( "%s not loaded\n", CONCRT_NAME(_MSVCP_VER) );
|
2015-11-03 22:54:34 +01:00
|
|
|
#else
|
2010-07-22 09:40:19 +02:00
|
|
|
if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
|
|
|
|
{
|
|
|
|
MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
|
|
|
|
MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
|
2011-09-13 10:30:29 +02:00
|
|
|
MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z");
|
2010-07-22 09:40:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
|
|
|
|
MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z");
|
2011-09-13 10:30:29 +02:00
|
|
|
MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z");
|
2016-05-27 02:49:43 +02:00
|
|
|
}
|
|
|
|
#endif
|
2014-06-26 13:46:09 +02:00
|
|
|
|
|
|
|
#if _MSVCP_VER >= 110
|
2016-05-27 02:49:43 +02:00
|
|
|
if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
|
|
|
|
{
|
|
|
|
critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QEAA@XZ");
|
|
|
|
critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QEAA@XZ");
|
|
|
|
critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QEAAXXZ");
|
|
|
|
critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QEAAXXZ");
|
|
|
|
critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QEAA_NXZ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-26 13:46:09 +02:00
|
|
|
#ifdef __arm__
|
2016-05-27 02:49:43 +02:00
|
|
|
critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QAA@XZ");
|
|
|
|
critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QAA@XZ");
|
|
|
|
critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QAAXXZ");
|
|
|
|
critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QAAXXZ");
|
|
|
|
critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QAA_NXZ");
|
2014-06-26 13:46:09 +02:00
|
|
|
#else
|
2016-05-27 02:49:43 +02:00
|
|
|
critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QAE@XZ");
|
|
|
|
critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QAE@XZ");
|
|
|
|
critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QAEXXZ");
|
|
|
|
critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QAEXXZ");
|
|
|
|
critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QAE_NXZ");
|
2014-06-26 13:46:09 +02:00
|
|
|
#endif
|
2010-07-22 09:40:19 +02:00
|
|
|
}
|
2016-05-27 02:49:43 +02:00
|
|
|
#endif /* _MSVCP_VER >= 110 */
|
2017-03-24 12:45:10 +01:00
|
|
|
|
|
|
|
#if _MSVCP_VER >= 100
|
|
|
|
Context_IsCurrentTaskCollectionCanceling = (void*)GetProcAddress(hcon, "?IsCurrentTaskCollectionCanceling@Context@Concurrency@@SA_NXZ");
|
|
|
|
#endif
|
2010-07-22 09:40:19 +02:00
|
|
|
}
|
|
|
|
|
2010-07-20 23:22:16 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
|
|
|
|
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2010-07-22 09:40:19 +02:00
|
|
|
init_cxx_funcs();
|
2011-06-22 14:03:54 +02:00
|
|
|
init_lockit();
|
2012-09-07 11:01:35 +02:00
|
|
|
init_exception(hinstDLL);
|
|
|
|
init_locale(hinstDLL);
|
|
|
|
init_io(hinstDLL);
|
2017-04-01 14:36:29 +02:00
|
|
|
#if _MSVCP_VER >= 100
|
2014-10-17 12:07:23 +02:00
|
|
|
init_misc(hinstDLL);
|
2017-04-01 14:36:29 +02:00
|
|
|
#endif
|
2010-07-20 23:22:16 +02:00
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
2013-05-20 12:29:07 +02:00
|
|
|
if (lpvReserved) break;
|
2012-06-15 11:07:49 +02:00
|
|
|
free_io();
|
2012-06-12 18:12:12 +02:00
|
|
|
free_locale();
|
2011-06-22 14:03:54 +02:00
|
|
|
free_lockit();
|
2017-04-01 14:36:29 +02:00
|
|
|
#if _MSVCP_VER >= 100
|
2015-11-04 02:10:16 +01:00
|
|
|
free_misc();
|
2017-04-01 14:36:29 +02:00
|
|
|
#endif
|
2010-07-20 23:22:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-05-04 13:48:21 +02:00
|
|
|
|
|
|
|
/* ?_BADOFF@std@@3JB -> long const std::_BADOFF */
|
|
|
|
/* ?_BADOFF@std@@3_JB -> __int64 const std::_BADOFF */
|
2012-08-15 10:26:48 +02:00
|
|
|
const streamoff std_BADOFF = -1;
|
2011-05-04 13:48:21 +02:00
|
|
|
|
|
|
|
/* ?_BADOFF_func@std@@YAABJXZ -> long const & __cdecl std::_BADOFF_func(void) */
|
|
|
|
/* ?_BADOFF_func@std@@YAAEB_JXZ -> __int64 const & __ptr64 __cdecl std::_BADOFF_func(void) */
|
2012-08-15 10:26:48 +02:00
|
|
|
const streamoff * __cdecl std_BADOFF_func(void)
|
2011-05-04 13:48:21 +02:00
|
|
|
{
|
|
|
|
return &std_BADOFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ?_Fpz@std@@3_JA __int64 std::_Fpz */
|
|
|
|
__int64 std_Fpz = 0;
|
|
|
|
|
|
|
|
/* ?_Fpz_func@std@@YAAA_JXZ -> __int64 & __cdecl std::_Fpz_func(void) */
|
|
|
|
/* ?_Fpz_func@std@@YAAEA_JXZ -> __int64 & __ptr64 __cdecl std::_Fpz_func(void) */
|
|
|
|
__int64 * __cdecl std_Fpz_func(void)
|
|
|
|
{
|
|
|
|
return &std_Fpz;
|
|
|
|
}
|
2013-12-21 12:43:03 +01:00
|
|
|
|
|
|
|
#if defined(__MINGW32__) && _MSVCP_VER >= 80 && _MSVCP_VER <= 90
|
|
|
|
/* Hack: prevent Mingw from importing mingw_helpers.o which conflicts with encode/decode_pointer */
|
|
|
|
int mingw_app_type = 0;
|
|
|
|
#endif
|