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
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcp
);
33 /* error strings generated with glibc strerror */
34 static const char str_EPERM
[] = "operation not permitted";
35 static const char str_ENOENT
[] = "no such file or directory";
36 static const char str_ESRCH
[] = "no such process";
37 static const char str_EINTR
[] = "interrupted system call";
38 static const char str_EIO
[] = "input/output error";
39 static const char str_ENXIO
[] = "no such device or address";
40 static const char str_E2BIG
[] = "argument list too long";
41 static const char str_ENOEXEC
[] = "exec format error";
42 static const char str_EBADF
[] = "bad file descriptor";
43 static const char str_ECHILD
[] = "no child processes";
44 static const char str_EAGAIN
[] = "resource temporarily unavailable";
45 static const char str_ENOMEM
[] = "cannot allocate memory";
46 static const char str_EACCES
[] = "permission denied";
47 static const char str_EFAULT
[] = "bad address";
48 static const char str_EBUSY
[] = "device or resource busy";
49 static const char str_EEXIST
[] = "file exists";
50 static const char str_EXDEV
[] = "invalid cross-device link";
51 static const char str_ENODEV
[] = "no such device";
52 static const char str_ENOTDIR
[] = "not a directory";
53 static const char str_EISDIR
[] = "is a directory";
54 static const char str_EINVAL
[] = "invalid argument";
55 static const char str_ENFILE
[] = "too many open files in system";
56 static const char str_EMFILE
[] = "too many open files";
57 static const char str_ENOTTY
[] = "inappropriate ioctl for device";
58 static const char str_EFBIG
[] = "file too large";
59 static const char str_ENOSPC
[] = "no space left on device";
60 static const char str_ESPIPE
[] = "illegal seek";
61 static const char str_EROFS
[] = "read-only file system";
62 static const char str_EMLINK
[] = "too many links";
63 static const char str_EPIPE
[] = "broken pipe";
64 static const char str_EDOM
[] = "numerical argument out of domain";
65 static const char str_ERANGE
[] = "numerical result out of range";
66 static const char str_EDEADLK
[] = "resource deadlock avoided";
67 static const char str_ENAMETOOLONG
[] = "file name too long";
68 static const char str_ENOLCK
[] = "no locks available";
69 static const char str_ENOSYS
[] = "function not implemented";
70 static const char str_ENOTEMPTY
[] = "directory not empty";
71 static const char str_EILSEQ
[] = "invalid or incomplete multibyte or wide character";
72 static const char str_EADDRINUSE
[] = "address already in use";
73 static const char str_EADDRNOTAVAIL
[] = "cannot assign requested address";
74 static const char str_EAFNOSUPPORT
[] = "address family not supported by protocol";
75 static const char str_EALREADY
[] = "operation already in progress";
76 static const char str_EBADMSG
[] = "not a data message";
77 static const char str_ECANCELED
[] = "operation Canceled";
78 static const char str_ECONNABORTED
[] = "software caused connection abort";
79 static const char str_ECONNREFUSED
[] = "connection refused";
80 static const char str_ECONNRESET
[] = "connection reset by peer";
81 static const char str_EDESTADDRREQ
[] = "destination address required";
82 static const char str_EHOSTUNREACH
[] = "no route to host";
83 static const char str_EIDRM
[] = "identifier removed";
84 static const char str_EINPROGRESS
[] = "operation now in progress";
85 static const char str_EISCONN
[] = "transport endpoint is already connected";
86 static const char str_ELOOP
[] = "too many symbolic links encountered";
87 static const char str_EMSGSIZE
[] = "message too long";
88 static const char str_ENETDOWN
[] = "network is down";
89 static const char str_ENETRESET
[] = "network dropped connection because of reset";
90 static const char str_ENETUNREACH
[] = "network is unreachable";
91 static const char str_ENOBUFS
[] = "no buffer space available";
92 static const char str_ENODATA
[] = "no data available";
93 static const char str_ENOLINK
[] = "link has been severed";
94 static const char str_ENOMSG
[] = "no message of desired type";
95 static const char str_ENOPROTOOPT
[] = "protocol not available";
96 static const char str_ENOSR
[] = "out of streams resources";
97 static const char str_ENOSTR
[] = "device not a stream";
98 static const char str_ENOTCONN
[] = "transport endpoint is not connected";
99 static const char str_ENOTRECOVERABLE
[] = "state not recoverable";
100 static const char str_ENOTSOCK
[] = "socket operation on non-socket";
101 static const char str_ENOTSUP
[] = "not supported";
102 static const char str_EOPNOTSUPP
[] = "operation not supported on transport endpoint";
103 static const char str_EOVERFLOW
[] = "value too large for defined data type";
104 static const char str_EOWNERDEAD
[] = "owner died";
105 static const char str_EPROTO
[] = "protocol error";
106 static const char str_EPROTONOSUPPORT
[] = "protocol not supported";
107 static const char str_EPROTOTYPE
[] = "protocol wrong type for socket";
108 static const char str_ETIME
[] = "timer expired";
109 static const char str_ETIMEDOUT
[] = "connection timed out";
110 static const char str_ETXTBSY
[] = "text file busy";
111 static const char str_EWOULDBLOCK
[] = "operation would block";
113 static const struct {
119 {ENOENT
, str_ENOENT
},
125 {ENOEXEC
, str_ENOEXEC
},
127 {ECHILD
, str_ECHILD
},
128 {EAGAIN
, str_EAGAIN
},
129 {ENOMEM
, str_ENOMEM
},
130 {EACCES
, str_EACCES
},
131 {EFAULT
, str_EFAULT
},
133 {EEXIST
, str_EEXIST
},
135 {ENODEV
, str_ENODEV
},
136 {ENOTDIR
, str_ENOTDIR
},
137 {EISDIR
, str_EISDIR
},
138 {EINVAL
, str_EINVAL
},
139 {ENFILE
, str_ENFILE
},
140 {EMFILE
, str_EMFILE
},
141 {ENOTTY
, str_ENOTTY
},
143 {ENOSPC
, str_ENOSPC
},
144 {ESPIPE
, str_ESPIPE
},
146 {EMLINK
, str_EMLINK
},
149 {ERANGE
, str_ERANGE
},
150 {EDEADLK
, str_EDEADLK
},
151 {ENAMETOOLONG
, str_ENAMETOOLONG
},
152 {ENOLCK
, str_ENOLCK
},
153 {ENOSYS
, str_ENOSYS
},
154 {ENOTEMPTY
, str_ENOTEMPTY
},
155 {EILSEQ
, str_EILSEQ
},
156 {EADDRINUSE
, str_EADDRINUSE
},
157 {EADDRNOTAVAIL
, str_EADDRNOTAVAIL
},
158 {EAFNOSUPPORT
, str_EAFNOSUPPORT
},
159 {EALREADY
, str_EALREADY
},
160 {EBADMSG
, str_EBADMSG
},
161 {ECANCELED
, str_ECANCELED
},
162 {ECONNABORTED
, str_ECONNABORTED
},
163 {ECONNREFUSED
, str_ECONNREFUSED
},
164 {ECONNRESET
, str_ECONNRESET
},
165 {EDESTADDRREQ
, str_EDESTADDRREQ
},
166 {EHOSTUNREACH
, str_EHOSTUNREACH
},
168 {EINPROGRESS
, str_EINPROGRESS
},
169 {EISCONN
, str_EISCONN
},
171 {EMSGSIZE
, str_EMSGSIZE
},
172 {ENETDOWN
, str_ENETDOWN
},
173 {ENETRESET
, str_ENETRESET
},
174 {ENETUNREACH
, str_ENETUNREACH
},
175 {ENOBUFS
, str_ENOBUFS
},
176 {ENODATA
, str_ENODATA
},
177 {ENOLINK
, str_ENOLINK
},
178 {ENOMSG
, str_ENOMSG
},
179 {ENOPROTOOPT
, str_ENOPROTOOPT
},
181 {ENOSTR
, str_ENOSTR
},
182 {ENOTCONN
, str_ENOTCONN
},
183 {ENOTRECOVERABLE
, str_ENOTRECOVERABLE
},
184 {ENOTSOCK
, str_ENOTSOCK
},
185 {ENOTSUP
, str_ENOTSUP
},
186 {EOPNOTSUPP
, str_EOPNOTSUPP
},
187 {EOVERFLOW
, str_EOVERFLOW
},
188 {EOWNERDEAD
, str_EOWNERDEAD
},
189 {EPROTO
, str_EPROTO
},
190 {EPROTONOSUPPORT
, str_EPROTONOSUPPORT
},
191 {EPROTOTYPE
, str_EPROTOTYPE
},
193 {ETIMEDOUT
, str_ETIMEDOUT
},
194 {ETXTBSY
, str_ETXTBSY
},
195 {EWOULDBLOCK
, str_EWOULDBLOCK
},
199 #if _MSVCP_VER >= 140
200 static const struct {
205 {ERROR_INVALID_FUNCTION
, ENOSYS
}, {ERROR_FILE_NOT_FOUND
, ENOENT
},
206 {ERROR_PATH_NOT_FOUND
, ENOENT
}, {ERROR_TOO_MANY_OPEN_FILES
, EMFILE
},
207 {ERROR_ACCESS_DENIED
, EACCES
}, {ERROR_INVALID_HANDLE
, EINVAL
},
208 {ERROR_NOT_ENOUGH_MEMORY
, ENOMEM
}, {ERROR_INVALID_ACCESS
, EACCES
},
209 {ERROR_OUTOFMEMORY
, ENOMEM
}, {ERROR_INVALID_DRIVE
, ENODEV
},
210 {ERROR_CURRENT_DIRECTORY
, EACCES
}, {ERROR_NOT_SAME_DEVICE
, EXDEV
},
211 {ERROR_WRITE_PROTECT
, EACCES
}, {ERROR_BAD_UNIT
, ENODEV
},
212 {ERROR_NOT_READY
, EAGAIN
}, {ERROR_SEEK
, EIO
}, {ERROR_WRITE_FAULT
, EIO
},
213 {ERROR_READ_FAULT
, EIO
}, {ERROR_SHARING_VIOLATION
, EACCES
},
214 {ERROR_LOCK_VIOLATION
, ENOLCK
}, {ERROR_HANDLE_DISK_FULL
, ENOSPC
},
215 {ERROR_NOT_SUPPORTED
, ENOTSUP
}, {ERROR_DEV_NOT_EXIST
, ENODEV
},
216 {ERROR_FILE_EXISTS
, EEXIST
}, {ERROR_CANNOT_MAKE
, EACCES
},
217 {ERROR_INVALID_PARAMETER
, EINVAL
}, {ERROR_OPEN_FAILED
, EIO
},
218 {ERROR_BUFFER_OVERFLOW
, ENAMETOOLONG
}, {ERROR_DISK_FULL
, ENOSPC
},
219 {ERROR_INVALID_NAME
, ENOENT
}, {ERROR_NEGATIVE_SEEK
, EINVAL
},
220 {ERROR_BUSY_DRIVE
, EBUSY
}, {ERROR_DIR_NOT_EMPTY
, ENOTEMPTY
},
221 {ERROR_BUSY
, EBUSY
}, {ERROR_ALREADY_EXISTS
, EEXIST
},
222 {ERROR_LOCKED
, ENOLCK
}, {ERROR_DIRECTORY
, EINVAL
},
223 {ERROR_OPERATION_ABORTED
, ECANCELED
}, {ERROR_NOACCESS
, EACCES
},
224 {ERROR_CANTOPEN
, EIO
}, {ERROR_CANTREAD
, EIO
}, {ERROR_CANTWRITE
, EIO
},
225 {ERROR_RETRY
, EAGAIN
}, {ERROR_OPEN_FILES
, EBUSY
},
226 {ERROR_DEVICE_IN_USE
, EBUSY
}, {ERROR_REPARSE_TAG_INVALID
, EINVAL
},
227 {WSAEINTR
, EINTR
}, {WSAEBADF
, EBADF
}, {WSAEACCES
, EACCES
},
228 {WSAEFAULT
, EFAULT
}, {WSAEINVAL
, EINVAL
}, {WSAEMFILE
, EMFILE
},
229 {WSAEWOULDBLOCK
, EWOULDBLOCK
}, {WSAEINPROGRESS
, EINPROGRESS
},
230 {WSAEALREADY
, EALREADY
}, {WSAENOTSOCK
, ENOTSOCK
},
231 {WSAEDESTADDRREQ
, EDESTADDRREQ
}, {WSAEMSGSIZE
, EMSGSIZE
},
232 {WSAEPROTOTYPE
, EPROTOTYPE
}, {WSAENOPROTOOPT
, ENOPROTOOPT
},
233 {WSAEPROTONOSUPPORT
, EPROTONOSUPPORT
}, {WSAEOPNOTSUPP
, EOPNOTSUPP
},
234 {WSAEAFNOSUPPORT
, EAFNOSUPPORT
}, {WSAEADDRINUSE
, EADDRINUSE
},
235 {WSAEADDRNOTAVAIL
, EADDRNOTAVAIL
}, {WSAENETDOWN
, ENETDOWN
},
236 {WSAENETUNREACH
, ENETUNREACH
}, {WSAENETRESET
, ENETRESET
},
237 {WSAECONNABORTED
, ECONNABORTED
}, {WSAECONNRESET
, ECONNRESET
},
238 {WSAENOBUFS
, ENOBUFS
}, {WSAEISCONN
, EISCONN
}, {WSAENOTCONN
, ENOTCONN
},
239 {WSAETIMEDOUT
, ETIMEDOUT
}, {WSAECONNREFUSED
, ECONNREFUSED
},
240 {WSAENAMETOOLONG
, ENAMETOOLONG
}, {WSAEHOSTUNREACH
, EHOSTUNREACH
}
244 struct __Container_proxy
;
247 struct __Container_proxy
*proxy
;
250 typedef struct __Iterator_base12
{
251 struct __Container_proxy
*proxy
;
252 struct __Iterator_base12
*next
;
255 typedef struct __Container_proxy
{
256 const _Container_base12
*cont
;
257 _Iterator_base12
*head
;
260 /* ??0_Mutex@std@@QAE@XZ */
261 /* ??0_Mutex@std@@QEAA@XZ */
262 DEFINE_THISCALL_WRAPPER(mutex_ctor
, 4)
263 mutex
* __thiscall
mutex_ctor(mutex
*this)
265 CRITICAL_SECTION
*cs
= operator_new(sizeof(*cs
));
266 InitializeCriticalSection(cs
);
267 cs
->DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": _Mutex critical section");
272 /* ??1_Mutex@std@@QAE@XZ */
273 /* ??1_Mutex@std@@QEAA@XZ */
274 DEFINE_THISCALL_WRAPPER(mutex_dtor
, 4)
275 void __thiscall
mutex_dtor(mutex
*this)
277 ((CRITICAL_SECTION
*)this->mutex
)->DebugInfo
->Spare
[0] = 0;
278 DeleteCriticalSection(this->mutex
);
279 operator_delete(this->mutex
);
282 /* ?_Lock@_Mutex@std@@QAEXXZ */
283 /* ?_Lock@_Mutex@std@@QEAAXXZ */
284 DEFINE_THISCALL_WRAPPER(mutex_lock
, 4)
285 void __thiscall
mutex_lock(mutex
*this)
287 EnterCriticalSection(this->mutex
);
290 /* ?_Unlock@_Mutex@std@@QAEXXZ */
291 /* ?_Unlock@_Mutex@std@@QEAAXXZ */
292 DEFINE_THISCALL_WRAPPER(mutex_unlock
, 4)
293 void __thiscall
mutex_unlock(mutex
*this)
295 LeaveCriticalSection(this->mutex
);
298 /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */
299 /* ?_Mutex_Lock@_Mutex@std@@CAXPEAV12@@Z */
300 void CDECL
mutex_mutex_lock(mutex
*m
)
305 /* ?_Mutex_Unlock@_Mutex@std@@CAXPAV12@@Z */
306 /* ?_Mutex_Unlock@_Mutex@std@@CAXPEAV12@@Z */
307 void CDECL
mutex_mutex_unlock(mutex
*m
)
312 /* ?_Mutex_ctor@_Mutex@std@@CAXPAV12@@Z */
313 /* ?_Mutex_ctor@_Mutex@std@@CAXPEAV12@@Z */
314 void CDECL
mutex_mutex_ctor(mutex
*m
)
319 /* ?_Mutex_dtor@_Mutex@std@@CAXPAV12@@Z */
320 /* ?_Mutex_dtor@_Mutex@std@@CAXPEAV12@@Z */
321 void CDECL
mutex_mutex_dtor(mutex
*m
)
326 static CRITICAL_SECTION lockit_cs
[_MAX_LOCK
];
328 static LONG init_locks
;
329 static CRITICAL_SECTION init_locks_cs
;
330 static CRITICAL_SECTION_DEBUG init_locks_cs_debug
=
332 0, 0, &init_locks_cs
,
333 { &init_locks_cs_debug
.ProcessLocksList
, &init_locks_cs_debug
.ProcessLocksList
},
334 0, 0, { (DWORD_PTR
)(__FILE__
": init_locks_cs") }
336 static CRITICAL_SECTION init_locks_cs
= { &init_locks_cs_debug
, -1, 0, 0, 0, 0 };
338 /* ?_Init_locks_ctor@_Init_locks@std@@CAXPAV12@@Z */
339 /* ?_Init_locks_ctor@_Init_locks@std@@CAXPEAV12@@Z */
340 void __cdecl
_Init_locks__Init_locks_ctor(_Init_locks
*this)
344 EnterCriticalSection(&init_locks_cs
);
347 for(i
=0; i
<_MAX_LOCK
; i
++)
349 InitializeCriticalSection(&lockit_cs
[i
]);
350 lockit_cs
[i
].DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": _Lockit critical section");
354 LeaveCriticalSection(&init_locks_cs
);
357 /* ??0_Init_locks@std@@QAE@XZ */
358 /* ??0_Init_locks@std@@QEAA@XZ */
359 DEFINE_THISCALL_WRAPPER(_Init_locks_ctor
, 4)
360 _Init_locks
* __thiscall
_Init_locks_ctor(_Init_locks
*this)
362 _Init_locks__Init_locks_ctor(this);
366 /* ?_Init_locks_dtor@_Init_locks@std@@CAXPAV12@@Z */
367 /* ?_Init_locks_dtor@_Init_locks@std@@CAXPEAV12@@Z */
368 void __cdecl
_Init_locks__Init_locks_dtor(_Init_locks
*this)
372 EnterCriticalSection(&init_locks_cs
);
376 for(i
=0; i
<_MAX_LOCK
; i
++)
378 lockit_cs
[i
].DebugInfo
->Spare
[0] = 0;
379 DeleteCriticalSection(&lockit_cs
[i
]);
382 LeaveCriticalSection(&init_locks_cs
);
385 /* ??1_Init_locks@std@@QAE@XZ */
386 /* ??1_Init_locks@std@@QEAA@XZ */
387 DEFINE_THISCALL_WRAPPER(_Init_locks_dtor
, 4)
388 void __thiscall
_Init_locks_dtor(_Init_locks
*this)
390 _Init_locks__Init_locks_dtor(this);
394 static inline int get_locktype( _Lockit
*lockit
) { return lockit
->locktype
; }
395 static inline void set_locktype( _Lockit
*lockit
, int type
) { lockit
->locktype
= type
; }
397 static inline int get_locktype( _Lockit
*lockit
) { return 0; }
398 static inline void set_locktype( _Lockit
*lockit
, int type
) { }
401 /* ?_Lockit_ctor@_Lockit@std@@SAXH@Z */
402 void __cdecl
_Lockit__Lockit_ctor_lock(int locktype
)
404 EnterCriticalSection(&lockit_cs
[locktype
]);
407 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@H@Z */
408 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@H@Z */
409 void __cdecl
_Lockit__Lockit_ctor_locktype(_Lockit
*lockit
, int locktype
)
411 set_locktype( lockit
, locktype
);
412 _Lockit__Lockit_ctor_lock(locktype
);
415 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@@Z */
416 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@@Z */
417 void __cdecl
_Lockit__Lockit_ctor(_Lockit
*lockit
)
419 _Lockit__Lockit_ctor_locktype(lockit
, 0);
422 /* ??0_Lockit@std@@QAE@H@Z */
423 /* ??0_Lockit@std@@QEAA@H@Z */
424 DEFINE_THISCALL_WRAPPER(_Lockit_ctor_locktype
, 8)
425 _Lockit
* __thiscall
_Lockit_ctor_locktype(_Lockit
*this, int locktype
)
427 _Lockit__Lockit_ctor_locktype(this, locktype
);
431 /* ??0_Lockit@std@@QAE@XZ */
432 /* ??0_Lockit@std@@QEAA@XZ */
433 DEFINE_THISCALL_WRAPPER(_Lockit_ctor
, 4)
434 _Lockit
* __thiscall
_Lockit_ctor(_Lockit
*this)
436 _Lockit__Lockit_ctor_locktype(this, 0);
440 /* ?_Lockit_dtor@_Lockit@std@@SAXH@Z */
441 void __cdecl
_Lockit__Lockit_dtor_unlock(int locktype
)
443 LeaveCriticalSection(&lockit_cs
[locktype
]);
446 /* ?_Lockit_dtor@_Lockit@std@@CAXPAV12@@Z */
447 /* ?_Lockit_dtor@_Lockit@std@@CAXPEAV12@@Z */
448 void __cdecl
_Lockit__Lockit_dtor(_Lockit
*lockit
)
450 _Lockit__Lockit_dtor_unlock(get_locktype( lockit
));
453 /* ??1_Lockit@std@@QAE@XZ */
454 /* ??1_Lockit@std@@QEAA@XZ */
455 DEFINE_THISCALL_WRAPPER(_Lockit_dtor
, 4)
456 void __thiscall
_Lockit_dtor(_Lockit
*this)
458 _Lockit__Lockit_dtor(this);
462 unsigned short __cdecl
wctype(const char *property
)
464 static const struct {
468 { "alnum", _DIGIT
|_ALPHA
},
470 { "cntrl", _CONTROL
},
472 { "graph", _DIGIT
|_PUNCT
|_ALPHA
},
474 { "print", _DIGIT
|_PUNCT
|_BLANK
|_ALPHA
},
482 for(i
= 0; i
< ARRAY_SIZE(properties
); i
++)
483 if(!strcmp(property
, properties
[i
].name
))
484 return properties
[i
].mask
;
489 typedef void (__cdecl
*MSVCP_new_handler_func
)(void);
490 static MSVCP_new_handler_func MSVCP_new_handler
;
491 static int __cdecl
new_handler_wrapper(size_t unused
)
497 /* ?set_new_handler@std@@YAP6AXXZP6AXXZ@Z */
498 MSVCP_new_handler_func __cdecl
set_new_handler(MSVCP_new_handler_func new_handler
)
500 MSVCP_new_handler_func old_handler
= MSVCP_new_handler
;
502 TRACE("%p\n", new_handler
);
504 MSVCP_new_handler
= new_handler
;
505 MSVCRT_set_new_handler(new_handler
? new_handler_wrapper
: NULL
);
509 /* ?set_new_handler@std@@YAP6AXXZH@Z */
510 MSVCP_new_handler_func __cdecl
set_new_handler_reset(int unused
)
512 return set_new_handler(NULL
);
515 /* _Container_base0 is used by apps compiled without iterator checking
516 * (i.e. with _ITERATOR_DEBUG_LEVEL=0 ).
517 * It provides empty versions of methods used by visual c++'s stl's
519 * msvcr100 has to provide them in case apps are compiled with /Od
520 * or the optimizer fails to inline those (empty) calls.
523 /* ?_Orphan_all@_Container_base0@std@@QAEXXZ */
524 /* ?_Orphan_all@_Container_base0@std@@QEAAXXZ */
525 DEFINE_THISCALL_WRAPPER(Container_base0_Orphan_all
, 4)
526 void __thiscall
Container_base0_Orphan_all(void *this)
530 /* ?_Swap_all@_Container_base0@std@@QAEXAAU12@@Z */
531 /* ?_Swap_all@_Container_base0@std@@QEAAXAEAU12@@Z */
532 DEFINE_THISCALL_WRAPPER(Container_base0_Swap_all
, 8)
533 void __thiscall
Container_base0_Swap_all(void *this, void *that
)
537 /* ??4_Container_base0@std@@QAEAAU01@ABU01@@Z */
538 /* ??4_Container_base0@std@@QEAAAEAU01@AEBU01@@Z */
539 DEFINE_THISCALL_WRAPPER(Container_base0_op_assign
, 8)
540 void* __thiscall
Container_base0_op_assign(void *this, const void *that
)
545 /* ??0_Container_base12@std@@QAE@ABU01@@Z */
546 /* ??0_Container_base12@std@@QEAA@AEBU01@@Z */
547 DEFINE_THISCALL_WRAPPER(_Container_base12_copy_ctor
, 8)
548 _Container_base12
* __thiscall
_Container_base12_copy_ctor(
549 _Container_base12
*this, _Container_base12
*that
)
555 /* ??0_Container_base12@std@@QAE@XZ */
556 /* ??0_Container_base12@std@@QEAA@XZ */
557 DEFINE_THISCALL_WRAPPER(_Container_base12_ctor
, 4)
558 _Container_base12
* __thiscall
_Container_base12_ctor(_Container_base12
*this)
564 /* ??1_Container_base12@std@@QAE@XZ */
565 /* ??1_Container_base12@std@@QEAA@XZ */
566 DEFINE_THISCALL_WRAPPER(_Container_base12_dtor
, 4)
567 void __thiscall
_Container_base12_dtor(_Container_base12
*this)
571 /* ??4_Container_base12@std@@QAEAAU01@ABU01@@Z */
572 /* ??4_Container_base12@std@@QEAAAEAU01@AEBU01@@ */
573 DEFINE_THISCALL_WRAPPER(_Container_base12_op_assign
, 8)
574 _Container_base12
* __thiscall
_Container_base12_op_assign(
575 _Container_base12
*this, const _Container_base12
*that
)
580 /* ?_Getpfirst@_Container_base12@std@@QBEPAPAU_Iterator_base12@2@XZ */
581 /* ?_Getpfirst@_Container_base12@std@@QEBAPEAPEAU_Iterator_base12@2@XZ */
582 DEFINE_THISCALL_WRAPPER(_Container_base12__Getpfirst
, 4)
583 _Iterator_base12
** __thiscall
_Container_base12__Getpfirst(_Container_base12
*this)
585 return this->proxy
? &this->proxy
->head
: NULL
;
588 /* ?_Orphan_all@_Container_base12@std@@QAEXXZ */
589 /* ?_Orphan_all@_Container_base12@std@@QEAAXXZ */
590 DEFINE_THISCALL_WRAPPER(_Container_base12__Orphan_all
, 4)
591 void __thiscall
_Container_base12__Orphan_all(_Container_base12
*this)
595 /* ?_Swap_all@_Container_base12@std@@QAEXAAU12@@Z */
596 /* ?_Swap_all@_Container_base12@std@@QEAAXAEAU12@@Z */
597 DEFINE_THISCALL_WRAPPER(_Container_base12__Swap_all
, 8)
598 void __thiscall
_Container_base12__Swap_all(
599 _Container_base12
*this, _Container_base12
*that
)
601 _Container_proxy
*tmp
;
604 this->proxy
= that
->proxy
;
608 this->proxy
->cont
= this;
610 that
->proxy
->cont
= that
;
613 #if _MSVCP_VER >= 110
615 #define SECSPERDAY 86400
616 /* 1601 to 1970 is 369 years plus 89 leap days */
617 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
618 #define TICKSPERSEC 10000000
619 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
620 #define NANOSEC_PER_MILLISEC 1000000
621 #define MILLISEC_PER_SEC 1000
622 #define NANOSEC_PER_SEC (NANOSEC_PER_MILLISEC * MILLISEC_PER_SEC)
624 typedef int MSVCRT_long
;
632 /* _Xtime_get_ticks */
633 LONGLONG __cdecl
_Xtime_get_ticks(void)
639 GetSystemTimeAsFileTime(&ft
);
640 return ((LONGLONG
)ft
.dwHighDateTime
<<32) + ft
.dwLowDateTime
- TICKS_1601_TO_1970
;
644 int __cdecl
xtime_get(xtime
* t
, int unknown
)
653 ticks
= _Xtime_get_ticks();
654 t
->sec
= ticks
/ TICKSPERSEC
;
655 t
->nsec
= ticks
% TICKSPERSEC
* 100;
659 /* _Xtime_diff_to_millis2 */
660 MSVCRT_long __cdecl
_Xtime_diff_to_millis2(const xtime
*t1
, const xtime
*t2
)
662 LONGLONG diff_sec
, diff_nsec
;
664 TRACE("(%p, %p)\n", t1
, t2
);
666 diff_sec
= t1
->sec
- t2
->sec
;
667 diff_nsec
= t1
->nsec
- t2
->nsec
;
669 diff_sec
+= diff_nsec
/ NANOSEC_PER_SEC
;
670 diff_nsec
%= NANOSEC_PER_SEC
;
673 diff_nsec
+= NANOSEC_PER_SEC
;
676 if (diff_sec
<0 || (diff_sec
==0 && diff_nsec
<0))
678 return diff_sec
* MILLISEC_PER_SEC
+
679 (diff_nsec
+ NANOSEC_PER_MILLISEC
- 1) / NANOSEC_PER_MILLISEC
;
682 /* _Xtime_diff_to_millis */
683 MSVCRT_long __cdecl
_Xtime_diff_to_millis(const xtime
*t
)
690 return _Xtime_diff_to_millis2(t
, &now
);
695 unsigned int __cdecl
_Random_device(void)
701 /* TODO: throw correct exception in case of failure */
703 throw_exception("random number generator failed\n");
708 #if _MSVCP_VER >= 110
709 #ifdef __ASM_USE_THISCALL_WRAPPER
711 extern void *call_thiscall_func
;
712 __ASM_GLOBAL_FUNC(call_thiscall_func
,
719 #define call_func1(func,this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)(func,this)
723 #define call_func1(func,this) func(this)
725 #endif /* __i386__ */
727 #define MTX_PLAIN 0x1
729 #define MTX_TIMED 0x4
730 #define MTX_RECURSIVE 0x100
740 #if _MSVCP_VER >= 140
741 typedef _Mtx_t _Mtx_arg_t
;
742 #define MTX_T_FROM_ARG(m) (m)
743 #define MTX_T_TO_ARG(m) (m)
745 typedef _Mtx_t
*_Mtx_arg_t
;
746 #define MTX_T_FROM_ARG(m) (*(m))
747 #define MTX_T_TO_ARG(m) (&(m))
750 void __cdecl
_Mtx_init_in_situ(_Mtx_t mtx
, int flags
)
752 if(flags
& ~(MTX_PLAIN
| MTX_TRY
| MTX_TIMED
| MTX_RECURSIVE
))
753 FIXME("unknown flags ignored: %x\n", flags
);
756 call_func1(critical_section_ctor
, &mtx
->cs
);
761 int __cdecl
_Mtx_init(_Mtx_t
*mtx
, int flags
)
763 *mtx
= operator_new(sizeof(**mtx
));
764 _Mtx_init_in_situ(*mtx
, flags
);
768 void __cdecl
_Mtx_destroy_in_situ(_Mtx_t mtx
)
770 call_func1(critical_section_dtor
, &mtx
->cs
);
773 void __cdecl
_Mtx_destroy(_Mtx_arg_t mtx
)
775 call_func1(critical_section_dtor
, &MTX_T_FROM_ARG(mtx
)->cs
);
776 operator_delete(MTX_T_FROM_ARG(mtx
));
779 int __cdecl
_Mtx_current_owns(_Mtx_arg_t mtx
)
781 return MTX_T_FROM_ARG(mtx
)->thread_id
== GetCurrentThreadId();
784 int __cdecl
_Mtx_lock(_Mtx_arg_t mtx
)
786 if(MTX_T_FROM_ARG(mtx
)->thread_id
!= GetCurrentThreadId()) {
787 call_func1(critical_section_lock
, &MTX_T_FROM_ARG(mtx
)->cs
);
788 MTX_T_FROM_ARG(mtx
)->thread_id
= GetCurrentThreadId();
789 }else if(!(MTX_T_FROM_ARG(mtx
)->flags
& MTX_RECURSIVE
)
790 && MTX_T_FROM_ARG(mtx
)->flags
!= MTX_PLAIN
) {
794 MTX_T_FROM_ARG(mtx
)->count
++;
798 int __cdecl
_Mtx_unlock(_Mtx_arg_t mtx
)
800 if(--MTX_T_FROM_ARG(mtx
)->count
)
803 MTX_T_FROM_ARG(mtx
)->thread_id
= -1;
804 call_func1(critical_section_unlock
, &MTX_T_FROM_ARG(mtx
)->cs
);
808 int __cdecl
_Mtx_trylock(_Mtx_arg_t mtx
)
810 if(MTX_T_FROM_ARG(mtx
)->thread_id
!= GetCurrentThreadId()) {
811 if(!call_func1(critical_section_trylock
, &MTX_T_FROM_ARG(mtx
)->cs
))
813 MTX_T_FROM_ARG(mtx
)->thread_id
= GetCurrentThreadId();
814 }else if(!(MTX_T_FROM_ARG(mtx
)->flags
& MTX_RECURSIVE
)
815 && MTX_T_FROM_ARG(mtx
)->flags
!= MTX_PLAIN
) {
819 MTX_T_FROM_ARG(mtx
)->count
++;
823 critical_section
* __cdecl
_Mtx_getconcrtcs(_Mtx_arg_t mtx
)
825 return &MTX_T_FROM_ARG(mtx
)->cs
;
828 static inline LONG
interlocked_dec_if_nonzero( LONG
*dest
)
831 for (val
= *dest
;; val
= tmp
)
833 if (!val
|| (tmp
= InterlockedCompareExchange( dest
, val
- 1, val
)) == val
)
839 #define CND_TIMEDOUT 2
843 CONDITION_VARIABLE cv
;
846 #if _MSVCP_VER >= 140
847 typedef _Cnd_t _Cnd_arg_t
;
848 #define CND_T_FROM_ARG(c) (c)
849 #define CND_T_TO_ARG(c) (c)
851 typedef _Cnd_t
*_Cnd_arg_t
;
852 #define CND_T_FROM_ARG(c) (*(c))
853 #define CND_T_TO_ARG(c) (&(c))
856 static HANDLE keyed_event
;
858 void __cdecl
_Cnd_init_in_situ(_Cnd_t cnd
)
860 InitializeConditionVariable(&cnd
->cv
);
865 NtCreateKeyedEvent(&event
, GENERIC_READ
|GENERIC_WRITE
, NULL
, 0);
866 if(InterlockedCompareExchangePointer(&keyed_event
, event
, NULL
) != NULL
)
871 int __cdecl
_Cnd_init(_Cnd_t
*cnd
)
873 *cnd
= operator_new(sizeof(**cnd
));
874 _Cnd_init_in_situ(*cnd
);
878 int __cdecl
_Cnd_wait(_Cnd_arg_t cnd
, _Mtx_arg_t mtx
)
880 CONDITION_VARIABLE
*cv
= &CND_T_FROM_ARG(cnd
)->cv
;
882 InterlockedExchangeAdd( (LONG
*)&cv
->Ptr
, 1 );
885 NtWaitForKeyedEvent(keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
891 int __cdecl
_Cnd_timedwait(_Cnd_arg_t cnd
, _Mtx_arg_t mtx
, const xtime
*xt
)
893 CONDITION_VARIABLE
*cv
= &CND_T_FROM_ARG(cnd
)->cv
;
894 LARGE_INTEGER timeout
;
897 InterlockedExchangeAdd( (LONG
*)&cv
->Ptr
, 1 );
900 timeout
.QuadPart
= (ULONGLONG
)(ULONG
)_Xtime_diff_to_millis(xt
) * -10000;
901 status
= NtWaitForKeyedEvent(keyed_event
, &cv
->Ptr
, FALSE
, &timeout
);
904 if (!interlocked_dec_if_nonzero( (LONG
*)&cv
->Ptr
))
905 status
= NtWaitForKeyedEvent( keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
909 return status
? CND_TIMEDOUT
: 0;
912 int __cdecl
_Cnd_broadcast(_Cnd_arg_t cnd
)
914 CONDITION_VARIABLE
*cv
= &CND_T_FROM_ARG(cnd
)->cv
;
915 LONG val
= InterlockedExchange( (LONG
*)&cv
->Ptr
, 0 );
917 NtReleaseKeyedEvent( keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
921 int __cdecl
_Cnd_signal(_Cnd_arg_t cnd
)
923 CONDITION_VARIABLE
*cv
= &CND_T_FROM_ARG(cnd
)->cv
;
924 if (interlocked_dec_if_nonzero( (LONG
*)&cv
->Ptr
))
925 NtReleaseKeyedEvent( keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
929 void __cdecl
_Cnd_destroy_in_situ(_Cnd_t cnd
)
931 _Cnd_broadcast(CND_T_TO_ARG(cnd
));
934 void __cdecl
_Cnd_destroy(_Cnd_arg_t cnd
)
938 operator_delete(CND_T_FROM_ARG(cnd
));
946 struct _to_broadcast
{
952 } broadcast_at_thread_exit
;
954 static CRITICAL_SECTION broadcast_at_thread_exit_cs
;
955 static CRITICAL_SECTION_DEBUG broadcast_at_thread_exit_cs_debug
=
957 0, 0, &broadcast_at_thread_exit_cs
,
958 { &broadcast_at_thread_exit_cs_debug
.ProcessLocksList
, &broadcast_at_thread_exit_cs_debug
.ProcessLocksList
},
959 0, 0, { (DWORD_PTR
)(__FILE__
": broadcast_at_thread_exit_cs") }
961 static CRITICAL_SECTION broadcast_at_thread_exit_cs
= { &broadcast_at_thread_exit_cs_debug
, -1, 0, 0, 0, 0 };
963 void __cdecl
_Cnd_register_at_thread_exit(_Cnd_arg_t cnd
, _Mtx_arg_t mtx
, int *p
)
965 struct _to_broadcast
*add
;
967 TRACE("(%p %p %p)\n", cnd
, mtx
, p
);
969 EnterCriticalSection(&broadcast_at_thread_exit_cs
);
970 if(!broadcast_at_thread_exit
.size
) {
971 broadcast_at_thread_exit
.to_broadcast
= HeapAlloc(GetProcessHeap(),
972 0, 8*sizeof(broadcast_at_thread_exit
.to_broadcast
[0]));
973 if(!broadcast_at_thread_exit
.to_broadcast
) {
974 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
977 broadcast_at_thread_exit
.size
= 8;
978 } else if(broadcast_at_thread_exit
.size
== broadcast_at_thread_exit
.used
) {
979 add
= HeapReAlloc(GetProcessHeap(), 0, broadcast_at_thread_exit
.to_broadcast
,
980 broadcast_at_thread_exit
.size
*2*sizeof(broadcast_at_thread_exit
.to_broadcast
[0]));
982 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
985 broadcast_at_thread_exit
.to_broadcast
= add
;
986 broadcast_at_thread_exit
.size
*= 2;
989 add
= broadcast_at_thread_exit
.to_broadcast
+ broadcast_at_thread_exit
.used
++;
990 add
->thread_id
= GetCurrentThreadId();
994 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
997 void __cdecl
_Cnd_unregister_at_thread_exit(_Mtx_arg_t mtx
)
1001 TRACE("(%p)\n", mtx
);
1003 EnterCriticalSection(&broadcast_at_thread_exit_cs
);
1004 for(i
=0; i
<broadcast_at_thread_exit
.used
; i
++) {
1005 if(broadcast_at_thread_exit
.to_broadcast
[i
].mtx
!= mtx
)
1008 memmove(broadcast_at_thread_exit
.to_broadcast
+i
, broadcast_at_thread_exit
.to_broadcast
+i
+1,
1009 (broadcast_at_thread_exit
.used
-i
-1)*sizeof(broadcast_at_thread_exit
.to_broadcast
[0]));
1010 broadcast_at_thread_exit
.used
--;
1013 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
1016 void __cdecl
_Cnd_do_broadcast_at_thread_exit(void)
1018 int i
, id
= GetCurrentThreadId();
1022 EnterCriticalSection(&broadcast_at_thread_exit_cs
);
1023 for(i
=0; i
<broadcast_at_thread_exit
.used
; i
++) {
1024 if(broadcast_at_thread_exit
.to_broadcast
[i
].thread_id
!= id
)
1027 _Mtx_unlock(broadcast_at_thread_exit
.to_broadcast
[i
].mtx
);
1028 _Cnd_broadcast(broadcast_at_thread_exit
.to_broadcast
[i
].cnd
);
1029 if(broadcast_at_thread_exit
.to_broadcast
[i
].p
)
1030 *broadcast_at_thread_exit
.to_broadcast
[i
].p
= 1;
1032 memmove(broadcast_at_thread_exit
.to_broadcast
+i
, broadcast_at_thread_exit
.to_broadcast
+i
+1,
1033 (broadcast_at_thread_exit
.used
-i
-1)*sizeof(broadcast_at_thread_exit
.to_broadcast
[0]));
1034 broadcast_at_thread_exit
.used
--;
1037 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
1042 #if _MSVCP_VER == 100
1044 const vtable_ptr
*vtable
;
1048 error_category base
;
1051 static custom_category iostream_category
;
1053 DEFINE_RTTI_DATA0(error_category
, 0, ".?AVerror_category@std@@")
1054 DEFINE_RTTI_DATA1(iostream_category
, 0, &error_category_rtti_base_descriptor
, ".?AV_Iostream_error_category@std@@")
1056 extern const vtable_ptr iostream_category_vtable
;
1058 static void iostream_category_ctor(custom_category
*this)
1060 this->base
.vtable
= &iostream_category_vtable
;
1061 this->type
= "iostream";
1064 DEFINE_THISCALL_WRAPPER(custom_category_vector_dtor
, 8)
1065 custom_category
* __thiscall
custom_category_vector_dtor(custom_category
*this, unsigned int flags
)
1067 TRACE("(%p %x)\n", this, flags
);
1069 /* we have an array, with the number of elements stored before the first object */
1070 INT_PTR i
, *ptr
= (INT_PTR
*)this-1;
1072 for(i
=*ptr
-1; i
>=0; i
--)
1073 operator_delete(ptr
);
1076 operator_delete(this);
1082 DEFINE_THISCALL_WRAPPER(custom_category_name
, 4)
1083 const char* __thiscall
custom_category_name(const custom_category
*this)
1088 DEFINE_THISCALL_WRAPPER(custom_category_message
, 12)
1089 basic_string_char
* __thiscall
custom_category_message(const custom_category
*this,
1090 basic_string_char
*ret
, int err
)
1092 return MSVCP_basic_string_char_ctor_cstr(ret
, strerror(err
));
1095 DEFINE_THISCALL_WRAPPER(custom_category_default_error_condition
, 12)
1096 /*error_condition*/void* __thiscall
custom_category_default_error_condition(
1097 custom_category
*this, /*error_condition*/void *ret
, int code
)
1099 FIXME("(%p %p %x) stub\n", this, ret
, code
);
1103 DEFINE_THISCALL_WRAPPER(custom_category_equivalent
, 12)
1104 bool __thiscall
custom_category_equivalent(const custom_category
*this,
1105 int code
, const /*error_condition*/void *condition
)
1107 FIXME("(%p %x %p) stub\n", this, code
, condition
);
1111 DEFINE_THISCALL_WRAPPER(custom_category_equivalent_code
, 12)
1112 bool __thiscall
custom_category_equivalent_code(custom_category
*this,
1113 const /*error_code*/void *code
, int condition
)
1115 FIXME("(%p %p %x) stub\n", this, code
, condition
);
1119 DEFINE_THISCALL_WRAPPER(iostream_category_message
, 12)
1120 basic_string_char
* __thiscall
iostream_category_message(const custom_category
*this,
1121 basic_string_char
*ret
, int err
)
1123 if(err
== 1) return MSVCP_basic_string_char_ctor_cstr(ret
, "iostream error");
1124 return MSVCP_basic_string_char_ctor_cstr(ret
, strerror(err
));
1127 /* ?iostream_category@std@@YAABVerror_category@1@XZ */
1128 /* ?iostream_category@std@@YAAEBVerror_category@1@XZ */
1129 const error_category
* __cdecl
std_iostream_category(void)
1132 return &iostream_category
.base
;
1135 static custom_category system_category
;
1136 DEFINE_RTTI_DATA1(system_category
, 0, &error_category_rtti_base_descriptor
, ".?AV_System_error_category@std@@")
1138 extern const vtable_ptr system_category_vtable
;
1140 static void system_category_ctor(custom_category
*this)
1142 this->base
.vtable
= &system_category_vtable
;
1143 this->type
= "system";
1146 /* ?system_category@std@@YAABVerror_category@1@XZ */
1147 /* ?system_category@std@@YAAEBVerror_category@1@XZ */
1148 const error_category
* __cdecl
std_system_category(void)
1151 return &system_category
.base
;
1154 static custom_category generic_category
;
1155 DEFINE_RTTI_DATA1(generic_category
, 0, &error_category_rtti_base_descriptor
, ".?AV_Generic_error_category@std@@")
1157 extern const vtable_ptr generic_category_vtable
;
1159 static void generic_category_ctor(custom_category
*this)
1161 this->base
.vtable
= &generic_category_vtable
;
1162 this->type
= "generic";
1165 /* ?generic_category@std@@YAABVerror_category@1@XZ */
1166 /* ?generic_category@std@@YAAEBVerror_category@1@XZ */
1167 const error_category
* __cdecl
std_generic_category(void)
1170 return &generic_category
.base
;
1174 #if _MSVCP_VER >= 110
1175 static CRITICAL_SECTION call_once_cs
;
1176 static CRITICAL_SECTION_DEBUG call_once_cs_debug
=
1178 0, 0, &call_once_cs
,
1179 { &call_once_cs_debug
.ProcessLocksList
, &call_once_cs_debug
.ProcessLocksList
},
1180 0, 0, { (DWORD_PTR
)(__FILE__
": call_once_cs") }
1182 static CRITICAL_SECTION call_once_cs
= { &call_once_cs_debug
, -1, 0, 0, 0, 0 };
1184 void __cdecl
_Call_onceEx(int *once
, void (__cdecl
*func
)(void*), void *argv
)
1186 TRACE("%p %p %p\n", once
, func
, argv
);
1188 EnterCriticalSection(&call_once_cs
);
1190 /* FIXME: handle exceptions */
1194 LeaveCriticalSection(&call_once_cs
);
1197 static void __cdecl
call_once_func_wrapper(void *func
)
1199 ((void (__cdecl
*)(void))func
)();
1202 void __cdecl
_Call_once(int *once
, void (__cdecl
*func
)(void))
1204 TRACE("%p %p\n", once
, func
);
1205 _Call_onceEx(once
, call_once_func_wrapper
, func
);
1208 void __cdecl
_Do_call(void *this)
1210 CALL_VTBL_FUNC(this, 0, void, (void*), (this));
1214 #if _MSVCP_VER >= 110
1221 typedef int (__cdecl
*_Thrd_start_t
)(void*);
1223 #define _THRD_ERROR 4
1225 int __cdecl
_Thrd_equal(_Thrd_t a
, _Thrd_t b
)
1227 TRACE("(%p %u %p %u)\n", a
.hnd
, a
.id
, b
.hnd
, b
.id
);
1228 return a
.id
== b
.id
;
1231 int __cdecl
_Thrd_lt(_Thrd_t a
, _Thrd_t b
)
1233 TRACE("(%p %u %p %u)\n", a
.hnd
, a
.id
, b
.hnd
, b
.id
);
1237 void __cdecl
_Thrd_sleep(const xtime
*t
)
1240 Sleep(_Xtime_diff_to_millis(t
));
1243 void __cdecl
_Thrd_yield(void)
1249 static _Thrd_t
thread_current(void)
1253 if(DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
1254 GetCurrentProcess(), &ret
.hnd
, 0, FALSE
, DUPLICATE_SAME_ACCESS
)) {
1255 CloseHandle(ret
.hnd
);
1259 ret
.id
= GetCurrentThreadId();
1261 TRACE("(%p %u)\n", ret
.hnd
, ret
.id
);
1266 _Thrd_t __cdecl
_Thrd_current(void)
1268 return thread_current();
1271 ULONGLONG __cdecl
_Thrd_current(void)
1278 C_ASSERT(sizeof(_Thrd_t
) <= sizeof(ULONGLONG
));
1280 ret
.thr
= thread_current();
1285 int __cdecl
_Thrd_join(_Thrd_t thr
, int *code
)
1287 TRACE("(%p %u %p)\n", thr
.hnd
, thr
.id
, code
);
1288 if (WaitForSingleObject(thr
.hnd
, INFINITE
))
1292 GetExitCodeThread(thr
.hnd
, (DWORD
*)code
);
1294 CloseHandle(thr
.hnd
);
1298 int __cdecl
_Thrd_start(_Thrd_t
*thr
, LPTHREAD_START_ROUTINE proc
, void *arg
)
1300 TRACE("(%p %p %p)\n", thr
, proc
, arg
);
1301 thr
->hnd
= CreateThread(NULL
, 0, proc
, arg
, 0, &thr
->id
);
1302 return thr
->hnd
? 0 : _THRD_ERROR
;
1311 static DWORD WINAPI
thread_proc_wrapper(void *arg
)
1313 thread_proc_arg wrapped_arg
= *((thread_proc_arg
*)arg
);
1315 return wrapped_arg
.proc(wrapped_arg
.arg
);
1318 int __cdecl
_Thrd_create(_Thrd_t
*thr
, _Thrd_start_t proc
, void *arg
)
1320 thread_proc_arg
*wrapped_arg
;
1323 TRACE("(%p %p %p)\n", thr
, proc
, arg
);
1325 wrapped_arg
= malloc(sizeof(*wrapped_arg
));
1327 return _THRD_ERROR
; /* TODO: probably different error should be returned here */
1329 wrapped_arg
->proc
= proc
;
1330 wrapped_arg
->arg
= arg
;
1331 ret
= _Thrd_start(thr
, thread_proc_wrapper
, wrapped_arg
);
1332 if(ret
) free(wrapped_arg
);
1336 int __cdecl
_Thrd_detach(_Thrd_t thr
)
1338 return CloseHandle(thr
.hnd
) ? 0 : _THRD_ERROR
;
1343 const vtable_ptr
*vtable
;
1349 DEFINE_RTTI_DATA0(_Pad
, 0, ".?AV_Pad@std@@")
1351 /* ??_7_Pad@std@@6B@ */
1352 extern const vtable_ptr _Pad_vtable
;
1354 unsigned int __cdecl
_Thrd_hardware_concurrency(void)
1356 static unsigned int val
= -1;
1364 val
= si
.dwNumberOfProcessors
;
1370 unsigned int __cdecl
_Thrd_id(void)
1373 return GetCurrentThreadId();
1376 /* ??0_Pad@std@@QAE@XZ */
1377 /* ??0_Pad@std@@QEAA@XZ */
1378 DEFINE_THISCALL_WRAPPER(_Pad_ctor
, 4)
1379 _Pad
* __thiscall
_Pad_ctor(_Pad
*this)
1381 TRACE("(%p)\n", this);
1383 this->vtable
= &_Pad_vtable
;
1384 _Cnd_init(&this->cnd
);
1385 _Mtx_init(&this->mtx
, 0);
1386 this->launched
= FALSE
;
1387 _Mtx_lock(MTX_T_TO_ARG(this->mtx
));
1391 /* ??4_Pad@std@@QAEAAV01@ABV01@@Z */
1392 /* ??4_Pad@std@@QEAAAEAV01@AEBV01@@Z */
1393 DEFINE_THISCALL_WRAPPER(_Pad_op_assign
, 8)
1394 _Pad
* __thiscall
_Pad_op_assign(_Pad
*this, const _Pad
*copy
)
1396 TRACE("(%p %p)\n", this, copy
);
1398 this->cnd
= copy
->cnd
;
1399 this->mtx
= copy
->mtx
;
1400 this->launched
= copy
->launched
;
1404 /* ??0_Pad@std@@QAE@ABV01@@Z */
1405 /* ??0_Pad@std@@QEAA@AEBV01@@Z */
1406 DEFINE_THISCALL_WRAPPER(_Pad_copy_ctor
, 8)
1407 _Pad
* __thiscall
_Pad_copy_ctor(_Pad
*this, const _Pad
*copy
)
1409 TRACE("(%p %p)\n", this, copy
);
1411 this->vtable
= &_Pad_vtable
;
1412 return _Pad_op_assign(this, copy
);
1415 /* ??1_Pad@std@@QAE@XZ */
1416 /* ??1_Pad@std@@QEAA@XZ */
1417 DEFINE_THISCALL_WRAPPER(_Pad_dtor
, 4)
1418 void __thiscall
_Pad_dtor(_Pad
*this)
1420 TRACE("(%p)\n", this);
1422 _Mtx_unlock(MTX_T_TO_ARG(this->mtx
));
1423 _Mtx_destroy(MTX_T_TO_ARG(this->mtx
));
1424 _Cnd_destroy(CND_T_TO_ARG(this->cnd
));
1427 DEFINE_THISCALL_WRAPPER(_Pad__Go
, 4)
1428 #define call__Pad__Go(this) CALL_VTBL_FUNC(this, 0, unsigned int, (_Pad*), (this))
1429 unsigned int __thiscall
_Pad__Go(_Pad
*this)
1431 ERR("(%p) should not be called\n", this);
1435 static DWORD WINAPI
launch_thread_proc(void *arg
)
1438 return call__Pad__Go(this);
1441 /* ?_Launch@_Pad@std@@QAEXPAU_Thrd_imp_t@@@Z */
1442 /* ?_Launch@_Pad@std@@QEAAXPEAU_Thrd_imp_t@@@Z */
1443 DEFINE_THISCALL_WRAPPER(_Pad__Launch
, 8)
1444 void __thiscall
_Pad__Launch(_Pad
*this, _Thrd_t
*thr
)
1446 TRACE("(%p %p)\n", this, thr
);
1448 _Thrd_start(thr
, launch_thread_proc
, this);
1449 _Cnd_wait(CND_T_TO_ARG(this->cnd
), MTX_T_TO_ARG(this->mtx
));
1452 /* ?_Release@_Pad@std@@QAEXXZ */
1453 /* ?_Release@_Pad@std@@QEAAXXZ */
1454 DEFINE_THISCALL_WRAPPER(_Pad__Release
, 4)
1455 void __thiscall
_Pad__Release(_Pad
*this)
1457 TRACE("(%p)\n", this);
1459 _Mtx_lock(MTX_T_TO_ARG(this->mtx
));
1460 this->launched
= TRUE
;
1461 _Cnd_signal(CND_T_TO_ARG(this->cnd
));
1462 _Mtx_unlock(MTX_T_TO_ARG(this->mtx
));
1466 /*********************************************************************
1467 * __crtInitializeCriticalSectionEx (MSVCP140.@)
1469 BOOL CDECL
MSVCP__crtInitializeCriticalSectionEx(
1470 CRITICAL_SECTION
*cs
, DWORD spin_count
, DWORD flags
)
1472 TRACE("(%p %x %x)\n", cs
, spin_count
, flags
);
1473 return InitializeCriticalSectionEx(cs
, spin_count
, flags
);
1476 /*********************************************************************
1477 * __crtCreateEventExW (MSVCP140.@)
1479 HANDLE CDECL
MSVCP__crtCreateEventExW(
1480 SECURITY_ATTRIBUTES
*attribs
, LPCWSTR name
, DWORD flags
, DWORD access
)
1482 TRACE("(%p %s 0x%08x 0x%08x)\n", attribs
, debugstr_w(name
), flags
, access
);
1483 return CreateEventExW(attribs
, name
, flags
, access
);
1486 /*********************************************************************
1487 * __crtGetTickCount64 (MSVCP140.@)
1489 ULONGLONG CDECL
MSVCP__crtGetTickCount64(void)
1491 return GetTickCount64();
1494 /*********************************************************************
1495 * __crtGetCurrentProcessorNumber (MSVCP140.@)
1497 DWORD CDECL
MSVCP__crtGetCurrentProcessorNumber(void)
1499 return GetCurrentProcessorNumber();
1502 /*********************************************************************
1503 * __crtFlushProcessWriteBuffers (MSVCP140.@)
1505 VOID CDECL
MSVCP__crtFlushProcessWriteBuffers(void)
1507 return FlushProcessWriteBuffers();
1510 /*********************************************************************
1511 * __crtCreateSemaphoreExW (MSVCP140.@)
1513 HANDLE CDECL
MSVCP__crtCreateSemaphoreExW(
1514 SECURITY_ATTRIBUTES
*attribs
, LONG initial_count
, LONG max_count
, LPCWSTR name
,
1515 DWORD flags
, DWORD access
)
1517 TRACE("(%p %d %d %s 0x%08x 0x%08x)\n", attribs
, initial_count
, max_count
, debugstr_w(name
),
1519 return CreateSemaphoreExW(attribs
, initial_count
, max_count
, name
, flags
, access
);
1522 /*********************************************************************
1523 * __crtCreateThreadpoolTimer (MSVCP140.@)
1525 PTP_TIMER CDECL
MSVCP__crtCreateThreadpoolTimer(PTP_TIMER_CALLBACK callback
,
1526 PVOID userdata
, TP_CALLBACK_ENVIRON
*environment
)
1528 TRACE("(%p %p %p)\n", callback
, userdata
, environment
);
1529 return CreateThreadpoolTimer(callback
, userdata
, environment
);
1532 /*********************************************************************
1533 * __crtCloseThreadpoolTimer (MSVCP140.@)
1535 VOID CDECL
MSVCP__crtCloseThreadpoolTimer(TP_TIMER
*timer
)
1537 TRACE("(%p)\n", timer
);
1538 CloseThreadpoolTimer(timer
);
1541 /*********************************************************************
1542 * __crtSetThreadpoolTimer (MSVCP140.@)
1544 VOID CDECL
MSVCP__crtSetThreadpoolTimer(TP_TIMER
*timer
,
1545 FILETIME
*due_time
, DWORD period
, DWORD window_length
)
1547 TRACE("(%p %p 0x%08x 0x%08x)\n", timer
, due_time
, period
, window_length
);
1548 return SetThreadpoolTimer(timer
, due_time
, period
, window_length
);
1551 /*********************************************************************
1552 * __crtWaitForThreadpoolTimerCallbacks (MSVCP140.@)
1554 VOID CDECL
MSVCP__crtWaitForThreadpoolTimerCallbacks(TP_TIMER
*timer
, BOOL cancel
)
1556 TRACE("(%p %d)\n", timer
, cancel
);
1557 WaitForThreadpoolTimerCallbacks(timer
, cancel
);
1560 /*********************************************************************
1561 * __crtCreateThreadpoolWait (MSVCP140.@)
1563 PTP_WAIT CDECL
MSVCP__crtCreateThreadpoolWait(PTP_WAIT_CALLBACK callback
,
1564 PVOID userdata
, TP_CALLBACK_ENVIRON
*environment
)
1566 TRACE("(%p %p %p)\n", callback
, userdata
, environment
);
1567 return CreateThreadpoolWait(callback
, userdata
, environment
);
1570 /*********************************************************************
1571 * __crtCloseThreadpoolWait (MSVCP140.@)
1573 VOID CDECL
MSVCP__crtCloseThreadpoolWait(TP_WAIT
*wait
)
1575 TRACE("(%p)\n", wait
);
1576 CloseThreadpoolWait(wait
);
1579 /*********************************************************************
1580 * __crtSetThreadpoolWait (MSVCP140.@)
1582 VOID CDECL
MSVCP__crtSetThreadpoolWait(TP_WAIT
*wait
, HANDLE handle
, FILETIME
*due_time
)
1584 TRACE("(%p %p %p)\n", wait
, handle
, due_time
);
1585 return SetThreadpoolWait(wait
, handle
, due_time
);
1588 /*********************************************************************
1589 * __crtFreeLibraryWhenCallbackReturns (MSVCP140.@)
1591 VOID CDECL
MSVCP__crtFreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE instance
, HMODULE mod
)
1593 TRACE("(%p %p)\n", instance
, mod
);
1594 FreeLibraryWhenCallbackReturns(instance
, mod
);
1597 /* ?_Execute_once@std@@YAHAAUonce_flag@1@P6GHPAX1PAPAX@Z1@Z */
1598 /* ?_Execute_once@std@@YAHAEAUonce_flag@1@P6AHPEAX1PEAPEAX@Z1@Z */
1599 BOOL __cdecl
_Execute_once(INIT_ONCE
*flag
, PINIT_ONCE_FN func
, void *param
)
1601 return InitOnceExecuteOnce(flag
, func
, param
, NULL
);
1604 #if _MSVCP_VER >= 140
1605 LONGLONG __cdecl
_Query_perf_counter(void)
1608 QueryPerformanceCounter(&li
);
1612 LONGLONG __cdecl
_Query_perf_frequency(void)
1615 QueryPerformanceFrequency(&li
);
1620 void __cdecl
threads__Mtx_new(void **mtx
)
1622 *mtx
= operator_new(sizeof(CRITICAL_SECTION
));
1623 InitializeCriticalSection(*mtx
);
1626 void __cdecl
threads__Mtx_delete(void *mtx
)
1628 DeleteCriticalSection(mtx
);
1631 void __cdecl
threads__Mtx_lock(void *mtx
)
1633 EnterCriticalSection(mtx
);
1636 void __cdecl
threads__Mtx_unlock(void *mtx
)
1638 LeaveCriticalSection(mtx
);
1641 #if _MSVCP_VER >= 110
1642 static LONG shared_ptr_lock
;
1644 void __cdecl
_Lock_shared_ptr_spin_lock(void)
1648 while(InterlockedCompareExchange(&shared_ptr_lock
, 1, 0) != 0) {
1656 void __cdecl
_Unlock_shared_ptr_spin_lock(void)
1658 shared_ptr_lock
= 0;
1662 #if _MSVCP_VER >= 110 && _MSVCP_VER <= 120
1667 /* ?_1@placeholders@std@@3V?$_Ph@$00@2@A */
1668 /* ?_20@placeholders@std@@3V?$_Ph@$0BE@@2@A */
1669 _Ph _Ph_1
= {0}, _Ph_2
= {0}, _Ph_3
= {0}, _Ph_4
= {0}, _Ph_5
= {0};
1670 _Ph _Ph_6
= {0}, _Ph_7
= {0}, _Ph_8
= {0}, _Ph_9
= {0}, _Ph_10
= {0};
1671 _Ph _Ph_11
= {0}, _Ph_12
= {0}, _Ph_13
= {0}, _Ph_14
= {0}, _Ph_15
= {0};
1672 _Ph _Ph_16
= {0}, _Ph_17
= {0}, _Ph_18
= {0}, _Ph_19
= {0}, _Ph_20
= {0};
1675 #if _MSVCP_VER >= 110
1676 /* ?_Syserror_map@std@@YAPBDH@Z */
1677 /* ?_Syserror_map@std@@YAPEBDH@Z */
1678 const char* __cdecl
_Syserror_map(int err
)
1682 TRACE("(%d)\n", err
);
1684 for(i
= 0; i
< ARRAY_SIZE(syserror_map
); i
++)
1686 if(syserror_map
[i
].err
== err
)
1687 return syserror_map
[i
].str
;
1689 #if _MSVCP_VER >= 140
1690 return "unknown error";
1697 #if _MSVCP_VER >= 140
1698 /* ?_Winerror_message@std@@YAKKPADK@Z */
1699 /* ?_Winerror_message@std@@YAKKPEADK@Z */
1700 ULONG __cdecl
_Winerror_message(ULONG err
, char *buf
, ULONG size
)
1702 TRACE("(%u %p %u)\n", err
, buf
, size
);
1704 return FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
,
1705 NULL
, err
, 0, buf
, size
, NULL
);
1708 /* ?_Winerror_map@std@@YAHH@Z */
1709 int __cdecl
_Winerror_map(int err
)
1711 int low
= 0, high
= ARRAY_SIZE(winerror_map
) - 1, mid
;
1715 mid
= (low
+ high
) / 2;
1717 if(err
== winerror_map
[mid
].winerr
)
1718 return winerror_map
[mid
].doserr
;
1719 if(err
> winerror_map
[mid
].winerr
)
1729 #if _MSVCP_VER >= 100
1730 __ASM_BLOCK_BEGIN(misc_vtables
)
1731 #if _MSVCP_VER == 100
1732 __ASM_VTABLE(iostream_category
,
1733 VTABLE_ADD_FUNC(custom_category_vector_dtor
)
1734 VTABLE_ADD_FUNC(custom_category_name
)
1735 VTABLE_ADD_FUNC(iostream_category_message
)
1736 VTABLE_ADD_FUNC(custom_category_default_error_condition
)
1737 VTABLE_ADD_FUNC(custom_category_equivalent
)
1738 VTABLE_ADD_FUNC(custom_category_equivalent_code
));
1739 __ASM_VTABLE(system_category
,
1740 VTABLE_ADD_FUNC(custom_category_vector_dtor
)
1741 VTABLE_ADD_FUNC(custom_category_name
)
1742 VTABLE_ADD_FUNC(custom_category_message
)
1743 VTABLE_ADD_FUNC(custom_category_default_error_condition
)
1744 VTABLE_ADD_FUNC(custom_category_equivalent
)
1745 VTABLE_ADD_FUNC(custom_category_equivalent_code
));
1746 __ASM_VTABLE(generic_category
,
1747 VTABLE_ADD_FUNC(custom_category_vector_dtor
)
1748 VTABLE_ADD_FUNC(custom_category_name
)
1749 VTABLE_ADD_FUNC(custom_category_message
)
1750 VTABLE_ADD_FUNC(custom_category_default_error_condition
)
1751 VTABLE_ADD_FUNC(custom_category_equivalent
)
1752 VTABLE_ADD_FUNC(custom_category_equivalent_code
));
1754 #if _MSVCP_VER >= 110
1756 VTABLE_ADD_FUNC(_Pad__Go
));
1760 void init_misc(void *base
)
1763 #if _MSVCP_VER == 100
1764 init_error_category_rtti(base
);
1765 init_iostream_category_rtti(base
);
1766 init_system_category_rtti(base
);
1767 init_generic_category_rtti(base
);
1769 #if _MSVCP_VER >= 110
1770 init__Pad_rtti(base
);
1774 #if _MSVCP_VER == 100
1775 iostream_category_ctor(&iostream_category
);
1776 system_category_ctor(&system_category
);
1777 generic_category_ctor(&generic_category
);
1781 void free_misc(void)
1783 #if _MSVCP_VER >= 110
1785 NtClose(keyed_event
);
1786 HeapFree(GetProcessHeap(), 0, broadcast_at_thread_exit
.to_broadcast
);