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
29 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcp
);
32 struct __Container_proxy
;
35 struct __Container_proxy
*proxy
;
38 typedef struct __Iterator_base12
{
39 struct __Container_proxy
*proxy
;
40 struct __Iterator_base12
*next
;
43 typedef struct __Container_proxy
{
44 const _Container_base12
*cont
;
45 _Iterator_base12
*head
;
48 /* ??0_Mutex@std@@QAE@XZ */
49 /* ??0_Mutex@std@@QEAA@XZ */
50 DEFINE_THISCALL_WRAPPER(mutex_ctor
, 4)
51 mutex
* __thiscall
mutex_ctor(mutex
*this)
53 CRITICAL_SECTION
*cs
= MSVCRT_operator_new(sizeof(*cs
));
55 ERR("Out of memory\n");
56 throw_exception(EXCEPTION_BAD_ALLOC
, NULL
);
59 InitializeCriticalSection(cs
);
60 cs
->DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": _Mutex critical section");
65 /* ??1_Mutex@std@@QAE@XZ */
66 /* ??1_Mutex@std@@QEAA@XZ */
67 DEFINE_THISCALL_WRAPPER(mutex_dtor
, 4)
68 void __thiscall
mutex_dtor(mutex
*this)
70 ((CRITICAL_SECTION
*)this->mutex
)->DebugInfo
->Spare
[0] = 0;
71 DeleteCriticalSection(this->mutex
);
72 MSVCRT_operator_delete(this->mutex
);
75 /* ?_Lock@_Mutex@std@@QAEXXZ */
76 /* ?_Lock@_Mutex@std@@QEAAXXZ */
77 DEFINE_THISCALL_WRAPPER(mutex_lock
, 4)
78 void __thiscall
mutex_lock(mutex
*this)
80 EnterCriticalSection(this->mutex
);
83 /* ?_Unlock@_Mutex@std@@QAEXXZ */
84 /* ?_Unlock@_Mutex@std@@QEAAXXZ */
85 DEFINE_THISCALL_WRAPPER(mutex_unlock
, 4)
86 void __thiscall
mutex_unlock(mutex
*this)
88 LeaveCriticalSection(this->mutex
);
91 /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */
92 /* ?_Mutex_Lock@_Mutex@std@@CAXPEAV12@@Z */
93 void CDECL
mutex_mutex_lock(mutex
*m
)
98 /* ?_Mutex_Unlock@_Mutex@std@@CAXPAV12@@Z */
99 /* ?_Mutex_Unlock@_Mutex@std@@CAXPEAV12@@Z */
100 void CDECL
mutex_mutex_unlock(mutex
*m
)
105 /* ?_Mutex_ctor@_Mutex@std@@CAXPAV12@@Z */
106 /* ?_Mutex_ctor@_Mutex@std@@CAXPEAV12@@Z */
107 void CDECL
mutex_mutex_ctor(mutex
*m
)
112 /* ?_Mutex_dtor@_Mutex@std@@CAXPAV12@@Z */
113 /* ?_Mutex_dtor@_Mutex@std@@CAXPEAV12@@Z */
114 void CDECL
mutex_mutex_dtor(mutex
*m
)
119 static CRITICAL_SECTION lockit_cs
[_MAX_LOCK
];
122 static inline int get_locktype( _Lockit
*lockit
) { return lockit
->locktype
; }
123 static inline void set_locktype( _Lockit
*lockit
, int type
) { lockit
->locktype
= type
; }
125 static inline int get_locktype( _Lockit
*lockit
) { return 0; }
126 static inline void set_locktype( _Lockit
*lockit
, int type
) { }
129 /* ?_Lockit_ctor@_Lockit@std@@SAXH@Z */
130 void __cdecl
_Lockit_init(int locktype
) {
131 InitializeCriticalSection(&lockit_cs
[locktype
]);
132 lockit_cs
[locktype
].DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": _Lockit critical section");
135 /* ?_Lockit_dtor@_Lockit@std@@SAXH@Z */
136 void __cdecl
_Lockit_free(int locktype
)
138 lockit_cs
[locktype
].DebugInfo
->Spare
[0] = 0;
139 DeleteCriticalSection(&lockit_cs
[locktype
]);
142 void init_lockit(void) {
145 for(i
=0; i
<_MAX_LOCK
; i
++)
149 void free_lockit(void) {
152 for(i
=0; i
<_MAX_LOCK
; i
++)
156 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@H@Z */
157 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@H@Z */
158 void __cdecl
_Lockit__Lockit_ctor_locktype(_Lockit
*lockit
, int locktype
)
160 set_locktype( lockit
, locktype
);
161 EnterCriticalSection(&lockit_cs
[locktype
]);
164 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@@Z */
165 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@@Z */
166 void __cdecl
_Lockit__Lockit_ctor(_Lockit
*lockit
)
168 _Lockit__Lockit_ctor_locktype(lockit
, 0);
171 /* ??0_Lockit@std@@QAE@H@Z */
172 /* ??0_Lockit@std@@QEAA@H@Z */
173 DEFINE_THISCALL_WRAPPER(_Lockit_ctor_locktype
, 8)
174 _Lockit
* __thiscall
_Lockit_ctor_locktype(_Lockit
*this, int locktype
)
176 _Lockit__Lockit_ctor_locktype(this, locktype
);
180 /* ??0_Lockit@std@@QAE@XZ */
181 /* ??0_Lockit@std@@QEAA@XZ */
182 DEFINE_THISCALL_WRAPPER(_Lockit_ctor
, 4)
183 _Lockit
* __thiscall
_Lockit_ctor(_Lockit
*this)
185 _Lockit__Lockit_ctor_locktype(this, 0);
189 /* ?_Lockit_dtor@_Lockit@std@@CAXPAV12@@Z */
190 /* ?_Lockit_dtor@_Lockit@std@@CAXPEAV12@@Z */
191 void __cdecl
_Lockit__Lockit_dtor(_Lockit
*lockit
)
193 LeaveCriticalSection(&lockit_cs
[get_locktype( lockit
)]);
196 /* ??1_Lockit@std@@QAE@XZ */
197 /* ??1_Lockit@std@@QEAA@XZ */
198 DEFINE_THISCALL_WRAPPER(_Lockit_dtor
, 4)
199 void __thiscall
_Lockit_dtor(_Lockit
*this)
201 _Lockit__Lockit_dtor(this);
205 unsigned short __cdecl
wctype(const char *property
)
207 static const struct {
211 { "alnum", _DIGIT
|_ALPHA
},
213 { "cntrl", _CONTROL
},
215 { "graph", _DIGIT
|_PUNCT
|_ALPHA
},
217 { "print", _DIGIT
|_PUNCT
|_BLANK
|_ALPHA
},
225 for(i
=0; i
<sizeof(properties
)/sizeof(properties
[0]); i
++)
226 if(!strcmp(property
, properties
[i
].name
))
227 return properties
[i
].mask
;
232 typedef void (__cdecl
*MSVCP_new_handler_func
)(void);
233 static MSVCP_new_handler_func MSVCP_new_handler
;
234 static int __cdecl
new_handler_wrapper(MSVCP_size_t unused
)
240 /* ?set_new_handler@std@@YAP6AXXZP6AXXZ@Z */
241 MSVCP_new_handler_func __cdecl
set_new_handler(MSVCP_new_handler_func new_handler
)
243 MSVCP_new_handler_func old_handler
= MSVCP_new_handler
;
245 TRACE("%p\n", new_handler
);
247 MSVCP_new_handler
= new_handler
;
248 MSVCRT_set_new_handler(new_handler
? new_handler_wrapper
: NULL
);
252 /* ?set_new_handler@std@@YAP6AXXZH@Z */
253 MSVCP_new_handler_func __cdecl
set_new_handler_reset(int unused
)
255 return set_new_handler(NULL
);
258 /* _Container_base0 is used by apps compiled without iterator checking
259 * (i.e. with _ITERATOR_DEBUG_LEVEL=0 ).
260 * It provides empty versions of methods used by visual c++'s stl's
262 * msvcr100 has to provide them in case apps are compiled with /Od
263 * or the optimizer fails to inline those (empty) calls.
266 /* ?_Orphan_all@_Container_base0@std@@QAEXXZ */
267 /* ?_Orphan_all@_Container_base0@std@@QEAAXXZ */
268 DEFINE_THISCALL_WRAPPER(Container_base0_Orphan_all
, 4)
269 void __thiscall
Container_base0_Orphan_all(void *this)
273 /* ?_Swap_all@_Container_base0@std@@QAEXAAU12@@Z */
274 /* ?_Swap_all@_Container_base0@std@@QEAAXAEAU12@@Z */
275 DEFINE_THISCALL_WRAPPER(Container_base0_Swap_all
, 8)
276 void __thiscall
Container_base0_Swap_all(void *this, void *that
)
280 /* ??4_Container_base0@std@@QAEAAU01@ABU01@@Z */
281 /* ??4_Container_base0@std@@QEAAAEAU01@AEBU01@@Z */
282 DEFINE_THISCALL_WRAPPER(Container_base0_op_assign
, 8)
283 void* __thiscall
Container_base0_op_assign(void *this, const void *that
)
288 /* ??0_Container_base12@std@@QAE@ABU01@@Z */
289 /* ??0_Container_base12@std@@QEAA@AEBU01@@Z */
290 DEFINE_THISCALL_WRAPPER(_Container_base12_copy_ctor
, 8)
291 _Container_base12
* __thiscall
_Container_base12_copy_ctor(
292 _Container_base12
*this, _Container_base12
*that
)
298 /* ??0_Container_base12@std@@QAE@XZ */
299 /* ??0_Container_base12@std@@QEAA@XZ */
300 DEFINE_THISCALL_WRAPPER(_Container_base12_ctor
, 4)
301 _Container_base12
* __thiscall
_Container_base12_ctor(_Container_base12
*this)
307 /* ??1_Container_base12@std@@QAE@XZ */
308 /* ??1_Container_base12@std@@QEAA@XZ */
309 DEFINE_THISCALL_WRAPPER(_Container_base12_dtor
, 4)
310 void __thiscall
_Container_base12_dtor(_Container_base12
*this)
314 /* ??4_Container_base12@std@@QAEAAU01@ABU01@@Z */
315 /* ??4_Container_base12@std@@QEAAAEAU01@AEBU01@@ */
316 DEFINE_THISCALL_WRAPPER(_Container_base12_op_assign
, 8)
317 _Container_base12
* __thiscall
_Container_base12_op_assign(
318 _Container_base12
*this, const _Container_base12
*that
)
323 /* ?_Getpfirst@_Container_base12@std@@QBEPAPAU_Iterator_base12@2@XZ */
324 /* ?_Getpfirst@_Container_base12@std@@QEBAPEAPEAU_Iterator_base12@2@XZ */
325 DEFINE_THISCALL_WRAPPER(_Container_base12__Getpfirst
, 4)
326 _Iterator_base12
** __thiscall
_Container_base12__Getpfirst(_Container_base12
*this)
328 return this->proxy
? &this->proxy
->head
: NULL
;
331 /* ?_Orphan_all@_Container_base12@std@@QAEXXZ */
332 /* ?_Orphan_all@_Container_base12@std@@QEAAXXZ */
333 DEFINE_THISCALL_WRAPPER(_Container_base12__Orphan_all
, 4)
334 void __thiscall
_Container_base12__Orphan_all(_Container_base12
*this)
338 /* ?_Swap_all@_Container_base12@std@@QAEXAAU12@@Z */
339 /* ?_Swap_all@_Container_base12@std@@QEAAXAEAU12@@Z */
340 DEFINE_THISCALL_WRAPPER(_Container_base12__Swap_all
, 8)
341 void __thiscall
_Container_base12__Swap_all(
342 _Container_base12
*this, _Container_base12
*that
)
344 _Container_proxy
*tmp
;
347 this->proxy
= that
->proxy
;
351 this->proxy
->cont
= this;
353 that
->proxy
->cont
= that
;
356 #if _MSVCP_VER >= 110
358 #define SECSPERDAY 86400
359 /* 1601 to 1970 is 369 years plus 89 leap days */
360 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
361 #define TICKSPERSEC 10000000
362 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
363 #define NANOSEC_PER_MILLISEC 1000000
364 #define MILLISEC_PER_SEC 1000
366 typedef int MSVCRT_long
;
374 /* _Xtime_get_ticks */
375 LONGLONG __cdecl
_Xtime_get_ticks(void)
381 GetSystemTimeAsFileTime(&ft
);
382 return ((LONGLONG
)ft
.dwHighDateTime
<<32) + ft
.dwLowDateTime
- TICKS_1601_TO_1970
;
386 int __cdecl
xtime_get(xtime
* t
, int unknown
)
395 ticks
= _Xtime_get_ticks();
396 t
->sec
= ticks
/ TICKSPERSEC
;
397 t
->nsec
= ticks
% TICKSPERSEC
* 100;
401 /* _Xtime_diff_to_millis2 */
402 MSVCRT_long __cdecl
_Xtime_diff_to_millis2(const xtime
*t1
, const xtime
*t2
)
405 MSVCRT_long diff_nsec
, ret
;
407 TRACE("(%p, %p)\n", t1
, t2
);
409 diff_sec
= t1
->sec
- t2
->sec
;
410 diff_nsec
= t1
->nsec
- t2
->nsec
;
411 ret
= diff_sec
* MILLISEC_PER_SEC
+
412 (diff_nsec
+ NANOSEC_PER_MILLISEC
- 1) / NANOSEC_PER_MILLISEC
;
413 return ret
> 0 ? ret
: 0;
416 /* _Xtime_diff_to_millis */
417 MSVCRT_long __cdecl
_Xtime_diff_to_millis(const xtime
*t
)
424 return _Xtime_diff_to_millis2(t
, &now
);
429 unsigned int __cdecl
_Random_device(void)
435 /* TODO: throw correct exception in case of failure */
437 throw_exception(EXCEPTION
, "random number generator failed\n");
442 #if _MSVCP_VER >= 110
443 #if defined(__i386__) && !defined(__arm__)
445 extern void *call_thiscall_func
;
446 __ASM_GLOBAL_FUNC(call_thiscall_func
,
453 #define call_func1(func,this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)(func,this)
457 #define call_func1(func,this) func(this)
459 #endif /* __i386__ */
461 #define MTX_MULTI_LOCK 0x100
471 int __cdecl
_Mtx_init(_Mtx_t
*mtx
, int flags
)
473 if(flags
& ~MTX_MULTI_LOCK
)
474 FIXME("unknown flags ignorred: %x\n", flags
);
476 *mtx
= MSVCRT_operator_new(sizeof(**mtx
));
477 (*mtx
)->flags
= flags
;
478 call_func1(critical_section_ctor
, &(*mtx
)->cs
);
479 (*mtx
)->thread_id
= -1;
484 void __cdecl
_Mtx_destroy(_Mtx_t
*mtx
)
486 call_func1(critical_section_dtor
, &(*mtx
)->cs
);
487 MSVCRT_operator_delete(*mtx
);
490 int __cdecl
_Mtx_lock(_Mtx_t
*mtx
)
492 if((*mtx
)->thread_id
!= GetCurrentThreadId()) {
493 call_func1(critical_section_lock
, &(*mtx
)->cs
);
494 (*mtx
)->thread_id
= GetCurrentThreadId();
495 }else if(!((*mtx
)->flags
& MTX_MULTI_LOCK
)) {
503 int __cdecl
_Mtx_unlock(_Mtx_t
*mtx
)
508 (*mtx
)->thread_id
= -1;
509 call_func1(critical_section_unlock
, &(*mtx
)->cs
);
513 int __cdecl
_Mtx_trylock(_Mtx_t
*mtx
)
515 if((*mtx
)->thread_id
!= GetCurrentThreadId()) {
516 if(!call_func1(critical_section_trylock
, &(*mtx
)->cs
))
518 (*mtx
)->thread_id
= GetCurrentThreadId();
519 }else if(!((*mtx
)->flags
& MTX_MULTI_LOCK
)) {
527 critical_section
* __cdecl
_Mtx_getconcrtcs(_Mtx_t
*mtx
)
532 static inline LONG
interlocked_dec_if_nonzero( LONG
*dest
)
535 for (val
= *dest
;; val
= tmp
)
537 if (!val
|| (tmp
= InterlockedCompareExchange( dest
, val
- 1, val
)) == val
)
543 #define CND_TIMEDOUT 2
547 CONDITION_VARIABLE cv
;
550 static HANDLE keyed_event
;
552 int __cdecl
_Cnd_init(_Cnd_t
*cnd
)
554 *cnd
= MSVCRT_operator_new(sizeof(**cnd
));
555 InitializeConditionVariable(&(*cnd
)->cv
);
560 NtCreateKeyedEvent(&event
, GENERIC_READ
|GENERIC_WRITE
, NULL
, 0);
561 if(InterlockedCompareExchangePointer(&keyed_event
, event
, NULL
) != NULL
)
568 int __cdecl
_Cnd_wait(_Cnd_t
*cnd
, _Mtx_t
*mtx
)
570 CONDITION_VARIABLE
*cv
= &(*cnd
)->cv
;
572 InterlockedExchangeAdd( (LONG
*)&cv
->Ptr
, 1 );
575 NtWaitForKeyedEvent(keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
581 int __cdecl
_Cnd_timedwait(_Cnd_t
*cnd
, _Mtx_t
*mtx
, const xtime
*xt
)
583 CONDITION_VARIABLE
*cv
= &(*cnd
)->cv
;
584 LARGE_INTEGER timeout
;
587 InterlockedExchangeAdd( (LONG
*)&cv
->Ptr
, 1 );
590 timeout
.QuadPart
= (ULONGLONG
)_Xtime_diff_to_millis(xt
) * -10000;
591 status
= NtWaitForKeyedEvent(keyed_event
, &cv
->Ptr
, FALSE
, &timeout
);
594 if (!interlocked_dec_if_nonzero( (LONG
*)&cv
->Ptr
))
595 status
= NtWaitForKeyedEvent( keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
599 return status
? CND_TIMEDOUT
: 0;
602 int __cdecl
_Cnd_broadcast(_Cnd_t
*cnd
)
604 CONDITION_VARIABLE
*cv
= &(*cnd
)->cv
;
605 LONG val
= InterlockedExchange( (LONG
*)&cv
->Ptr
, 0 );
607 NtReleaseKeyedEvent( keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
611 int __cdecl
_Cnd_signal(_Cnd_t
*cnd
)
613 CONDITION_VARIABLE
*cv
= &(*cnd
)->cv
;
614 if (interlocked_dec_if_nonzero( (LONG
*)&cv
->Ptr
))
615 NtReleaseKeyedEvent( keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
619 void __cdecl
_Cnd_destroy(_Cnd_t
*cnd
)
623 MSVCRT_operator_delete(*cnd
);
628 #if _MSVCP_VER == 100
630 const vtable_ptr
*vtable
;
637 static custom_category iostream_category
;
639 DEFINE_RTTI_DATA0(error_category
, 0, ".?AVerror_category@std@@")
640 DEFINE_RTTI_DATA1(iostream_category
, 0, &error_category_rtti_base_descriptor
, ".?AV_Iostream_error_category@std@@")
642 extern const vtable_ptr MSVCP_iostream_category_vtable
;
644 static void iostream_category_ctor(custom_category
*this)
646 this->base
.vtable
= &MSVCP_iostream_category_vtable
;
647 this->type
= "iostream";
650 DEFINE_THISCALL_WRAPPER(custom_category_vector_dtor
, 8)
651 custom_category
* __thiscall
custom_category_vector_dtor(custom_category
*this, unsigned int flags
)
653 TRACE("(%p %x)\n", this, flags
);
655 /* we have an array, with the number of elements stored before the first object */
656 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
658 for(i
=*ptr
-1; i
>=0; i
--)
659 MSVCRT_operator_delete(ptr
);
662 MSVCRT_operator_delete(this);
668 DEFINE_THISCALL_WRAPPER(custom_category_name
, 4)
669 const char* __thiscall
custom_category_name(const custom_category
*this)
674 DEFINE_THISCALL_WRAPPER(custom_category_message
, 12)
675 basic_string_char
* __thiscall
custom_category_message(const custom_category
*this,
676 basic_string_char
*ret
, int err
)
678 if(err
== 1) return MSVCP_basic_string_char_ctor_cstr(ret
, "iostream error");
679 return MSVCP_basic_string_char_ctor_cstr(ret
, strerror(err
));
682 DEFINE_THISCALL_WRAPPER(custom_category_default_error_condition
, 12)
683 /*error_condition*/void* __thiscall
custom_category_default_error_condition(
684 custom_category
*this, /*error_condition*/void *ret
, int code
)
686 FIXME("(%p %p %x) stub\n", this, ret
, code
);
690 DEFINE_THISCALL_WRAPPER(custom_category_equivalent
, 12)
691 MSVCP_bool __thiscall
custom_category_equivalent(const custom_category
*this,
692 int code
, const /*error_condition*/void *condition
)
694 FIXME("(%p %x %p) stub\n", this, code
, condition
);
698 DEFINE_THISCALL_WRAPPER(custom_category_equivalent_code
, 12)
699 MSVCP_bool __thiscall
custom_category_equivalent_code(custom_category
*this,
700 const /*error_code*/void *code
, int condition
)
702 FIXME("(%p %p %x) stub\n", this, code
, condition
);
706 /* ?iostream_category@std@@YAABVerror_category@1@XZ */
707 /* ?iostream_category@std@@YAAEBVerror_category@1@XZ */
708 const error_category
* __cdecl
std_iostream_category(void)
711 return &iostream_category
.base
;
715 void __asm_dummy_vtables(void) {
717 __ASM_VTABLE(iostream_category
,
718 VTABLE_ADD_FUNC(custom_category_vector_dtor
)
719 VTABLE_ADD_FUNC(custom_category_name
)
720 VTABLE_ADD_FUNC(custom_category_message
)
721 VTABLE_ADD_FUNC(custom_category_default_error_condition
)
722 VTABLE_ADD_FUNC(custom_category_equivalent
)
723 VTABLE_ADD_FUNC(custom_category_equivalent_code
));
729 #if _MSVCP_VER >= 110
730 static CRITICAL_SECTION call_once_cs
;
731 static CRITICAL_SECTION_DEBUG call_once_cs_debug
=
734 { &call_once_cs_debug
.ProcessLocksList
, &call_once_cs_debug
.ProcessLocksList
},
735 0, 0, { (DWORD_PTR
)(__FILE__
": call_once_cs") }
737 static CRITICAL_SECTION call_once_cs
= { &call_once_cs_debug
, -1, 0, 0, 0, 0 };
739 void __cdecl
_Call_onceEx(int *once
, void (__cdecl
*func
)(void*), void *argv
)
741 TRACE("%p %p %p\n", once
, func
, argv
);
743 EnterCriticalSection(&call_once_cs
);
745 /* FIXME: handle exceptions */
749 LeaveCriticalSection(&call_once_cs
);
752 static void __cdecl
call_once_func_wrapper(void *func
)
754 ((void (__cdecl
*)(void))func
)();
757 void __cdecl
_Call_once(int *once
, void (__cdecl
*func
)(void))
759 TRACE("%p %p\n", once
, func
);
760 _Call_onceEx(once
, call_once_func_wrapper
, func
);
763 void __cdecl
_Do_call(void *this)
765 CALL_VTBL_FUNC(this, 0, void, (void*), (this));
769 void init_misc(void *base
)
772 #if _MSVCP_VER == 100
773 init_error_category_rtti(base
);
774 init_iostream_category_rtti(base
);
778 #if _MSVCP_VER == 100
779 iostream_category_ctor(&iostream_category
);
785 #if _MSVCP_VER >= 110
787 NtClose(keyed_event
);
791 #if _MSVCP_VER >= 110
798 typedef int (__cdecl
*_Thrd_start_t
)(void*);
800 #define _THRD_ERROR 4
802 int __cdecl
_Thrd_equal(_Thrd_t a
, _Thrd_t b
)
804 TRACE("(%p %u %p %u)\n", a
.hnd
, a
.id
, b
.hnd
, b
.id
);
808 int __cdecl
_Thrd_lt(_Thrd_t a
, _Thrd_t b
)
810 TRACE("(%p %u %p %u)\n", a
.hnd
, a
.id
, b
.hnd
, b
.id
);
814 void __cdecl
_Thrd_sleep(const xtime
*t
)
817 Sleep(_Xtime_diff_to_millis(t
));
820 void __cdecl
_Thrd_yield(void)
826 static _Thrd_t
thread_current(void)
830 if(DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
831 GetCurrentProcess(), &ret
.hnd
, 0, FALSE
, DUPLICATE_SAME_ACCESS
)) {
832 CloseHandle(ret
.hnd
);
836 ret
.id
= GetCurrentThreadId();
838 TRACE("(%p %u)\n", ret
.hnd
, ret
.id
);
843 _Thrd_t __cdecl
_Thrd_current(void)
845 return thread_current();
848 ULONGLONG __cdecl
_Thrd_current(void)
855 C_ASSERT(sizeof(_Thrd_t
) <= sizeof(ULONGLONG
));
857 ret
.thr
= thread_current();
862 int __cdecl
_Thrd_join(_Thrd_t thr
, int *code
)
864 TRACE("(%p %u %p)\n", thr
.hnd
, thr
.id
, code
);
865 if (WaitForSingleObject(thr
.hnd
, INFINITE
))
869 GetExitCodeThread(thr
.hnd
, (DWORD
*)code
);
871 CloseHandle(thr
.hnd
);
875 int __cdecl
_Thrd_create(_Thrd_t
*thr
, _Thrd_start_t proc
, void *arg
)
877 TRACE("(%p %p %p)\n", thr
, proc
, arg
);
878 thr
->hnd
= CreateThread(NULL
, 0, (LPTHREAD_START_ROUTINE
)proc
, arg
, 0, &thr
->id
);