kernelbase/tests: Use win_skip() for missing APIs.
[wine.git] / dlls / msvcp90 / msvcp_main.c
blob8717384c2c67dd0bbee16362530324ccbf61a4ed
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 #ifdef __ASM_USE_THISCALL_WRAPPER
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_set_new_handler)(void*);
59 #if _MSVCP_VER >= 110 && _MSVCP_VER <= 120
60 #ifdef __ASM_USE_THISCALL_WRAPPER
62 extern void *call_thiscall_func;
63 __ASM_GLOBAL_FUNC(call_thiscall_func,
64 "popl %eax\n\t"
65 "popl %edx\n\t"
66 "popl %ecx\n\t"
67 "pushl %eax\n\t"
68 "jmp *%edx\n\t")
70 #define call_func1(func,this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)(func,this)
71 #define call_func2(func,this,a) ((void* (WINAPI*)(void*,void*,void*))&call_thiscall_func)(func,this,a)
72 #define call_func3(func,this,a,b) ((void* (WINAPI*)(void*,void*,void*,unsigned int))&call_thiscall_func)(func,this,a,b)
74 #else /* __i386__ */
76 #define call_func1(func,this) func(this)
77 #define call_func2(func,this,a) func(this,a)
78 #define call_func3(func,this,a,b) func(this,a,b)
80 #endif /* __i386__ */
82 static critical_section* (__thiscall *critical_section_ctor)(critical_section*);
83 static void (__thiscall *critical_section_dtor)(critical_section*);
84 static void (__thiscall *critical_section_lock)(critical_section*);
85 static void (__thiscall *critical_section_unlock)(critical_section*);
86 static bool (__thiscall *critical_section_trylock)(critical_section*);
88 static _Condition_variable* (__thiscall *_Condition_variable_ctor)(_Condition_variable*);
89 static void (__thiscall *_Condition_variable_dtor)(_Condition_variable*);
90 static void (__thiscall *_Condition_variable_wait)(_Condition_variable*, critical_section*);
91 static bool (__thiscall *_Condition_variable_wait_for)(_Condition_variable*,
92 critical_section*, unsigned int);
93 static void (__thiscall *_Condition_variable_notify_one)(_Condition_variable*);
94 static void (__thiscall *_Condition_variable_notify_all)(_Condition_variable*);
96 void cs_init(cs *cs)
98 call_func1(critical_section_ctor, &cs->conc);
101 void cs_destroy(cs *cs)
103 call_func1(critical_section_dtor, &cs->conc);
106 void cs_lock(cs *cs)
108 call_func1(critical_section_lock, &cs->conc);
111 void cs_unlock(cs *cs)
113 call_func1(critical_section_unlock, &cs->conc);
116 bool cs_trylock(cs *cs)
118 return call_func1(critical_section_trylock, &cs->conc);
121 void cv_init(cv *cv)
123 call_func1(_Condition_variable_ctor, &cv->conc);
126 void cv_destroy(cv *cv)
128 call_func1(_Condition_variable_dtor, &cv->conc);
131 void cv_wait(cv *cv, cs *cs)
133 call_func2(_Condition_variable_wait, &cv->conc, &cs->conc);
136 bool cv_wait_for(cv *cv, cs *cs, unsigned int timeout)
138 return call_func3(_Condition_variable_wait_for, &cv->conc, &cs->conc, timeout);
141 void cv_notify_one(cv *cv)
143 call_func1(_Condition_variable_notify_one, &cv->conc);
146 void cv_notify_all(cv *cv)
148 call_func1(_Condition_variable_notify_all, &cv->conc);
150 #elif _MSVCP_VER >= 140
151 void cs_init(cs *cs)
153 InitializeSRWLock(&cs->win);
156 void cs_destroy(cs *cs)
160 void cs_lock(cs *cs)
162 AcquireSRWLockExclusive(&cs->win);
165 void cs_unlock(cs *cs)
167 ReleaseSRWLockExclusive(&cs->win);
170 bool cs_trylock(cs *cs)
172 return TryAcquireSRWLockExclusive(&cs->win);
175 void cv_init(cv *cv)
177 InitializeConditionVariable(&cv->win);
180 void cv_destroy(cv *cv)
184 void cv_wait(cv *cv, cs *cs)
186 SleepConditionVariableSRW(&cv->win, &cs->win, INFINITE, 0);
189 bool cv_wait_for(cv *cv, cs *cs, unsigned int timeout)
191 return SleepConditionVariableSRW(&cv->win, &cs->win, timeout, 0);
194 void cv_notify_one(cv *cv)
196 WakeConditionVariable(&cv->win);
199 void cv_notify_all(cv *cv)
201 WakeAllConditionVariable(&cv->win);
203 #endif
205 #if _MSVCP_VER >= 100
206 bool (__cdecl *Context_IsCurrentTaskCollectionCanceling)(void);
207 #endif
209 #define VERSION_STRING(ver) #ver
210 #if _MSVCP_VER >= 140
211 #define MSVCRT_NAME(ver) "ucrtbase.dll"
212 #define CONCRT_NAME(ver) "concrt" VERSION_STRING(ver) ".dll"
213 #else
214 #define MSVCRT_NAME(ver) "msvcr" VERSION_STRING(ver) ".dll"
215 #endif
217 #if _MSVCP_VER >= 140
218 void* __cdecl operator_new(size_t size)
220 void *retval;
221 int freed;
225 retval = malloc(size);
226 if (retval)
228 TRACE("(%Iu) returning %p\n", size, retval);
229 return retval;
231 freed = _callnewh(size);
232 } while (freed);
234 TRACE("(%Iu) out of memory\n", size);
235 _Xmem();
238 void __cdecl operator_delete(void *mem)
240 TRACE("(%p)\n", mem);
241 free(mem);
244 void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file, unsigned int line, uintptr_t arg)
246 _invalid_parameter_noinfo();
248 #else
249 static void* (__cdecl *MSVCRT_operator_new)(size_t);
250 static void (__cdecl *MSVCRT_operator_delete)(void*);
252 void* __cdecl operator_new(size_t size)
254 void *ret = MSVCRT_operator_new(size);
255 #if _MSVCP_VER < 80
256 if (!ret) _Xmem();
257 #endif
258 return ret;
261 void __cdecl operator_delete(void *mem)
263 MSVCRT_operator_delete(mem);
265 #endif
267 static void init_cxx_funcs(void)
269 HMODULE hmod = GetModuleHandleA( MSVCRT_NAME(_MSVCP_VER) );
270 #if _MSVCP_VER >= 100
271 HMODULE hcon = hmod;
272 #endif
274 if (!hmod) FIXME( "%s not loaded\n", MSVCRT_NAME(_MSVCP_VER) );
276 #if _MSVCP_VER >= 140
277 MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "_set_new_handler");
279 hcon = LoadLibraryA( CONCRT_NAME(_MSVCP_VER) );
280 if (!hcon) FIXME( "%s not loaded\n", CONCRT_NAME(_MSVCP_VER) );
281 #else
282 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
284 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
285 MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
286 MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z");
288 else
290 MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
291 MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z");
292 MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z");
294 #endif
296 #if _MSVCP_VER >= 110 && _MSVCP_VER <= 120
297 if (sizeof(void *) > sizeof(int)) /* 64-bit has different names */
299 critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QEAA@XZ");
300 critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QEAA@XZ");
301 critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QEAAXXZ");
302 critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QEAAXXZ");
303 critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QEAA_NXZ");
304 _Condition_variable_ctor = (void*)GetProcAddress(hcon, "??0_Condition_variable@details@Concurrency@@QEAA@XZ");
305 _Condition_variable_dtor = (void*)GetProcAddress(hcon, "??1_Condition_variable@details@Concurrency@@QEAA@XZ");
306 _Condition_variable_wait = (void*)GetProcAddress(hcon,
307 "?wait@_Condition_variable@details@Concurrency@@QEAAXAEAVcritical_section@3@@Z");
308 _Condition_variable_wait_for = (void*)GetProcAddress(hcon,
309 "?wait_for@_Condition_variable@details@Concurrency@@QEAA_NAEAVcritical_section@3@I@Z");
310 _Condition_variable_notify_one = (void*)GetProcAddress(hcon,
311 "?notify_one@_Condition_variable@details@Concurrency@@QEAAXXZ");
312 _Condition_variable_notify_all = (void*)GetProcAddress(hcon,
313 "?notify_all@_Condition_variable@details@Concurrency@@QEAAXXZ");
315 else
317 #ifdef __arm__
318 critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QAA@XZ");
319 critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QAA@XZ");
320 critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QAAXXZ");
321 critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QAAXXZ");
322 critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QAA_NXZ");
323 _Condition_variable_ctor = (void*)GetProcAddress(hcon, "??0_Condition_variable@details@Concurrency@@QAA@XZ");
324 _Condition_variable_dtor = (void*)GetProcAddress(hcon, "??1_Condition_variable@details@Concurrency@@QAA@XZ");
325 _Condition_variable_wait = (void*)GetProcAddress(hcon,
326 "?wait@_Condition_variable@details@Concurrency@@QAAXAAVcritical_section@3@@Z");
327 _Condition_variable_wait_for = (void*)GetProcAddress(hcon,
328 "?wait_for@_Condition_variable@details@Concurrency@@QAA_NAAVcritical_section@3@I@Z");
329 _Condition_variable_notify_one = (void*)GetProcAddress(hcon,
330 "?notify_one@_Condition_variable@details@Concurrency@@QAAXXZ");
331 _Condition_variable_notify_all = (void*)GetProcAddress(hcon,
332 "?notify_all@_Condition_variable@details@Concurrency@@QAAXXZ");
333 #else
334 critical_section_ctor = (void*)GetProcAddress(hcon, "??0critical_section@Concurrency@@QAE@XZ");
335 critical_section_dtor = (void*)GetProcAddress(hcon, "??1critical_section@Concurrency@@QAE@XZ");
336 critical_section_lock = (void*)GetProcAddress(hcon, "?lock@critical_section@Concurrency@@QAEXXZ");
337 critical_section_unlock = (void*)GetProcAddress(hcon, "?unlock@critical_section@Concurrency@@QAEXXZ");
338 critical_section_trylock = (void*)GetProcAddress(hcon, "?try_lock@critical_section@Concurrency@@QAE_NXZ");
339 _Condition_variable_ctor = (void*)GetProcAddress(hcon, "??0_Condition_variable@details@Concurrency@@QAE@XZ");
340 _Condition_variable_dtor = (void*)GetProcAddress(hcon, "??1_Condition_variable@details@Concurrency@@QAE@XZ");
341 _Condition_variable_wait = (void*)GetProcAddress(hcon,
342 "?wait@_Condition_variable@details@Concurrency@@QAEXAAVcritical_section@3@@Z");
343 _Condition_variable_wait_for = (void*)GetProcAddress(hcon,
344 "?wait_for@_Condition_variable@details@Concurrency@@QAE_NAAVcritical_section@3@I@Z");
345 _Condition_variable_notify_one = (void*)GetProcAddress(hcon,
346 "?notify_one@_Condition_variable@details@Concurrency@@QAEXXZ");
347 _Condition_variable_notify_all = (void*)GetProcAddress(hcon,
348 "?notify_all@_Condition_variable@details@Concurrency@@QAEXXZ");
349 #endif
351 #endif /* _MSVCP_VER >= 110 */
353 #if _MSVCP_VER >= 100
354 Context_IsCurrentTaskCollectionCanceling = (void*)GetProcAddress(hcon, "?IsCurrentTaskCollectionCanceling@Context@Concurrency@@SA_NXZ");
355 #endif
358 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
360 TRACE("(0x%p, %ld, %p)\n", hinstDLL, fdwReason, lpvReserved);
362 switch (fdwReason)
364 case DLL_PROCESS_ATTACH:
365 init_cxx_funcs();
366 _Init_locks__Init_locks_ctor(NULL);
367 init_exception(hinstDLL);
368 init_locale(hinstDLL);
369 init_io(hinstDLL);
370 #if _MSVCP_VER >= 100
371 init_misc(hinstDLL);
372 init_concurrency_details(hinstDLL);
373 #endif
374 break;
375 case DLL_PROCESS_DETACH:
376 if (lpvReserved) break;
377 free_io();
378 free_locale();
379 _Init_locks__Init_locks_dtor(NULL);
380 #if _MSVCP_VER >= 100
381 free_misc();
382 #endif
383 break;
386 return TRUE;
389 /* ?_BADOFF@std@@3JB -> long const std::_BADOFF */
390 /* ?_BADOFF@std@@3_JB -> __int64 const std::_BADOFF */
391 const streamoff std_BADOFF = -1;
393 /* ?_BADOFF_func@std@@YAABJXZ -> long const & __cdecl std::_BADOFF_func(void) */
394 /* ?_BADOFF_func@std@@YAAEB_JXZ -> __int64 const & __ptr64 __cdecl std::_BADOFF_func(void) */
395 const streamoff * __cdecl std_BADOFF_func(void)
397 return &std_BADOFF;
400 /* ?_Fpz@std@@3_JA __int64 std::_Fpz */
401 __int64 std_Fpz = 0;
403 /* ?_Fpz_func@std@@YAAA_JXZ -> __int64 & __cdecl std::_Fpz_func(void) */
404 /* ?_Fpz_func@std@@YAAEA_JXZ -> __int64 & __ptr64 __cdecl std::_Fpz_func(void) */
405 __int64 * __cdecl std_Fpz_func(void)
407 return &std_Fpz;