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
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcp
);
30 /* error strings generated with glibc strerror */
31 static const char str_EPERM
[] = "operation not permitted";
32 static const char str_ENOENT
[] = "no such file or directory";
33 static const char str_ESRCH
[] = "no such process";
34 static const char str_EINTR
[] = "interrupted system call";
35 static const char str_EIO
[] = "input/output error";
36 static const char str_ENXIO
[] = "no such device or address";
37 static const char str_E2BIG
[] = "argument list too long";
38 static const char str_ENOEXEC
[] = "exec format error";
39 static const char str_EBADF
[] = "bad file descriptor";
40 static const char str_ECHILD
[] = "no child processes";
41 static const char str_EAGAIN
[] = "resource temporarily unavailable";
42 static const char str_ENOMEM
[] = "cannot allocate memory";
43 static const char str_EACCES
[] = "permission denied";
44 static const char str_EFAULT
[] = "bad address";
45 static const char str_EBUSY
[] = "device or resource busy";
46 static const char str_EEXIST
[] = "file exists";
47 static const char str_EXDEV
[] = "invalid cross-device link";
48 static const char str_ENODEV
[] = "no such device";
49 static const char str_ENOTDIR
[] = "not a directory";
50 static const char str_EISDIR
[] = "is a directory";
51 static const char str_EINVAL
[] = "invalid argument";
52 static const char str_ENFILE
[] = "too many open files in system";
53 static const char str_EMFILE
[] = "too many open files";
54 static const char str_ENOTTY
[] = "inappropriate ioctl for device";
55 static const char str_EFBIG
[] = "file too large";
56 static const char str_ENOSPC
[] = "no space left on device";
57 static const char str_ESPIPE
[] = "illegal seek";
58 static const char str_EROFS
[] = "read-only file system";
59 static const char str_EMLINK
[] = "too many links";
60 static const char str_EPIPE
[] = "broken pipe";
61 static const char str_EDOM
[] = "numerical argument out of domain";
62 static const char str_ERANGE
[] = "numerical result out of range";
63 static const char str_EDEADLK
[] = "resource deadlock avoided";
64 static const char str_ENAMETOOLONG
[] = "file name too long";
65 static const char str_ENOLCK
[] = "no locks available";
66 static const char str_ENOSYS
[] = "function not implemented";
67 static const char str_ENOTEMPTY
[] = "directory not empty";
68 static const char str_EILSEQ
[] = "invalid or incomplete multibyte or wide character";
69 static const char str_EADDRINUSE
[] = "address already in use";
70 static const char str_EADDRNOTAVAIL
[] = "cannot assign requested address";
71 static const char str_EAFNOSUPPORT
[] = "address family not supported by protocol";
72 static const char str_EALREADY
[] = "operation already in progress";
73 static const char str_EBADMSG
[] = "not a data message";
74 static const char str_ECANCELED
[] = "operation Canceled";
75 static const char str_ECONNABORTED
[] = "software caused connection abort";
76 static const char str_ECONNREFUSED
[] = "connection refused";
77 static const char str_ECONNRESET
[] = "connection reset by peer";
78 static const char str_EDESTADDRREQ
[] = "destination address required";
79 static const char str_EHOSTUNREACH
[] = "no route to host";
80 static const char str_EIDRM
[] = "identifier removed";
81 static const char str_EINPROGRESS
[] = "operation now in progress";
82 static const char str_EISCONN
[] = "transport endpoint is already connected";
83 static const char str_ELOOP
[] = "too many symbolic links encountered";
84 static const char str_EMSGSIZE
[] = "message too long";
85 static const char str_ENETDOWN
[] = "network is down";
86 static const char str_ENETRESET
[] = "network dropped connection because of reset";
87 static const char str_ENETUNREACH
[] = "network is unreachable";
88 static const char str_ENOBUFS
[] = "no buffer space available";
89 static const char str_ENODATA
[] = "no data available";
90 static const char str_ENOLINK
[] = "link has been severed";
91 static const char str_ENOMSG
[] = "no message of desired type";
92 static const char str_ENOPROTOOPT
[] = "protocol not available";
93 static const char str_ENOSR
[] = "out of streams resources";
94 static const char str_ENOSTR
[] = "device not a stream";
95 static const char str_ENOTCONN
[] = "transport endpoint is not connected";
96 static const char str_ENOTRECOVERABLE
[] = "state not recoverable";
97 static const char str_ENOTSOCK
[] = "socket operation on non-socket";
98 static const char str_ENOTSUP
[] = "not supported";
99 static const char str_EOPNOTSUPP
[] = "operation not supported on transport endpoint";
100 static const char str_EOVERFLOW
[] = "value too large for defined data type";
101 static const char str_EOWNERDEAD
[] = "owner died";
102 static const char str_EPROTO
[] = "protocol error";
103 static const char str_EPROTONOSUPPORT
[] = "protocol not supported";
104 static const char str_EPROTOTYPE
[] = "protocol wrong type for socket";
105 static const char str_ETIME
[] = "timer expired";
106 static const char str_ETIMEDOUT
[] = "connection timed out";
107 static const char str_ETXTBSY
[] = "text file busy";
108 static const char str_EWOULDBLOCK
[] = "operation would block";
110 static const struct {
116 {ENOENT
, str_ENOENT
},
122 {ENOEXEC
, str_ENOEXEC
},
124 {ECHILD
, str_ECHILD
},
125 {EAGAIN
, str_EAGAIN
},
126 {ENOMEM
, str_ENOMEM
},
127 {EACCES
, str_EACCES
},
128 {EFAULT
, str_EFAULT
},
130 {EEXIST
, str_EEXIST
},
132 {ENODEV
, str_ENODEV
},
133 {ENOTDIR
, str_ENOTDIR
},
134 {EISDIR
, str_EISDIR
},
135 {EINVAL
, str_EINVAL
},
136 {ENFILE
, str_ENFILE
},
137 {EMFILE
, str_EMFILE
},
138 {ENOTTY
, str_ENOTTY
},
140 {ENOSPC
, str_ENOSPC
},
141 {ESPIPE
, str_ESPIPE
},
143 {EMLINK
, str_EMLINK
},
146 {ERANGE
, str_ERANGE
},
147 {EDEADLK
, str_EDEADLK
},
148 {ENAMETOOLONG
, str_ENAMETOOLONG
},
149 {ENOLCK
, str_ENOLCK
},
150 {ENOSYS
, str_ENOSYS
},
151 {ENOTEMPTY
, str_ENOTEMPTY
},
152 {EILSEQ
, str_EILSEQ
},
153 {EADDRINUSE
, str_EADDRINUSE
},
154 {EADDRNOTAVAIL
, str_EADDRNOTAVAIL
},
155 {EAFNOSUPPORT
, str_EAFNOSUPPORT
},
156 {EALREADY
, str_EALREADY
},
157 {EBADMSG
, str_EBADMSG
},
158 {ECANCELED
, str_ECANCELED
},
159 {ECONNABORTED
, str_ECONNABORTED
},
160 {ECONNREFUSED
, str_ECONNREFUSED
},
161 {ECONNRESET
, str_ECONNRESET
},
162 {EDESTADDRREQ
, str_EDESTADDRREQ
},
163 {EHOSTUNREACH
, str_EHOSTUNREACH
},
165 {EINPROGRESS
, str_EINPROGRESS
},
166 {EISCONN
, str_EISCONN
},
168 {EMSGSIZE
, str_EMSGSIZE
},
169 {ENETDOWN
, str_ENETDOWN
},
170 {ENETRESET
, str_ENETRESET
},
171 {ENETUNREACH
, str_ENETUNREACH
},
172 {ENOBUFS
, str_ENOBUFS
},
173 {ENODATA
, str_ENODATA
},
174 {ENOLINK
, str_ENOLINK
},
175 {ENOMSG
, str_ENOMSG
},
176 {ENOPROTOOPT
, str_ENOPROTOOPT
},
178 {ENOSTR
, str_ENOSTR
},
179 {ENOTCONN
, str_ENOTCONN
},
180 {ENOTRECOVERABLE
, str_ENOTRECOVERABLE
},
181 {ENOTSOCK
, str_ENOTSOCK
},
182 {ENOTSUP
, str_ENOTSUP
},
183 {EOPNOTSUPP
, str_EOPNOTSUPP
},
184 {EOVERFLOW
, str_EOVERFLOW
},
185 {EOWNERDEAD
, str_EOWNERDEAD
},
186 {EPROTO
, str_EPROTO
},
187 {EPROTONOSUPPORT
, str_EPROTONOSUPPORT
},
188 {EPROTOTYPE
, str_EPROTOTYPE
},
190 {ETIMEDOUT
, str_ETIMEDOUT
},
191 {ETXTBSY
, str_ETXTBSY
},
192 {EWOULDBLOCK
, str_EWOULDBLOCK
},
195 static const struct {
200 {ERROR_INVALID_FUNCTION
, ENOSYS
}, {ERROR_FILE_NOT_FOUND
, ENOENT
},
201 {ERROR_PATH_NOT_FOUND
, ENOENT
}, {ERROR_TOO_MANY_OPEN_FILES
, EMFILE
},
202 {ERROR_ACCESS_DENIED
, EACCES
}, {ERROR_INVALID_HANDLE
, EINVAL
},
203 {ERROR_NOT_ENOUGH_MEMORY
, ENOMEM
}, {ERROR_INVALID_ACCESS
, EACCES
},
204 {ERROR_OUTOFMEMORY
, ENOMEM
}, {ERROR_INVALID_DRIVE
, ENODEV
},
205 {ERROR_CURRENT_DIRECTORY
, EACCES
}, {ERROR_NOT_SAME_DEVICE
, EXDEV
},
206 {ERROR_WRITE_PROTECT
, EACCES
}, {ERROR_BAD_UNIT
, ENODEV
},
207 {ERROR_NOT_READY
, EAGAIN
}, {ERROR_SEEK
, EIO
}, {ERROR_WRITE_FAULT
, EIO
},
208 {ERROR_READ_FAULT
, EIO
}, {ERROR_SHARING_VIOLATION
, EACCES
},
209 {ERROR_LOCK_VIOLATION
, ENOLCK
}, {ERROR_HANDLE_DISK_FULL
, ENOSPC
},
210 {ERROR_NOT_SUPPORTED
, ENOTSUP
}, {ERROR_DEV_NOT_EXIST
, ENODEV
},
211 {ERROR_FILE_EXISTS
, EEXIST
}, {ERROR_CANNOT_MAKE
, EACCES
},
212 {ERROR_INVALID_PARAMETER
, EINVAL
}, {ERROR_OPEN_FAILED
, EIO
},
213 {ERROR_BUFFER_OVERFLOW
, ENAMETOOLONG
}, {ERROR_DISK_FULL
, ENOSPC
},
214 {ERROR_INVALID_NAME
, ENOENT
}, {ERROR_NEGATIVE_SEEK
, EINVAL
},
215 {ERROR_BUSY_DRIVE
, EBUSY
}, {ERROR_DIR_NOT_EMPTY
, ENOTEMPTY
},
216 {ERROR_BUSY
, EBUSY
}, {ERROR_ALREADY_EXISTS
, EEXIST
},
217 {ERROR_LOCKED
, ENOLCK
}, {ERROR_DIRECTORY
, EINVAL
},
218 {ERROR_OPERATION_ABORTED
, ECANCELED
}, {ERROR_NOACCESS
, EACCES
},
219 {ERROR_CANTOPEN
, EIO
}, {ERROR_CANTREAD
, EIO
}, {ERROR_CANTWRITE
, EIO
},
220 {ERROR_RETRY
, EAGAIN
}, {ERROR_OPEN_FILES
, EBUSY
},
221 {ERROR_DEVICE_IN_USE
, EBUSY
}, {ERROR_REPARSE_TAG_INVALID
, EINVAL
},
222 {WSAEINTR
, EINTR
}, {WSAEBADF
, EBADF
}, {WSAEACCES
, EACCES
},
223 {WSAEFAULT
, EFAULT
}, {WSAEINVAL
, EINVAL
}, {WSAEMFILE
, EMFILE
},
224 {WSAEWOULDBLOCK
, EWOULDBLOCK
}, {WSAEINPROGRESS
, EINPROGRESS
},
225 {WSAEALREADY
, EALREADY
}, {WSAENOTSOCK
, ENOTSOCK
},
226 {WSAEDESTADDRREQ
, EDESTADDRREQ
}, {WSAEMSGSIZE
, EMSGSIZE
},
227 {WSAEPROTOTYPE
, EPROTOTYPE
}, {WSAENOPROTOOPT
, ENOPROTOOPT
},
228 {WSAEPROTONOSUPPORT
, EPROTONOSUPPORT
}, {WSAEOPNOTSUPP
, EOPNOTSUPP
},
229 {WSAEAFNOSUPPORT
, EAFNOSUPPORT
}, {WSAEADDRINUSE
, EADDRINUSE
},
230 {WSAEADDRNOTAVAIL
, EADDRNOTAVAIL
}, {WSAENETDOWN
, ENETDOWN
},
231 {WSAENETUNREACH
, ENETUNREACH
}, {WSAENETRESET
, ENETRESET
},
232 {WSAECONNABORTED
, ECONNABORTED
}, {WSAECONNRESET
, ECONNRESET
},
233 {WSAENOBUFS
, ENOBUFS
}, {WSAEISCONN
, EISCONN
}, {WSAENOTCONN
, ENOTCONN
},
234 {WSAETIMEDOUT
, ETIMEDOUT
}, {WSAECONNREFUSED
, ECONNREFUSED
},
235 {WSAENAMETOOLONG
, ENAMETOOLONG
}, {WSAEHOSTUNREACH
, EHOSTUNREACH
}
239 struct __Container_proxy
;
242 struct __Container_proxy
*proxy
;
245 typedef struct __Iterator_base12
{
246 struct __Container_proxy
*proxy
;
247 struct __Iterator_base12
*next
;
250 typedef struct __Container_proxy
{
251 const _Container_base12
*cont
;
252 _Iterator_base12
*head
;
255 /* ??0_Mutex@std@@QAE@XZ */
256 /* ??0_Mutex@std@@QEAA@XZ */
257 DEFINE_THISCALL_WRAPPER(mutex_ctor
, 4)
258 mutex
* __thiscall
mutex_ctor(mutex
*this)
260 CRITICAL_SECTION
*cs
= operator_new(sizeof(*cs
));
261 InitializeCriticalSection(cs
);
262 cs
->DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": _Mutex critical section");
267 /* ??1_Mutex@std@@QAE@XZ */
268 /* ??1_Mutex@std@@QEAA@XZ */
269 DEFINE_THISCALL_WRAPPER(mutex_dtor
, 4)
270 void __thiscall
mutex_dtor(mutex
*this)
272 ((CRITICAL_SECTION
*)this->mutex
)->DebugInfo
->Spare
[0] = 0;
273 DeleteCriticalSection(this->mutex
);
274 operator_delete(this->mutex
);
277 /* ?_Lock@_Mutex@std@@QAEXXZ */
278 /* ?_Lock@_Mutex@std@@QEAAXXZ */
279 DEFINE_THISCALL_WRAPPER(mutex_lock
, 4)
280 void __thiscall
mutex_lock(mutex
*this)
282 EnterCriticalSection(this->mutex
);
285 /* ?_Unlock@_Mutex@std@@QAEXXZ */
286 /* ?_Unlock@_Mutex@std@@QEAAXXZ */
287 DEFINE_THISCALL_WRAPPER(mutex_unlock
, 4)
288 void __thiscall
mutex_unlock(mutex
*this)
290 LeaveCriticalSection(this->mutex
);
293 /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */
294 /* ?_Mutex_Lock@_Mutex@std@@CAXPEAV12@@Z */
295 void CDECL
mutex_mutex_lock(mutex
*m
)
300 /* ?_Mutex_Unlock@_Mutex@std@@CAXPAV12@@Z */
301 /* ?_Mutex_Unlock@_Mutex@std@@CAXPEAV12@@Z */
302 void CDECL
mutex_mutex_unlock(mutex
*m
)
307 /* ?_Mutex_ctor@_Mutex@std@@CAXPAV12@@Z */
308 /* ?_Mutex_ctor@_Mutex@std@@CAXPEAV12@@Z */
309 void CDECL
mutex_mutex_ctor(mutex
*m
)
314 /* ?_Mutex_dtor@_Mutex@std@@CAXPAV12@@Z */
315 /* ?_Mutex_dtor@_Mutex@std@@CAXPEAV12@@Z */
316 void CDECL
mutex_mutex_dtor(mutex
*m
)
321 static CRITICAL_SECTION lockit_cs
[_MAX_LOCK
];
323 static LONG init_locks
;
324 static CRITICAL_SECTION init_locks_cs
;
325 static CRITICAL_SECTION_DEBUG init_locks_cs_debug
=
327 0, 0, &init_locks_cs
,
328 { &init_locks_cs_debug
.ProcessLocksList
, &init_locks_cs_debug
.ProcessLocksList
},
329 0, 0, { (DWORD_PTR
)(__FILE__
": init_locks_cs") }
331 static CRITICAL_SECTION init_locks_cs
= { &init_locks_cs_debug
, -1, 0, 0, 0, 0 };
333 /* ?_Init_locks_ctor@_Init_locks@std@@CAXPAV12@@Z */
334 /* ?_Init_locks_ctor@_Init_locks@std@@CAXPEAV12@@Z */
335 void __cdecl
_Init_locks__Init_locks_ctor(_Init_locks
*this)
339 EnterCriticalSection(&init_locks_cs
);
342 for(i
=0; i
<_MAX_LOCK
; i
++)
344 InitializeCriticalSection(&lockit_cs
[i
]);
345 lockit_cs
[i
].DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": _Lockit critical section");
349 LeaveCriticalSection(&init_locks_cs
);
352 /* ??0_Init_locks@std@@QAE@XZ */
353 /* ??0_Init_locks@std@@QEAA@XZ */
354 DEFINE_THISCALL_WRAPPER(_Init_locks_ctor
, 4)
355 _Init_locks
* __thiscall
_Init_locks_ctor(_Init_locks
*this)
357 _Init_locks__Init_locks_ctor(this);
361 /* ?_Init_locks_dtor@_Init_locks@std@@CAXPAV12@@Z */
362 /* ?_Init_locks_dtor@_Init_locks@std@@CAXPEAV12@@Z */
363 void __cdecl
_Init_locks__Init_locks_dtor(_Init_locks
*this)
367 EnterCriticalSection(&init_locks_cs
);
371 for(i
=0; i
<_MAX_LOCK
; i
++)
373 lockit_cs
[i
].DebugInfo
->Spare
[0] = 0;
374 DeleteCriticalSection(&lockit_cs
[i
]);
377 LeaveCriticalSection(&init_locks_cs
);
380 /* ??1_Init_locks@std@@QAE@XZ */
381 /* ??1_Init_locks@std@@QEAA@XZ */
382 DEFINE_THISCALL_WRAPPER(_Init_locks_dtor
, 4)
383 void __thiscall
_Init_locks_dtor(_Init_locks
*this)
385 _Init_locks__Init_locks_dtor(this);
389 static inline int get_locktype( _Lockit
*lockit
) { return lockit
->locktype
; }
390 static inline void set_locktype( _Lockit
*lockit
, int type
) { lockit
->locktype
= type
; }
392 static inline int get_locktype( _Lockit
*lockit
) { return 0; }
393 static inline void set_locktype( _Lockit
*lockit
, int type
) { }
396 /* ?_Lockit_ctor@_Lockit@std@@SAXH@Z */
397 void __cdecl
_Lockit__Lockit_ctor_lock(int locktype
)
399 EnterCriticalSection(&lockit_cs
[locktype
]);
402 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@H@Z */
403 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@H@Z */
404 void __cdecl
_Lockit__Lockit_ctor_locktype(_Lockit
*lockit
, int locktype
)
406 set_locktype( lockit
, locktype
);
407 _Lockit__Lockit_ctor_lock(locktype
);
410 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@@Z */
411 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@@Z */
412 void __cdecl
_Lockit__Lockit_ctor(_Lockit
*lockit
)
414 _Lockit__Lockit_ctor_locktype(lockit
, 0);
417 /* ??0_Lockit@std@@QAE@H@Z */
418 /* ??0_Lockit@std@@QEAA@H@Z */
419 DEFINE_THISCALL_WRAPPER(_Lockit_ctor_locktype
, 8)
420 _Lockit
* __thiscall
_Lockit_ctor_locktype(_Lockit
*this, int locktype
)
422 _Lockit__Lockit_ctor_locktype(this, locktype
);
426 /* ??0_Lockit@std@@QAE@XZ */
427 /* ??0_Lockit@std@@QEAA@XZ */
428 DEFINE_THISCALL_WRAPPER(_Lockit_ctor
, 4)
429 _Lockit
* __thiscall
_Lockit_ctor(_Lockit
*this)
431 _Lockit__Lockit_ctor_locktype(this, 0);
435 /* ?_Lockit_dtor@_Lockit@std@@SAXH@Z */
436 void __cdecl
_Lockit__Lockit_dtor_unlock(int locktype
)
438 LeaveCriticalSection(&lockit_cs
[locktype
]);
441 /* ?_Lockit_dtor@_Lockit@std@@CAXPAV12@@Z */
442 /* ?_Lockit_dtor@_Lockit@std@@CAXPEAV12@@Z */
443 void __cdecl
_Lockit__Lockit_dtor(_Lockit
*lockit
)
445 _Lockit__Lockit_dtor_unlock(get_locktype( lockit
));
448 /* ??1_Lockit@std@@QAE@XZ */
449 /* ??1_Lockit@std@@QEAA@XZ */
450 DEFINE_THISCALL_WRAPPER(_Lockit_dtor
, 4)
451 void __thiscall
_Lockit_dtor(_Lockit
*this)
453 _Lockit__Lockit_dtor(this);
457 unsigned short __cdecl
wctype(const char *property
)
459 static const struct {
463 { "alnum", _DIGIT
|_ALPHA
},
465 { "cntrl", _CONTROL
},
467 { "graph", _DIGIT
|_PUNCT
|_ALPHA
},
469 { "print", _DIGIT
|_PUNCT
|_BLANK
|_ALPHA
},
477 for(i
= 0; i
< ARRAY_SIZE(properties
); i
++)
478 if(!strcmp(property
, properties
[i
].name
))
479 return properties
[i
].mask
;
484 typedef void (__cdecl
*MSVCP_new_handler_func
)(void);
485 static MSVCP_new_handler_func MSVCP_new_handler
;
486 static int __cdecl
new_handler_wrapper(size_t unused
)
492 /* ?set_new_handler@std@@YAP6AXXZP6AXXZ@Z */
493 MSVCP_new_handler_func __cdecl
set_new_handler(MSVCP_new_handler_func new_handler
)
495 MSVCP_new_handler_func old_handler
= MSVCP_new_handler
;
497 TRACE("%p\n", new_handler
);
499 MSVCP_new_handler
= new_handler
;
500 MSVCRT_set_new_handler(new_handler
? new_handler_wrapper
: NULL
);
504 /* ?set_new_handler@std@@YAP6AXXZH@Z */
505 MSVCP_new_handler_func __cdecl
set_new_handler_reset(int unused
)
507 return set_new_handler(NULL
);
510 /* _Container_base0 is used by apps compiled without iterator checking
511 * (i.e. with _ITERATOR_DEBUG_LEVEL=0 ).
512 * It provides empty versions of methods used by visual c++'s stl's
514 * msvcr100 has to provide them in case apps are compiled with /Od
515 * or the optimizer fails to inline those (empty) calls.
518 /* ?_Orphan_all@_Container_base0@std@@QAEXXZ */
519 /* ?_Orphan_all@_Container_base0@std@@QEAAXXZ */
520 DEFINE_THISCALL_WRAPPER(Container_base0_Orphan_all
, 4)
521 void __thiscall
Container_base0_Orphan_all(void *this)
525 /* ?_Swap_all@_Container_base0@std@@QAEXAAU12@@Z */
526 /* ?_Swap_all@_Container_base0@std@@QEAAXAEAU12@@Z */
527 DEFINE_THISCALL_WRAPPER(Container_base0_Swap_all
, 8)
528 void __thiscall
Container_base0_Swap_all(void *this, void *that
)
532 /* ??4_Container_base0@std@@QAEAAU01@ABU01@@Z */
533 /* ??4_Container_base0@std@@QEAAAEAU01@AEBU01@@Z */
534 DEFINE_THISCALL_WRAPPER(Container_base0_op_assign
, 8)
535 void* __thiscall
Container_base0_op_assign(void *this, const void *that
)
540 /* ??0_Container_base12@std@@QAE@ABU01@@Z */
541 /* ??0_Container_base12@std@@QEAA@AEBU01@@Z */
542 DEFINE_THISCALL_WRAPPER(_Container_base12_copy_ctor
, 8)
543 _Container_base12
* __thiscall
_Container_base12_copy_ctor(
544 _Container_base12
*this, _Container_base12
*that
)
550 /* ??0_Container_base12@std@@QAE@XZ */
551 /* ??0_Container_base12@std@@QEAA@XZ */
552 DEFINE_THISCALL_WRAPPER(_Container_base12_ctor
, 4)
553 _Container_base12
* __thiscall
_Container_base12_ctor(_Container_base12
*this)
559 /* ??1_Container_base12@std@@QAE@XZ */
560 /* ??1_Container_base12@std@@QEAA@XZ */
561 DEFINE_THISCALL_WRAPPER(_Container_base12_dtor
, 4)
562 void __thiscall
_Container_base12_dtor(_Container_base12
*this)
566 /* ??4_Container_base12@std@@QAEAAU01@ABU01@@Z */
567 /* ??4_Container_base12@std@@QEAAAEAU01@AEBU01@@ */
568 DEFINE_THISCALL_WRAPPER(_Container_base12_op_assign
, 8)
569 _Container_base12
* __thiscall
_Container_base12_op_assign(
570 _Container_base12
*this, const _Container_base12
*that
)
575 /* ?_Getpfirst@_Container_base12@std@@QBEPAPAU_Iterator_base12@2@XZ */
576 /* ?_Getpfirst@_Container_base12@std@@QEBAPEAPEAU_Iterator_base12@2@XZ */
577 DEFINE_THISCALL_WRAPPER(_Container_base12__Getpfirst
, 4)
578 _Iterator_base12
** __thiscall
_Container_base12__Getpfirst(_Container_base12
*this)
580 return this->proxy
? &this->proxy
->head
: NULL
;
583 /* ?_Orphan_all@_Container_base12@std@@QAEXXZ */
584 /* ?_Orphan_all@_Container_base12@std@@QEAAXXZ */
585 DEFINE_THISCALL_WRAPPER(_Container_base12__Orphan_all
, 4)
586 void __thiscall
_Container_base12__Orphan_all(_Container_base12
*this)
590 /* ?_Swap_all@_Container_base12@std@@QAEXAAU12@@Z */
591 /* ?_Swap_all@_Container_base12@std@@QEAAXAEAU12@@Z */
592 DEFINE_THISCALL_WRAPPER(_Container_base12__Swap_all
, 8)
593 void __thiscall
_Container_base12__Swap_all(
594 _Container_base12
*this, _Container_base12
*that
)
596 _Container_proxy
*tmp
;
599 this->proxy
= that
->proxy
;
603 this->proxy
->cont
= this;
605 that
->proxy
->cont
= that
;
608 #if _MSVCP_VER >= 110
610 #define SECSPERDAY 86400
611 /* 1601 to 1970 is 369 years plus 89 leap days */
612 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
613 #define TICKSPERSEC 10000000
614 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
615 #define NANOSEC_PER_MILLISEC 1000000
616 #define MILLISEC_PER_SEC 1000
617 #define NANOSEC_PER_SEC (NANOSEC_PER_MILLISEC * MILLISEC_PER_SEC)
619 typedef int MSVCRT_long
;
627 /* _Xtime_get_ticks */
628 LONGLONG __cdecl
_Xtime_get_ticks(void)
634 GetSystemTimeAsFileTime(&ft
);
635 return ((LONGLONG
)ft
.dwHighDateTime
<<32) + ft
.dwLowDateTime
- TICKS_1601_TO_1970
;
639 int __cdecl
xtime_get(xtime
* t
, int unknown
)
648 ticks
= _Xtime_get_ticks();
649 t
->sec
= ticks
/ TICKSPERSEC
;
650 t
->nsec
= ticks
% TICKSPERSEC
* 100;
654 /* _Xtime_diff_to_millis2 */
655 MSVCRT_long __cdecl
_Xtime_diff_to_millis2(const xtime
*t1
, const xtime
*t2
)
657 LONGLONG diff_sec
, diff_nsec
;
659 TRACE("(%p, %p)\n", t1
, t2
);
661 diff_sec
= t1
->sec
- t2
->sec
;
662 diff_nsec
= t1
->nsec
- t2
->nsec
;
664 diff_sec
+= diff_nsec
/ NANOSEC_PER_SEC
;
665 diff_nsec
%= NANOSEC_PER_SEC
;
668 diff_nsec
+= NANOSEC_PER_SEC
;
671 if (diff_sec
<0 || (diff_sec
==0 && diff_nsec
<0))
673 return diff_sec
* MILLISEC_PER_SEC
+
674 (diff_nsec
+ NANOSEC_PER_MILLISEC
- 1) / NANOSEC_PER_MILLISEC
;
677 /* _Xtime_diff_to_millis */
678 MSVCRT_long __cdecl
_Xtime_diff_to_millis(const xtime
*t
)
685 return _Xtime_diff_to_millis2(t
, &now
);
690 unsigned int __cdecl
_Random_device(void)
696 /* TODO: throw correct exception in case of failure */
698 throw_exception("random number generator failed\n");
703 #if _MSVCP_VER >= 110
704 #define MTX_PLAIN 0x1
706 #define MTX_TIMED 0x4
707 #define MTX_RECURSIVE 0x100
717 #if _MSVCP_VER >= 140
718 typedef _Mtx_t _Mtx_arg_t
;
719 #define MTX_T_FROM_ARG(m) (m)
720 #define MTX_T_TO_ARG(m) (m)
722 typedef _Mtx_t
*_Mtx_arg_t
;
723 #define MTX_T_FROM_ARG(m) (*(m))
724 #define MTX_T_TO_ARG(m) (&(m))
727 void __cdecl
_Mtx_init_in_situ(_Mtx_t mtx
, int flags
)
729 if(flags
& ~(MTX_PLAIN
| MTX_TRY
| MTX_TIMED
| MTX_RECURSIVE
))
730 FIXME("unknown flags ignored: %x\n", flags
);
738 int __cdecl
_Mtx_init(_Mtx_t
*mtx
, int flags
)
740 *mtx
= operator_new(sizeof(**mtx
));
741 _Mtx_init_in_situ(*mtx
, flags
);
745 void __cdecl
_Mtx_destroy_in_situ(_Mtx_t mtx
)
747 cs_destroy(&mtx
->cs
);
750 void __cdecl
_Mtx_destroy(_Mtx_arg_t mtx
)
752 cs_destroy(&MTX_T_FROM_ARG(mtx
)->cs
);
753 operator_delete(MTX_T_FROM_ARG(mtx
));
756 int __cdecl
_Mtx_current_owns(_Mtx_arg_t mtx
)
758 return MTX_T_FROM_ARG(mtx
)->thread_id
== GetCurrentThreadId();
761 int __cdecl
_Mtx_lock(_Mtx_arg_t mtx
)
763 if(MTX_T_FROM_ARG(mtx
)->thread_id
!= GetCurrentThreadId()) {
764 cs_lock(&MTX_T_FROM_ARG(mtx
)->cs
);
765 MTX_T_FROM_ARG(mtx
)->thread_id
= GetCurrentThreadId();
766 }else if(!(MTX_T_FROM_ARG(mtx
)->flags
& MTX_RECURSIVE
)
767 && MTX_T_FROM_ARG(mtx
)->flags
!= MTX_PLAIN
) {
771 MTX_T_FROM_ARG(mtx
)->count
++;
775 int __cdecl
_Mtx_unlock(_Mtx_arg_t mtx
)
777 if(--MTX_T_FROM_ARG(mtx
)->count
)
780 MTX_T_FROM_ARG(mtx
)->thread_id
= -1;
781 cs_unlock(&MTX_T_FROM_ARG(mtx
)->cs
);
785 int __cdecl
_Mtx_trylock(_Mtx_arg_t mtx
)
787 if(MTX_T_FROM_ARG(mtx
)->thread_id
!= GetCurrentThreadId()) {
788 if(!cs_trylock(&MTX_T_FROM_ARG(mtx
)->cs
))
790 MTX_T_FROM_ARG(mtx
)->thread_id
= GetCurrentThreadId();
791 }else if(!(MTX_T_FROM_ARG(mtx
)->flags
& MTX_RECURSIVE
)
792 && MTX_T_FROM_ARG(mtx
)->flags
!= MTX_PLAIN
) {
796 MTX_T_FROM_ARG(mtx
)->count
++;
800 void* __cdecl
_Mtx_getconcrtcs(_Mtx_arg_t mtx
)
802 return &MTX_T_FROM_ARG(mtx
)->cs
;
805 void __cdecl
_Mtx_clear_owner(_Mtx_arg_t mtx
)
807 _Mtx_t m
= MTX_T_FROM_ARG(mtx
);
812 void __cdecl
_Mtx_reset_owner(_Mtx_arg_t mtx
)
814 _Mtx_t m
= MTX_T_FROM_ARG(mtx
);
815 m
->thread_id
= GetCurrentThreadId();
819 #define CND_TIMEDOUT 2
826 #if _MSVCP_VER >= 140
827 typedef _Cnd_t _Cnd_arg_t
;
828 #define CND_T_FROM_ARG(c) (c)
829 #define CND_T_TO_ARG(c) (c)
831 typedef _Cnd_t
*_Cnd_arg_t
;
832 #define CND_T_FROM_ARG(c) (*(c))
833 #define CND_T_TO_ARG(c) (&(c))
836 void __cdecl
_Cnd_init_in_situ(_Cnd_t cnd
)
841 int __cdecl
_Cnd_init(_Cnd_t
*cnd
)
843 *cnd
= operator_new(sizeof(**cnd
));
844 _Cnd_init_in_situ(*cnd
);
848 int __cdecl
_Cnd_wait(_Cnd_arg_t cnd
, _Mtx_arg_t mtx
)
850 cv
*cv
= &CND_T_FROM_ARG(cnd
)->cv
;
851 _Mtx_t m
= MTX_T_FROM_ARG(mtx
);
853 _Mtx_clear_owner(mtx
);
855 _Mtx_reset_owner(mtx
);
859 int __cdecl
_Cnd_timedwait(_Cnd_arg_t cnd
, _Mtx_arg_t mtx
, const xtime
*xt
)
861 cv
*cv
= &CND_T_FROM_ARG(cnd
)->cv
;
862 _Mtx_t m
= MTX_T_FROM_ARG(mtx
);
865 _Mtx_clear_owner(mtx
);
866 r
= cv_wait_for(cv
, &m
->cs
, _Xtime_diff_to_millis(xt
));
867 _Mtx_reset_owner(mtx
);
868 return r
? 0 : CND_TIMEDOUT
;
871 int __cdecl
_Cnd_broadcast(_Cnd_arg_t cnd
)
873 cv_notify_all(&CND_T_FROM_ARG(cnd
)->cv
);
877 int __cdecl
_Cnd_signal(_Cnd_arg_t cnd
)
879 cv_notify_one(&CND_T_FROM_ARG(cnd
)->cv
);
883 void __cdecl
_Cnd_destroy_in_situ(_Cnd_t cnd
)
885 _Cnd_broadcast(CND_T_TO_ARG(cnd
));
886 cv_destroy(&cnd
->cv
);
889 void __cdecl
_Cnd_destroy(_Cnd_arg_t cnd
)
893 cv_destroy(&CND_T_FROM_ARG(cnd
)->cv
);
894 operator_delete(CND_T_FROM_ARG(cnd
));
902 struct _to_broadcast
{
908 } broadcast_at_thread_exit
;
910 static CRITICAL_SECTION broadcast_at_thread_exit_cs
;
911 static CRITICAL_SECTION_DEBUG broadcast_at_thread_exit_cs_debug
=
913 0, 0, &broadcast_at_thread_exit_cs
,
914 { &broadcast_at_thread_exit_cs_debug
.ProcessLocksList
, &broadcast_at_thread_exit_cs_debug
.ProcessLocksList
},
915 0, 0, { (DWORD_PTR
)(__FILE__
": broadcast_at_thread_exit_cs") }
917 static CRITICAL_SECTION broadcast_at_thread_exit_cs
= { &broadcast_at_thread_exit_cs_debug
, -1, 0, 0, 0, 0 };
919 void __cdecl
_Cnd_register_at_thread_exit(_Cnd_arg_t cnd
, _Mtx_arg_t mtx
, int *p
)
921 struct _to_broadcast
*add
;
923 TRACE("(%p %p %p)\n", cnd
, mtx
, p
);
925 EnterCriticalSection(&broadcast_at_thread_exit_cs
);
926 if(!broadcast_at_thread_exit
.size
) {
927 broadcast_at_thread_exit
.to_broadcast
= HeapAlloc(GetProcessHeap(),
928 0, 8*sizeof(broadcast_at_thread_exit
.to_broadcast
[0]));
929 if(!broadcast_at_thread_exit
.to_broadcast
) {
930 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
933 broadcast_at_thread_exit
.size
= 8;
934 } else if(broadcast_at_thread_exit
.size
== broadcast_at_thread_exit
.used
) {
935 add
= HeapReAlloc(GetProcessHeap(), 0, broadcast_at_thread_exit
.to_broadcast
,
936 broadcast_at_thread_exit
.size
*2*sizeof(broadcast_at_thread_exit
.to_broadcast
[0]));
938 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
941 broadcast_at_thread_exit
.to_broadcast
= add
;
942 broadcast_at_thread_exit
.size
*= 2;
945 add
= broadcast_at_thread_exit
.to_broadcast
+ broadcast_at_thread_exit
.used
++;
946 add
->thread_id
= GetCurrentThreadId();
950 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
953 void __cdecl
_Cnd_unregister_at_thread_exit(_Mtx_arg_t mtx
)
957 TRACE("(%p)\n", mtx
);
959 EnterCriticalSection(&broadcast_at_thread_exit_cs
);
960 for(i
=0; i
<broadcast_at_thread_exit
.used
; i
++) {
961 if(broadcast_at_thread_exit
.to_broadcast
[i
].mtx
!= mtx
)
964 memmove(broadcast_at_thread_exit
.to_broadcast
+i
, broadcast_at_thread_exit
.to_broadcast
+i
+1,
965 (broadcast_at_thread_exit
.used
-i
-1)*sizeof(broadcast_at_thread_exit
.to_broadcast
[0]));
966 broadcast_at_thread_exit
.used
--;
969 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
972 void __cdecl
_Cnd_do_broadcast_at_thread_exit(void)
974 int i
, id
= GetCurrentThreadId();
978 EnterCriticalSection(&broadcast_at_thread_exit_cs
);
979 for(i
=0; i
<broadcast_at_thread_exit
.used
; i
++) {
980 if(broadcast_at_thread_exit
.to_broadcast
[i
].thread_id
!= id
)
983 _Mtx_unlock(broadcast_at_thread_exit
.to_broadcast
[i
].mtx
);
984 _Cnd_broadcast(broadcast_at_thread_exit
.to_broadcast
[i
].cnd
);
985 if(broadcast_at_thread_exit
.to_broadcast
[i
].p
)
986 *broadcast_at_thread_exit
.to_broadcast
[i
].p
= 1;
988 memmove(broadcast_at_thread_exit
.to_broadcast
+i
, broadcast_at_thread_exit
.to_broadcast
+i
+1,
989 (broadcast_at_thread_exit
.used
-i
-1)*sizeof(broadcast_at_thread_exit
.to_broadcast
[0]));
990 broadcast_at_thread_exit
.used
--;
993 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
998 #if _MSVCP_VER >= 100
1000 error_category base
;
1003 static custom_category iostream_category
;
1005 DEFINE_RTTI_DATA0(error_category
, 0, ".?AVerror_category@std@@")
1006 DEFINE_RTTI_DATA1(generic_category
, 0, &error_category_rtti_base_descriptor
, ".?AV_Generic_error_category@std@@")
1007 #if _MSVCP_VER == 100
1008 DEFINE_RTTI_DATA1(iostream_category
, 0, &error_category_rtti_base_descriptor
, ".?AV_Iostream_error_category@std@@")
1010 DEFINE_RTTI_DATA2(iostream_category
, 0, &generic_category_rtti_base_descriptor
,
1011 &error_category_rtti_base_descriptor
, ".?AV_Iostream_error_category@std@@")
1014 extern const vtable_ptr iostream_category_vtable
;
1016 static void iostream_category_ctor(custom_category
*this)
1018 this->base
.vtable
= &iostream_category_vtable
;
1019 #if _MSVCP_VER == 100
1020 this->type
= "iostream";
1024 DEFINE_THISCALL_WRAPPER(custom_category_vector_dtor
, 8)
1025 custom_category
* __thiscall
custom_category_vector_dtor(custom_category
*this, unsigned int flags
)
1027 TRACE("(%p %x)\n", this, flags
);
1029 /* we have an array, with the number of elements stored before the first object */
1030 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
1032 for(i
=*ptr
-1; i
>=0; i
--)
1033 operator_delete(ptr
);
1036 operator_delete(this);
1042 DEFINE_THISCALL_WRAPPER(custom_category_default_error_condition
, 12)
1043 /*error_condition*/void* __thiscall
custom_category_default_error_condition(
1044 custom_category
*this, /*error_condition*/void *ret
, int code
)
1046 FIXME("(%p %p %x) stub\n", this, ret
, code
);
1050 DEFINE_THISCALL_WRAPPER(custom_category_equivalent
, 12)
1051 bool __thiscall
custom_category_equivalent(const custom_category
*this,
1052 int code
, const /*error_condition*/void *condition
)
1054 FIXME("(%p %x %p) stub\n", this, code
, condition
);
1058 DEFINE_THISCALL_WRAPPER(custom_category_equivalent_code
, 12)
1059 bool __thiscall
custom_category_equivalent_code(custom_category
*this,
1060 const error_code
*code
, int condition
)
1062 FIXME("(%p %p %x) stub\n", this, code
, condition
);
1066 DEFINE_THISCALL_WRAPPER(iostream_category_name
, 4)
1067 const char* __thiscall
iostream_category_name(const custom_category
*this)
1069 #if _MSVCP_VER == 100
1076 DEFINE_THISCALL_WRAPPER(iostream_category_message
, 12)
1077 basic_string_char
* __thiscall
iostream_category_message(const custom_category
*this,
1078 basic_string_char
*ret
, int err
)
1080 if(err
== 1) return MSVCP_basic_string_char_ctor_cstr(ret
, "iostream error");
1081 return MSVCP_basic_string_char_ctor_cstr(ret
, strerror(err
));
1084 /* ?iostream_category@std@@YAABVerror_category@1@XZ */
1085 /* ?iostream_category@std@@YAAEBVerror_category@1@XZ */
1086 const error_category
* __cdecl
std_iostream_category(void)
1089 return &iostream_category
.base
;
1093 #if _MSVCP_VER == 100
1094 static custom_category system_category
;
1095 DEFINE_RTTI_DATA1(system_category
, 0, &error_category_rtti_base_descriptor
, ".?AV_System_error_category@std@@")
1097 extern const vtable_ptr system_category_vtable
;
1099 static void system_category_ctor(custom_category
*this)
1101 this->base
.vtable
= &system_category_vtable
;
1102 this->type
= "system";
1105 DEFINE_THISCALL_WRAPPER(custom_category_name
, 4)
1106 const char* __thiscall
custom_category_name(const custom_category
*this)
1111 /* ?system_category@std@@YAABVerror_category@1@XZ */
1112 /* ?system_category@std@@YAAEBVerror_category@1@XZ */
1113 const error_category
* __cdecl
std_system_category(void)
1116 return &system_category
.base
;
1120 #if _MSVCP_VER >= 100
1121 static custom_category generic_category
;
1123 extern const vtable_ptr generic_category_vtable
;
1125 static void generic_category_ctor(custom_category
*this)
1127 this->base
.vtable
= &generic_category_vtable
;
1128 #if _MSVCP_VER == 100
1129 this->type
= "generic";
1133 DEFINE_THISCALL_WRAPPER(generic_category_name
, 4)
1134 const char* __thiscall
generic_category_name(const custom_category
*this)
1136 #if _MSVCP_VER == 100
1143 DEFINE_THISCALL_WRAPPER(custom_category_message
, 12)
1144 basic_string_char
* __thiscall
custom_category_message(const custom_category
*this,
1145 basic_string_char
*ret
, int err
)
1147 return MSVCP_basic_string_char_ctor_cstr(ret
, strerror(err
));
1150 /* ?generic_category@std@@YAABVerror_category@1@XZ */
1151 /* ?generic_category@std@@YAAEBVerror_category@1@XZ */
1152 const error_category
* __cdecl
std_generic_category(void)
1155 return &generic_category
.base
;
1159 #if _MSVCP_VER >= 110
1160 static CRITICAL_SECTION call_once_cs
;
1161 static CRITICAL_SECTION_DEBUG call_once_cs_debug
=
1163 0, 0, &call_once_cs
,
1164 { &call_once_cs_debug
.ProcessLocksList
, &call_once_cs_debug
.ProcessLocksList
},
1165 0, 0, { (DWORD_PTR
)(__FILE__
": call_once_cs") }
1167 static CRITICAL_SECTION call_once_cs
= { &call_once_cs_debug
, -1, 0, 0, 0, 0 };
1169 void __cdecl
_Call_onceEx(int *once
, void (__cdecl
*func
)(void*), void *argv
)
1171 TRACE("%p %p %p\n", once
, func
, argv
);
1173 EnterCriticalSection(&call_once_cs
);
1175 /* FIXME: handle exceptions */
1179 LeaveCriticalSection(&call_once_cs
);
1182 static void __cdecl
call_once_func_wrapper(void *func
)
1184 ((void (__cdecl
*)(void))func
)();
1187 void __cdecl
_Call_once(int *once
, void (__cdecl
*func
)(void))
1189 TRACE("%p %p\n", once
, func
);
1190 _Call_onceEx(once
, call_once_func_wrapper
, func
);
1193 void __cdecl
_Do_call(void *this)
1195 CALL_VTBL_FUNC(this, 0, void, (void*), (this));
1199 #if _MSVCP_VER >= 110
1206 typedef int (__cdecl
*_Thrd_start_t
)(void*);
1208 #define _THRD_ERROR 4
1210 int __cdecl
_Thrd_equal(_Thrd_t a
, _Thrd_t b
)
1212 TRACE("(%p %lu %p %lu)\n", a
.hnd
, a
.id
, b
.hnd
, b
.id
);
1213 return a
.id
== b
.id
;
1216 int __cdecl
_Thrd_lt(_Thrd_t a
, _Thrd_t b
)
1218 TRACE("(%p %lu %p %lu)\n", a
.hnd
, a
.id
, b
.hnd
, b
.id
);
1222 void __cdecl
_Thrd_sleep(const xtime
*t
)
1225 Sleep(_Xtime_diff_to_millis(t
));
1228 void __cdecl
_Thrd_yield(void)
1234 static _Thrd_t
thread_current(void)
1238 if(DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
1239 GetCurrentProcess(), &ret
.hnd
, 0, FALSE
, DUPLICATE_SAME_ACCESS
)) {
1240 CloseHandle(ret
.hnd
);
1244 ret
.id
= GetCurrentThreadId();
1246 TRACE("(%p %lu)\n", ret
.hnd
, ret
.id
);
1251 _Thrd_t __cdecl
_Thrd_current(void)
1253 return thread_current();
1256 ULONGLONG __cdecl
_Thrd_current(void)
1263 C_ASSERT(sizeof(_Thrd_t
) <= sizeof(ULONGLONG
));
1265 ret
.thr
= thread_current();
1270 int __cdecl
_Thrd_join(_Thrd_t thr
, int *code
)
1272 TRACE("(%p %lu %p)\n", thr
.hnd
, thr
.id
, code
);
1273 if (WaitForSingleObject(thr
.hnd
, INFINITE
))
1277 GetExitCodeThread(thr
.hnd
, (DWORD
*)code
);
1279 CloseHandle(thr
.hnd
);
1283 int __cdecl
_Thrd_start(_Thrd_t
*thr
, LPTHREAD_START_ROUTINE proc
, void *arg
)
1285 TRACE("(%p %p %p)\n", thr
, proc
, arg
);
1286 thr
->hnd
= CreateThread(NULL
, 0, proc
, arg
, 0, &thr
->id
);
1287 return thr
->hnd
? 0 : _THRD_ERROR
;
1296 static DWORD WINAPI
thread_proc_wrapper(void *arg
)
1298 thread_proc_arg wrapped_arg
= *((thread_proc_arg
*)arg
);
1300 return wrapped_arg
.proc(wrapped_arg
.arg
);
1303 int __cdecl
_Thrd_create(_Thrd_t
*thr
, _Thrd_start_t proc
, void *arg
)
1305 thread_proc_arg
*wrapped_arg
;
1308 TRACE("(%p %p %p)\n", thr
, proc
, arg
);
1310 wrapped_arg
= malloc(sizeof(*wrapped_arg
));
1312 return _THRD_ERROR
; /* TODO: probably different error should be returned here */
1314 wrapped_arg
->proc
= proc
;
1315 wrapped_arg
->arg
= arg
;
1316 ret
= _Thrd_start(thr
, thread_proc_wrapper
, wrapped_arg
);
1317 if(ret
) free(wrapped_arg
);
1321 int __cdecl
_Thrd_detach(_Thrd_t thr
)
1323 return CloseHandle(thr
.hnd
) ? 0 : _THRD_ERROR
;
1328 const vtable_ptr
*vtable
;
1334 DEFINE_RTTI_DATA0(_Pad
, 0, ".?AV_Pad@std@@")
1336 /* ??_7_Pad@std@@6B@ */
1337 extern const vtable_ptr _Pad_vtable
;
1339 unsigned int __cdecl
_Thrd_hardware_concurrency(void)
1341 static unsigned int val
= -1;
1349 val
= si
.dwNumberOfProcessors
;
1355 unsigned int __cdecl
_Thrd_id(void)
1358 return GetCurrentThreadId();
1361 /* ??0_Pad@std@@QAE@XZ */
1362 /* ??0_Pad@std@@QEAA@XZ */
1363 DEFINE_THISCALL_WRAPPER(_Pad_ctor
, 4)
1364 _Pad
* __thiscall
_Pad_ctor(_Pad
*this)
1366 TRACE("(%p)\n", this);
1368 this->vtable
= &_Pad_vtable
;
1369 _Cnd_init(&this->cnd
);
1370 _Mtx_init(&this->mtx
, 0);
1371 this->launched
= FALSE
;
1372 _Mtx_lock(MTX_T_TO_ARG(this->mtx
));
1376 /* ??4_Pad@std@@QAEAAV01@ABV01@@Z */
1377 /* ??4_Pad@std@@QEAAAEAV01@AEBV01@@Z */
1378 DEFINE_THISCALL_WRAPPER(_Pad_op_assign
, 8)
1379 _Pad
* __thiscall
_Pad_op_assign(_Pad
*this, const _Pad
*copy
)
1381 TRACE("(%p %p)\n", this, copy
);
1383 this->cnd
= copy
->cnd
;
1384 this->mtx
= copy
->mtx
;
1385 this->launched
= copy
->launched
;
1389 /* ??0_Pad@std@@QAE@ABV01@@Z */
1390 /* ??0_Pad@std@@QEAA@AEBV01@@Z */
1391 DEFINE_THISCALL_WRAPPER(_Pad_copy_ctor
, 8)
1392 _Pad
* __thiscall
_Pad_copy_ctor(_Pad
*this, const _Pad
*copy
)
1394 TRACE("(%p %p)\n", this, copy
);
1396 this->vtable
= &_Pad_vtable
;
1397 return _Pad_op_assign(this, copy
);
1400 /* ??1_Pad@std@@QAE@XZ */
1401 /* ??1_Pad@std@@QEAA@XZ */
1402 DEFINE_THISCALL_WRAPPER(_Pad_dtor
, 4)
1403 void __thiscall
_Pad_dtor(_Pad
*this)
1405 TRACE("(%p)\n", this);
1407 _Mtx_unlock(MTX_T_TO_ARG(this->mtx
));
1408 _Mtx_destroy(MTX_T_TO_ARG(this->mtx
));
1409 _Cnd_destroy(CND_T_TO_ARG(this->cnd
));
1412 DEFINE_THISCALL_WRAPPER(_Pad__Go
, 4)
1413 #define call__Pad__Go(this) CALL_VTBL_FUNC(this, 0, unsigned int, (_Pad*), (this))
1414 unsigned int __thiscall
_Pad__Go(_Pad
*this)
1416 ERR("(%p) should not be called\n", this);
1420 static DWORD WINAPI
launch_thread_proc(void *arg
)
1423 return call__Pad__Go(this);
1426 /* ?_Launch@_Pad@std@@QAEXPAU_Thrd_imp_t@@@Z */
1427 /* ?_Launch@_Pad@std@@QEAAXPEAU_Thrd_imp_t@@@Z */
1428 DEFINE_THISCALL_WRAPPER(_Pad__Launch
, 8)
1429 void __thiscall
_Pad__Launch(_Pad
*this, _Thrd_t
*thr
)
1431 TRACE("(%p %p)\n", this, thr
);
1433 _Thrd_start(thr
, launch_thread_proc
, this);
1434 _Cnd_wait(CND_T_TO_ARG(this->cnd
), MTX_T_TO_ARG(this->mtx
));
1437 /* ?_Release@_Pad@std@@QAEXXZ */
1438 /* ?_Release@_Pad@std@@QEAAXXZ */
1439 DEFINE_THISCALL_WRAPPER(_Pad__Release
, 4)
1440 void __thiscall
_Pad__Release(_Pad
*this)
1442 TRACE("(%p)\n", this);
1444 _Mtx_lock(MTX_T_TO_ARG(this->mtx
));
1445 this->launched
= TRUE
;
1446 _Cnd_signal(CND_T_TO_ARG(this->cnd
));
1447 _Mtx_unlock(MTX_T_TO_ARG(this->mtx
));
1451 /*********************************************************************
1452 * __crtInitializeCriticalSectionEx (MSVCP140.@)
1454 BOOL CDECL
MSVCP__crtInitializeCriticalSectionEx(
1455 CRITICAL_SECTION
*cs
, DWORD spin_count
, DWORD flags
)
1457 TRACE("(%p %lx %lx)\n", cs
, spin_count
, flags
);
1458 return InitializeCriticalSectionEx(cs
, spin_count
, flags
);
1461 /*********************************************************************
1462 * __crtCreateEventExW (MSVCP140.@)
1464 HANDLE CDECL
MSVCP__crtCreateEventExW(
1465 SECURITY_ATTRIBUTES
*attribs
, LPCWSTR name
, DWORD flags
, DWORD access
)
1467 TRACE("(%p %s %#lx %#lx)\n", attribs
, debugstr_w(name
), flags
, access
);
1468 return CreateEventExW(attribs
, name
, flags
, access
);
1471 /*********************************************************************
1472 * __crtGetTickCount64 (MSVCP140.@)
1474 ULONGLONG CDECL
MSVCP__crtGetTickCount64(void)
1476 return GetTickCount64();
1479 /*********************************************************************
1480 * __crtGetCurrentProcessorNumber (MSVCP140.@)
1482 DWORD CDECL
MSVCP__crtGetCurrentProcessorNumber(void)
1484 return GetCurrentProcessorNumber();
1487 /*********************************************************************
1488 * __crtFlushProcessWriteBuffers (MSVCP140.@)
1490 VOID CDECL
MSVCP__crtFlushProcessWriteBuffers(void)
1492 return FlushProcessWriteBuffers();
1495 /*********************************************************************
1496 * __crtCreateSemaphoreExW (MSVCP140.@)
1498 HANDLE CDECL
MSVCP__crtCreateSemaphoreExW(
1499 SECURITY_ATTRIBUTES
*attribs
, LONG initial_count
, LONG max_count
, LPCWSTR name
,
1500 DWORD flags
, DWORD access
)
1502 TRACE("(%p %ld %ld %s %#lx %#lx)\n", attribs
, initial_count
, max_count
, debugstr_w(name
),
1504 return CreateSemaphoreExW(attribs
, initial_count
, max_count
, name
, flags
, access
);
1507 /*********************************************************************
1508 * __crtCreateThreadpoolTimer (MSVCP140.@)
1510 PTP_TIMER CDECL
MSVCP__crtCreateThreadpoolTimer(PTP_TIMER_CALLBACK callback
,
1511 PVOID userdata
, TP_CALLBACK_ENVIRON
*environment
)
1513 TRACE("(%p %p %p)\n", callback
, userdata
, environment
);
1514 return CreateThreadpoolTimer(callback
, userdata
, environment
);
1517 /*********************************************************************
1518 * __crtCloseThreadpoolTimer (MSVCP140.@)
1520 VOID CDECL
MSVCP__crtCloseThreadpoolTimer(TP_TIMER
*timer
)
1522 TRACE("(%p)\n", timer
);
1523 CloseThreadpoolTimer(timer
);
1526 /*********************************************************************
1527 * __crtSetThreadpoolTimer (MSVCP140.@)
1529 VOID CDECL
MSVCP__crtSetThreadpoolTimer(TP_TIMER
*timer
,
1530 FILETIME
*due_time
, DWORD period
, DWORD window_length
)
1532 TRACE("(%p %p %#lx %#lx)\n", timer
, due_time
, period
, window_length
);
1533 return SetThreadpoolTimer(timer
, due_time
, period
, window_length
);
1536 /*********************************************************************
1537 * __crtWaitForThreadpoolTimerCallbacks (MSVCP140.@)
1539 VOID CDECL
MSVCP__crtWaitForThreadpoolTimerCallbacks(TP_TIMER
*timer
, BOOL cancel
)
1541 TRACE("(%p %d)\n", timer
, cancel
);
1542 WaitForThreadpoolTimerCallbacks(timer
, cancel
);
1545 /*********************************************************************
1546 * __crtCreateThreadpoolWait (MSVCP140.@)
1548 PTP_WAIT CDECL
MSVCP__crtCreateThreadpoolWait(PTP_WAIT_CALLBACK callback
,
1549 PVOID userdata
, TP_CALLBACK_ENVIRON
*environment
)
1551 TRACE("(%p %p %p)\n", callback
, userdata
, environment
);
1552 return CreateThreadpoolWait(callback
, userdata
, environment
);
1555 /*********************************************************************
1556 * __crtCloseThreadpoolWait (MSVCP140.@)
1558 VOID CDECL
MSVCP__crtCloseThreadpoolWait(TP_WAIT
*wait
)
1560 TRACE("(%p)\n", wait
);
1561 CloseThreadpoolWait(wait
);
1564 /*********************************************************************
1565 * __crtSetThreadpoolWait (MSVCP140.@)
1567 VOID CDECL
MSVCP__crtSetThreadpoolWait(TP_WAIT
*wait
, HANDLE handle
, FILETIME
*due_time
)
1569 TRACE("(%p %p %p)\n", wait
, handle
, due_time
);
1570 return SetThreadpoolWait(wait
, handle
, due_time
);
1573 /*********************************************************************
1574 * __crtFreeLibraryWhenCallbackReturns (MSVCP140.@)
1576 VOID CDECL
MSVCP__crtFreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE instance
, HMODULE mod
)
1578 TRACE("(%p %p)\n", instance
, mod
);
1579 FreeLibraryWhenCallbackReturns(instance
, mod
);
1582 /* ?_Execute_once@std@@YAHAAUonce_flag@1@P6GHPAX1PAPAX@Z1@Z */
1583 /* ?_Execute_once@std@@YAHAEAUonce_flag@1@P6AHPEAX1PEAPEAX@Z1@Z */
1584 BOOL __cdecl
_Execute_once(INIT_ONCE
*flag
, PINIT_ONCE_FN func
, void *param
)
1586 return InitOnceExecuteOnce(flag
, func
, param
, NULL
);
1589 #if _MSVCP_VER >= 140
1590 LONGLONG __cdecl
_Query_perf_counter(void)
1593 QueryPerformanceCounter(&li
);
1597 LONGLONG __cdecl
_Query_perf_frequency(void)
1600 QueryPerformanceFrequency(&li
);
1605 void __cdecl
threads__Mtx_new(void **mtx
)
1607 *mtx
= operator_new(sizeof(CRITICAL_SECTION
));
1608 InitializeCriticalSection(*mtx
);
1611 void __cdecl
threads__Mtx_delete(void *mtx
)
1613 DeleteCriticalSection(mtx
);
1616 void __cdecl
threads__Mtx_lock(void *mtx
)
1618 EnterCriticalSection(mtx
);
1621 void __cdecl
threads__Mtx_unlock(void *mtx
)
1623 LeaveCriticalSection(mtx
);
1626 #if _MSVCP_VER >= 110
1627 static LONG shared_ptr_lock
;
1629 void __cdecl
_Lock_shared_ptr_spin_lock(void)
1633 while(InterlockedCompareExchange(&shared_ptr_lock
, 1, 0) != 0) {
1641 void __cdecl
_Unlock_shared_ptr_spin_lock(void)
1643 shared_ptr_lock
= 0;
1647 #if _MSVCP_VER >= 110 && _MSVCP_VER <= 120
1652 /* ?_1@placeholders@std@@3V?$_Ph@$00@2@A */
1653 /* ?_20@placeholders@std@@3V?$_Ph@$0BE@@2@A */
1654 _Ph _Ph_1
= {0}, _Ph_2
= {0}, _Ph_3
= {0}, _Ph_4
= {0}, _Ph_5
= {0};
1655 _Ph _Ph_6
= {0}, _Ph_7
= {0}, _Ph_8
= {0}, _Ph_9
= {0}, _Ph_10
= {0};
1656 _Ph _Ph_11
= {0}, _Ph_12
= {0}, _Ph_13
= {0}, _Ph_14
= {0}, _Ph_15
= {0};
1657 _Ph _Ph_16
= {0}, _Ph_17
= {0}, _Ph_18
= {0}, _Ph_19
= {0}, _Ph_20
= {0};
1660 #if _MSVCP_VER >= 110
1661 /* ?_Syserror_map@std@@YAPBDH@Z */
1662 /* ?_Syserror_map@std@@YAPEBDH@Z */
1663 const char* __cdecl
_Syserror_map(int err
)
1667 TRACE("(%d)\n", err
);
1669 for(i
= 0; i
< ARRAY_SIZE(syserror_map
); i
++)
1671 if(syserror_map
[i
].err
== err
)
1672 return syserror_map
[i
].str
;
1674 #if _MSVCP_VER >= 140
1675 return "unknown error";
1682 #if _MSVCP_VER >= 140
1683 /* ?_Winerror_message@std@@YAKKPADK@Z */
1684 /* ?_Winerror_message@std@@YAKKPEADK@Z */
1685 ULONG __cdecl
_Winerror_message(ULONG err
, char *buf
, ULONG size
)
1687 TRACE("(%lu %p %lu)\n", err
, buf
, size
);
1689 return FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
,
1690 NULL
, err
, 0, buf
, size
, NULL
);
1694 #if _MSVCP_VER >= 110
1695 /* ?_Winerror_map@std@@YAHH@Z */
1696 int __cdecl
_Winerror_map(int err
)
1698 int low
= 0, high
= ARRAY_SIZE(winerror_map
) - 1, mid
;
1702 mid
= (low
+ high
) / 2;
1704 if(err
== winerror_map
[mid
].winerr
)
1705 return winerror_map
[mid
].doserr
;
1706 if(err
> winerror_map
[mid
].winerr
)
1715 /* ?_Winerror_map@std@@YAPBDH@Z */
1716 /* ?_Winerror_map@std@@YAPEBDH@Z */
1717 const char *_Winerror_map_str(int err
)
1719 return _Syserror_map(_Winerror_map(err
));
1723 #if _MSVCP_VER >= 100
1724 __ASM_BLOCK_BEGIN(misc_vtables
)
1725 __ASM_VTABLE(iostream_category
,
1726 VTABLE_ADD_FUNC(custom_category_vector_dtor
)
1727 VTABLE_ADD_FUNC(iostream_category_name
)
1728 VTABLE_ADD_FUNC(iostream_category_message
)
1729 VTABLE_ADD_FUNC(custom_category_default_error_condition
)
1730 VTABLE_ADD_FUNC(custom_category_equivalent
)
1731 VTABLE_ADD_FUNC(custom_category_equivalent_code
));
1732 #if _MSVCP_VER == 100
1733 __ASM_VTABLE(system_category
,
1734 VTABLE_ADD_FUNC(custom_category_vector_dtor
)
1735 VTABLE_ADD_FUNC(custom_category_name
)
1736 VTABLE_ADD_FUNC(custom_category_message
)
1737 VTABLE_ADD_FUNC(custom_category_default_error_condition
)
1738 VTABLE_ADD_FUNC(custom_category_equivalent
)
1739 VTABLE_ADD_FUNC(custom_category_equivalent_code
));
1741 __ASM_VTABLE(generic_category
,
1742 VTABLE_ADD_FUNC(custom_category_vector_dtor
)
1743 VTABLE_ADD_FUNC(generic_category_name
)
1744 VTABLE_ADD_FUNC(custom_category_message
)
1745 VTABLE_ADD_FUNC(custom_category_default_error_condition
)
1746 VTABLE_ADD_FUNC(custom_category_equivalent
)
1747 VTABLE_ADD_FUNC(custom_category_equivalent_code
));
1748 #if _MSVCP_VER >= 110
1750 VTABLE_ADD_FUNC(_Pad__Go
));
1754 void init_misc(void *base
)
1757 #if _MSVCP_VER >= 100
1758 init_error_category_rtti(base
);
1759 init_generic_category_rtti(base
);
1760 init_iostream_category_rtti(base
);
1762 #if _MSVCP_VER == 100
1763 init_system_category_rtti(base
);
1765 #if _MSVCP_VER >= 110
1766 init__Pad_rtti(base
);
1770 #if _MSVCP_VER >= 100
1771 iostream_category_ctor(&iostream_category
);
1772 generic_category_ctor(&generic_category
);
1775 #if _MSVCP_VER == 100
1776 system_category_ctor(&system_category
);
1780 void free_misc(void)
1782 #if _MSVCP_VER >= 110
1783 HeapFree(GetProcessHeap(), 0, broadcast_at_thread_exit
.to_broadcast
);