bcrypt: Make format_gnutls_signature() static.
[wine.git] / dlls / msvcp90 / msvcp_main.c
blob6166591d0cb69ace7b02dbb3840c84668f31ae3d
1 /*
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
19 #include <stdarg.h>
21 #include "msvcp90.h"
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
29 #if defined(__i386__) && !defined(__MINGW32__)
31 #define DEFINE_VTBL_WRAPPER(off) \
32 __ASM_GLOBAL_FUNC(vtbl_wrapper_ ## off, \
33 "popl %eax\n\t" \
34 "popl %ecx\n\t" \
35 "pushl %eax\n\t" \
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);
55 #endif
57 void* (__cdecl *MSVCRT_operator_new)(MSVCP_size_t);
58 void (__cdecl *MSVCRT_operator_delete)(void*);
59 void* (__cdecl *MSVCRT_set_new_handler)(void*);
61 #if _MSVCP_VER >= 140
62 int* (__cdecl *UCRTBASE___processing_throw)(void);
63 #endif
65 #if _MSVCP_VER >= 110
66 critical_section* (__thiscall *critical_section_ctor)(critical_section*);
67 void (__thiscall *critical_section_dtor)(critical_section*);
68 void (__thiscall *critical_section_lock)(critical_section*);
69 void (__thiscall *critical_section_unlock)(critical_section*);
70 MSVCP_bool (__thiscall *critical_section_trylock)(critical_section*);
71 #endif
73 #if _MSVCP_VER >= 100
74 MSVCP_bool (__cdecl *Context_IsCurrentTaskCollectionCanceling)(void);
75 #endif
77 #define VERSION_STRING(ver) #ver
78 #if _MSVCP_VER >= 140
79 #define MSVCRT_NAME(ver) "ucrtbase.dll"
80 #define CONCRT_NAME(ver) "concrt" VERSION_STRING(ver) ".dll"
81 #else
82 #define MSVCRT_NAME(ver) "msvcr" VERSION_STRING(ver) ".dll"
83 #endif
85 #if _MSVCP_VER >= 140
86 static void* __cdecl operator_new(MSVCP_size_t size)
88 void *retval;
89 int freed;
93 retval = malloc(size);
94 if (retval)
96 TRACE("(%ld) returning %p\n", size, retval);
97 return retval;
99 freed = _callnewh(size);
100 } while (freed);
102 TRACE("(%ld) out of memory\n", size);
103 throw_exception(EXCEPTION_BAD_ALLOC, "bad allocation");
104 return NULL;
107 static void __cdecl operator_delete(void *mem)
109 TRACE("(%p)\n", mem);
110 free(mem);
113 void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file, unsigned int line, uintptr_t arg)
115 _invalid_parameter_noinfo();
118 int WINAPIV _scprintf(const char* fmt, ...)
120 int ret;
121 __ms_va_list valist;
122 __ms_va_start(valist, fmt);
123 ret = _vsnprintf(NULL, 0, fmt, valist);
124 __ms_va_end(valist);
125 return ret;
128 int WINAPIV sprintf(char *buf, const char *fmt, ...)
130 int ret;
131 __ms_va_list valist;
132 __ms_va_start(valist, fmt);
133 ret = _vsnprintf(buf, -1, fmt, valist);
134 __ms_va_end(valist);
135 return ret;
137 #endif
139 static void init_cxx_funcs(void)
141 HMODULE hmod = GetModuleHandleA( MSVCRT_NAME(_MSVCP_VER) );
142 #if _MSVCP_VER >= 100
143 HMODULE hcon = hmod;
144 #endif
146 if (!hmod) FIXME( "%s not loaded\n", MSVCRT_NAME(_MSVCP_VER) );
148 #if _MSVCP_VER >= 140
149 MSVCRT_operator_new = operator_new;
150 MSVCRT_operator_delete = operator_delete;
151 MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "_set_new_handler");
152 UCRTBASE___processing_throw = (void*)GetProcAddress(hmod, "__processing_throw");
154 hcon = LoadLibraryA( CONCRT_NAME(_MSVCP_VER) );
155 if (!hcon) FIXME( "%s not loaded\n", CONCRT_NAME(_MSVCP_VER) );
156 #else
157 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
159 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
160 MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
161 MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z");
163 else
165 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
166 MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z");
167 MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z");
169 #endif
171 #if _MSVCP_VER >= 110
172 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
174 critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QEAA@XZ");
175 critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QEAA@XZ");
176 critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QEAAXXZ");
177 critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QEAAXXZ");
178 critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QEAA_NXZ");
180 else
182 #ifdef __arm__
183 critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QAA@XZ");
184 critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QAA@XZ");
185 critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QAAXXZ");
186 critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QAAXXZ");
187 critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QAA_NXZ");
188 #else
189 critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QAE@XZ");
190 critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QAE@XZ");
191 critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QAEXXZ");
192 critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QAEXXZ");
193 critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QAE_NXZ");
194 #endif
196 #endif /* _MSVCP_VER >= 110 */
198 #if _MSVCP_VER >= 100
199 Context_IsCurrentTaskCollectionCanceling = (void*)GetProcAddress(hcon, "?IsCurrentTaskCollectionCanceling@Context@Concurrency@@SA_NXZ");
200 #endif
203 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
205 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
207 switch (fdwReason)
209 case DLL_PROCESS_ATTACH:
210 init_cxx_funcs();
211 _Init_locks__Init_locks_ctor(NULL);
212 init_exception(hinstDLL);
213 init_locale(hinstDLL);
214 init_io(hinstDLL);
215 #if _MSVCP_VER >= 100
216 init_misc(hinstDLL);
217 #endif
218 break;
219 case DLL_PROCESS_DETACH:
220 if (lpvReserved) break;
221 free_io();
222 free_locale();
223 _Init_locks__Init_locks_dtor(NULL);
224 #if _MSVCP_VER >= 100
225 free_misc();
226 #endif
227 break;
230 return TRUE;
233 /* ?_BADOFF@std@@3JB -> long const std::_BADOFF */
234 /* ?_BADOFF@std@@3_JB -> __int64 const std::_BADOFF */
235 const streamoff std_BADOFF = -1;
237 /* ?_BADOFF_func@std@@YAABJXZ -> long const & __cdecl std::_BADOFF_func(void) */
238 /* ?_BADOFF_func@std@@YAAEB_JXZ -> __int64 const & __ptr64 __cdecl std::_BADOFF_func(void) */
239 const streamoff * __cdecl std_BADOFF_func(void)
241 return &std_BADOFF;
244 /* ?_Fpz@std@@3_JA __int64 std::_Fpz */
245 __int64 std_Fpz = 0;
247 /* ?_Fpz_func@std@@YAAA_JXZ -> __int64 & __cdecl std::_Fpz_func(void) */
248 /* ?_Fpz_func@std@@YAAEA_JXZ -> __int64 & __ptr64 __cdecl std::_Fpz_func(void) */
249 __int64 * __cdecl std_Fpz_func(void)
251 return &std_Fpz;
254 #if defined(__MINGW32__) && _MSVCP_VER >= 80 && _MSVCP_VER <= 90
255 /* Hack: prevent Mingw from importing mingw_helpers.o which conflicts with encode/decode_pointer */
256 int mingw_app_type = 0;
257 #endif