wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / msvcp90 / misc.c
blobf70de9e560014031f1a6ef83a6df9eee01d2bcbf
1 /*
2 * Copyright 2010 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <limits.h>
21 #include <errno.h>
23 #include "msvcp90.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winternl.h"
28 #include "wine/debug.h"
29 #include "wine/exception.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
32 #if _MSVCP_VER >= 110
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 {
114 int err;
115 const char *str;
116 } syserror_map[] =
118 {EPERM, str_EPERM},
119 {ENOENT, str_ENOENT},
120 {ESRCH, str_ESRCH},
121 {EINTR, str_EINTR},
122 {EIO, str_EIO},
123 {ENXIO, str_ENXIO},
124 {E2BIG, str_E2BIG},
125 {ENOEXEC, str_ENOEXEC},
126 {EBADF, str_EBADF},
127 {ECHILD, str_ECHILD},
128 {EAGAIN, str_EAGAIN},
129 {ENOMEM, str_ENOMEM},
130 {EACCES, str_EACCES},
131 {EFAULT, str_EFAULT},
132 {EBUSY, str_EBUSY},
133 {EEXIST, str_EEXIST},
134 {EXDEV, str_EXDEV},
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},
142 {EFBIG, str_EFBIG},
143 {ENOSPC, str_ENOSPC},
144 {ESPIPE, str_ESPIPE},
145 {EROFS, str_EROFS},
146 {EMLINK, str_EMLINK},
147 {EPIPE, str_EPIPE},
148 {EDOM, str_EDOM},
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},
167 {EIDRM, str_EIDRM},
168 {EINPROGRESS, str_EINPROGRESS},
169 {EISCONN, str_EISCONN},
170 {ELOOP, str_ELOOP},
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},
180 {ENOSR, str_ENOSR},
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},
192 {ETIME, str_ETIME},
193 {ETIMEDOUT, str_ETIMEDOUT},
194 {ETXTBSY, str_ETXTBSY},
195 {EWOULDBLOCK, str_EWOULDBLOCK},
197 #endif
199 #if _MSVCP_VER >= 140
200 static const struct {
201 int winerr;
202 int doserr;
203 } winerror_map[] =
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, EINVAL}, {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}
242 #endif
244 struct __Container_proxy;
246 typedef struct {
247 struct __Container_proxy *proxy;
248 } _Container_base12;
250 typedef struct __Iterator_base12 {
251 struct __Container_proxy *proxy;
252 struct __Iterator_base12 *next;
253 } _Iterator_base12;
255 typedef struct __Container_proxy {
256 const _Container_base12 *cont;
257 _Iterator_base12 *head;
258 } _Container_proxy;
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 = MSVCRT_operator_new(sizeof(*cs));
266 if(!cs) {
267 ERR("Out of memory\n");
268 throw_exception(EXCEPTION_BAD_ALLOC, NULL);
271 InitializeCriticalSection(cs);
272 cs->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Mutex critical section");
273 this->mutex = cs;
274 return this;
277 /* ??1_Mutex@std@@QAE@XZ */
278 /* ??1_Mutex@std@@QEAA@XZ */
279 DEFINE_THISCALL_WRAPPER(mutex_dtor, 4)
280 void __thiscall mutex_dtor(mutex *this)
282 ((CRITICAL_SECTION*)this->mutex)->DebugInfo->Spare[0] = 0;
283 DeleteCriticalSection(this->mutex);
284 MSVCRT_operator_delete(this->mutex);
287 /* ?_Lock@_Mutex@std@@QAEXXZ */
288 /* ?_Lock@_Mutex@std@@QEAAXXZ */
289 DEFINE_THISCALL_WRAPPER(mutex_lock, 4)
290 void __thiscall mutex_lock(mutex *this)
292 EnterCriticalSection(this->mutex);
295 /* ?_Unlock@_Mutex@std@@QAEXXZ */
296 /* ?_Unlock@_Mutex@std@@QEAAXXZ */
297 DEFINE_THISCALL_WRAPPER(mutex_unlock, 4)
298 void __thiscall mutex_unlock(mutex *this)
300 LeaveCriticalSection(this->mutex);
303 /* ?_Mutex_Lock@_Mutex@std@@CAXPAV12@@Z */
304 /* ?_Mutex_Lock@_Mutex@std@@CAXPEAV12@@Z */
305 void CDECL mutex_mutex_lock(mutex *m)
307 mutex_lock(m);
310 /* ?_Mutex_Unlock@_Mutex@std@@CAXPAV12@@Z */
311 /* ?_Mutex_Unlock@_Mutex@std@@CAXPEAV12@@Z */
312 void CDECL mutex_mutex_unlock(mutex *m)
314 mutex_unlock(m);
317 /* ?_Mutex_ctor@_Mutex@std@@CAXPAV12@@Z */
318 /* ?_Mutex_ctor@_Mutex@std@@CAXPEAV12@@Z */
319 void CDECL mutex_mutex_ctor(mutex *m)
321 mutex_ctor(m);
324 /* ?_Mutex_dtor@_Mutex@std@@CAXPAV12@@Z */
325 /* ?_Mutex_dtor@_Mutex@std@@CAXPEAV12@@Z */
326 void CDECL mutex_mutex_dtor(mutex *m)
328 mutex_dtor(m);
331 static CRITICAL_SECTION lockit_cs[_MAX_LOCK];
333 static LONG init_locks;
334 static CRITICAL_SECTION init_locks_cs;
335 static CRITICAL_SECTION_DEBUG init_locks_cs_debug =
337 0, 0, &init_locks_cs,
338 { &init_locks_cs_debug.ProcessLocksList, &init_locks_cs_debug.ProcessLocksList },
339 0, 0, { (DWORD_PTR)(__FILE__ ": init_locks_cs") }
341 static CRITICAL_SECTION init_locks_cs = { &init_locks_cs_debug, -1, 0, 0, 0, 0 };
343 /* ?_Init_locks_ctor@_Init_locks@std@@CAXPAV12@@Z */
344 /* ?_Init_locks_ctor@_Init_locks@std@@CAXPEAV12@@Z */
345 void __cdecl _Init_locks__Init_locks_ctor(_Init_locks *this)
347 int i;
349 EnterCriticalSection(&init_locks_cs);
350 if (!init_locks)
352 for(i=0; i<_MAX_LOCK; i++)
354 InitializeCriticalSection(&lockit_cs[i]);
355 lockit_cs[i].DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": _Lockit critical section");
358 init_locks++;
359 LeaveCriticalSection(&init_locks_cs);
362 /* ??0_Init_locks@std@@QAE@XZ */
363 /* ??0_Init_locks@std@@QEAA@XZ */
364 DEFINE_THISCALL_WRAPPER(_Init_locks_ctor, 4)
365 _Init_locks* __thiscall _Init_locks_ctor(_Init_locks *this)
367 _Init_locks__Init_locks_ctor(this);
368 return this;
371 /* ?_Init_locks_dtor@_Init_locks@std@@CAXPAV12@@Z */
372 /* ?_Init_locks_dtor@_Init_locks@std@@CAXPEAV12@@Z */
373 void __cdecl _Init_locks__Init_locks_dtor(_Init_locks *this)
375 int i;
377 EnterCriticalSection(&init_locks_cs);
378 init_locks--;
379 if (!init_locks)
381 for(i=0; i<_MAX_LOCK; i++)
383 lockit_cs[i].DebugInfo->Spare[0] = 0;
384 DeleteCriticalSection(&lockit_cs[i]);
387 LeaveCriticalSection(&init_locks_cs);
390 /* ??1_Init_locks@std@@QAE@XZ */
391 /* ??1_Init_locks@std@@QEAA@XZ */
392 DEFINE_THISCALL_WRAPPER(_Init_locks_dtor, 4)
393 void __thiscall _Init_locks_dtor(_Init_locks *this)
395 _Init_locks__Init_locks_dtor(this);
398 #if _MSVCP_VER >= 70
399 static inline int get_locktype( _Lockit *lockit ) { return lockit->locktype; }
400 static inline void set_locktype( _Lockit *lockit, int type ) { lockit->locktype = type; }
401 #else
402 static inline int get_locktype( _Lockit *lockit ) { return 0; }
403 static inline void set_locktype( _Lockit *lockit, int type ) { }
404 #endif
406 /* ?_Lockit_ctor@_Lockit@std@@SAXH@Z */
407 void __cdecl _Lockit__Lockit_ctor_lock(int locktype)
409 EnterCriticalSection(&lockit_cs[locktype]);
412 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@H@Z */
413 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@H@Z */
414 void __cdecl _Lockit__Lockit_ctor_locktype(_Lockit *lockit, int locktype)
416 set_locktype( lockit, locktype );
417 _Lockit__Lockit_ctor_lock(locktype);
420 /* ?_Lockit_ctor@_Lockit@std@@CAXPAV12@@Z */
421 /* ?_Lockit_ctor@_Lockit@std@@CAXPEAV12@@Z */
422 void __cdecl _Lockit__Lockit_ctor(_Lockit *lockit)
424 _Lockit__Lockit_ctor_locktype(lockit, 0);
427 /* ??0_Lockit@std@@QAE@H@Z */
428 /* ??0_Lockit@std@@QEAA@H@Z */
429 DEFINE_THISCALL_WRAPPER(_Lockit_ctor_locktype, 8)
430 _Lockit* __thiscall _Lockit_ctor_locktype(_Lockit *this, int locktype)
432 _Lockit__Lockit_ctor_locktype(this, locktype);
433 return this;
436 /* ??0_Lockit@std@@QAE@XZ */
437 /* ??0_Lockit@std@@QEAA@XZ */
438 DEFINE_THISCALL_WRAPPER(_Lockit_ctor, 4)
439 _Lockit* __thiscall _Lockit_ctor(_Lockit *this)
441 _Lockit__Lockit_ctor_locktype(this, 0);
442 return this;
445 /* ?_Lockit_dtor@_Lockit@std@@SAXH@Z */
446 void __cdecl _Lockit__Lockit_dtor_unlock(int locktype)
448 LeaveCriticalSection(&lockit_cs[locktype]);
451 /* ?_Lockit_dtor@_Lockit@std@@CAXPAV12@@Z */
452 /* ?_Lockit_dtor@_Lockit@std@@CAXPEAV12@@Z */
453 void __cdecl _Lockit__Lockit_dtor(_Lockit *lockit)
455 _Lockit__Lockit_dtor_unlock(get_locktype( lockit ));
458 /* ??1_Lockit@std@@QAE@XZ */
459 /* ??1_Lockit@std@@QEAA@XZ */
460 DEFINE_THISCALL_WRAPPER(_Lockit_dtor, 4)
461 void __thiscall _Lockit_dtor(_Lockit *this)
463 _Lockit__Lockit_dtor(this);
466 /* wctype */
467 unsigned short __cdecl wctype(const char *property)
469 static const struct {
470 const char *name;
471 unsigned short mask;
472 } properties[] = {
473 { "alnum", _DIGIT|_ALPHA },
474 { "alpha", _ALPHA },
475 { "cntrl", _CONTROL },
476 { "digit", _DIGIT },
477 { "graph", _DIGIT|_PUNCT|_ALPHA },
478 { "lower", _LOWER },
479 { "print", _DIGIT|_PUNCT|_BLANK|_ALPHA },
480 { "punct", _PUNCT },
481 { "space", _SPACE },
482 { "upper", _UPPER },
483 { "xdigit", _HEX }
485 unsigned int i;
487 for(i = 0; i < ARRAY_SIZE(properties); i++)
488 if(!strcmp(property, properties[i].name))
489 return properties[i].mask;
491 return 0;
494 typedef void (__cdecl *MSVCP_new_handler_func)(void);
495 static MSVCP_new_handler_func MSVCP_new_handler;
496 static int __cdecl new_handler_wrapper(size_t unused)
498 MSVCP_new_handler();
499 return 1;
502 /* ?set_new_handler@std@@YAP6AXXZP6AXXZ@Z */
503 MSVCP_new_handler_func __cdecl set_new_handler(MSVCP_new_handler_func new_handler)
505 MSVCP_new_handler_func old_handler = MSVCP_new_handler;
507 TRACE("%p\n", new_handler);
509 MSVCP_new_handler = new_handler;
510 MSVCRT_set_new_handler(new_handler ? new_handler_wrapper : NULL);
511 return old_handler;
514 /* ?set_new_handler@std@@YAP6AXXZH@Z */
515 MSVCP_new_handler_func __cdecl set_new_handler_reset(int unused)
517 return set_new_handler(NULL);
520 /* _Container_base0 is used by apps compiled without iterator checking
521 * (i.e. with _ITERATOR_DEBUG_LEVEL=0 ).
522 * It provides empty versions of methods used by visual c++'s stl's
523 * iterator checking.
524 * msvcr100 has to provide them in case apps are compiled with /Od
525 * or the optimizer fails to inline those (empty) calls.
528 /* ?_Orphan_all@_Container_base0@std@@QAEXXZ */
529 /* ?_Orphan_all@_Container_base0@std@@QEAAXXZ */
530 DEFINE_THISCALL_WRAPPER(Container_base0_Orphan_all, 4)
531 void __thiscall Container_base0_Orphan_all(void *this)
535 /* ?_Swap_all@_Container_base0@std@@QAEXAAU12@@Z */
536 /* ?_Swap_all@_Container_base0@std@@QEAAXAEAU12@@Z */
537 DEFINE_THISCALL_WRAPPER(Container_base0_Swap_all, 8)
538 void __thiscall Container_base0_Swap_all(void *this, void *that)
542 /* ??4_Container_base0@std@@QAEAAU01@ABU01@@Z */
543 /* ??4_Container_base0@std@@QEAAAEAU01@AEBU01@@Z */
544 DEFINE_THISCALL_WRAPPER(Container_base0_op_assign, 8)
545 void* __thiscall Container_base0_op_assign(void *this, const void *that)
547 return this;
550 /* ??0_Container_base12@std@@QAE@ABU01@@Z */
551 /* ??0_Container_base12@std@@QEAA@AEBU01@@Z */
552 DEFINE_THISCALL_WRAPPER(_Container_base12_copy_ctor, 8)
553 _Container_base12* __thiscall _Container_base12_copy_ctor(
554 _Container_base12 *this, _Container_base12 *that)
556 this->proxy = NULL;
557 return this;
560 /* ??0_Container_base12@std@@QAE@XZ */
561 /* ??0_Container_base12@std@@QEAA@XZ */
562 DEFINE_THISCALL_WRAPPER(_Container_base12_ctor, 4)
563 _Container_base12* __thiscall _Container_base12_ctor(_Container_base12 *this)
565 this->proxy = NULL;
566 return this;
569 /* ??1_Container_base12@std@@QAE@XZ */
570 /* ??1_Container_base12@std@@QEAA@XZ */
571 DEFINE_THISCALL_WRAPPER(_Container_base12_dtor, 4)
572 void __thiscall _Container_base12_dtor(_Container_base12 *this)
576 /* ??4_Container_base12@std@@QAEAAU01@ABU01@@Z */
577 /* ??4_Container_base12@std@@QEAAAEAU01@AEBU01@@ */
578 DEFINE_THISCALL_WRAPPER(_Container_base12_op_assign, 8)
579 _Container_base12* __thiscall _Container_base12_op_assign(
580 _Container_base12 *this, const _Container_base12 *that)
582 return this;
585 /* ?_Getpfirst@_Container_base12@std@@QBEPAPAU_Iterator_base12@2@XZ */
586 /* ?_Getpfirst@_Container_base12@std@@QEBAPEAPEAU_Iterator_base12@2@XZ */
587 DEFINE_THISCALL_WRAPPER(_Container_base12__Getpfirst, 4)
588 _Iterator_base12** __thiscall _Container_base12__Getpfirst(_Container_base12 *this)
590 return this->proxy ? &this->proxy->head : NULL;
593 /* ?_Orphan_all@_Container_base12@std@@QAEXXZ */
594 /* ?_Orphan_all@_Container_base12@std@@QEAAXXZ */
595 DEFINE_THISCALL_WRAPPER(_Container_base12__Orphan_all, 4)
596 void __thiscall _Container_base12__Orphan_all(_Container_base12 *this)
600 /* ?_Swap_all@_Container_base12@std@@QAEXAAU12@@Z */
601 /* ?_Swap_all@_Container_base12@std@@QEAAXAEAU12@@Z */
602 DEFINE_THISCALL_WRAPPER(_Container_base12__Swap_all, 8)
603 void __thiscall _Container_base12__Swap_all(
604 _Container_base12 *this, _Container_base12 *that)
606 _Container_proxy *tmp;
608 tmp = this->proxy;
609 this->proxy = that->proxy;
610 that->proxy = tmp;
612 if(this->proxy)
613 this->proxy->cont = this;
614 if(that->proxy)
615 that->proxy->cont = that;
618 #if _MSVCP_VER >= 110
620 #define SECSPERDAY 86400
621 /* 1601 to 1970 is 369 years plus 89 leap days */
622 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
623 #define TICKSPERSEC 10000000
624 #define TICKS_1601_TO_1970 (SECS_1601_TO_1970 * TICKSPERSEC)
625 #define NANOSEC_PER_MILLISEC 1000000
626 #define MILLISEC_PER_SEC 1000
627 #define NANOSEC_PER_SEC (NANOSEC_PER_MILLISEC * MILLISEC_PER_SEC)
629 typedef int MSVCRT_long;
631 /* xtime */
632 typedef struct {
633 __time64_t sec;
634 MSVCRT_long nsec;
635 } xtime;
637 /* _Xtime_get_ticks */
638 LONGLONG __cdecl _Xtime_get_ticks(void)
640 FILETIME ft;
642 TRACE("\n");
644 GetSystemTimeAsFileTime(&ft);
645 return ((LONGLONG)ft.dwHighDateTime<<32) + ft.dwLowDateTime - TICKS_1601_TO_1970;
648 /* _xtime_get */
649 int __cdecl xtime_get(xtime* t, int unknown)
651 LONGLONG ticks;
653 TRACE("(%p)\n", t);
655 if(unknown != 1)
656 return 0;
658 ticks = _Xtime_get_ticks();
659 t->sec = ticks / TICKSPERSEC;
660 t->nsec = ticks % TICKSPERSEC * 100;
661 return 1;
664 /* _Xtime_diff_to_millis2 */
665 MSVCRT_long __cdecl _Xtime_diff_to_millis2(const xtime *t1, const xtime *t2)
667 LONGLONG diff_sec, diff_nsec;
669 TRACE("(%p, %p)\n", t1, t2);
671 diff_sec = t1->sec - t2->sec;
672 diff_nsec = t1->nsec - t2->nsec;
674 diff_sec += diff_nsec / NANOSEC_PER_SEC;
675 diff_nsec %= NANOSEC_PER_SEC;
676 if (diff_nsec < 0) {
677 diff_sec -= 1;
678 diff_nsec += NANOSEC_PER_SEC;
681 if (diff_sec<0 || (diff_sec==0 && diff_nsec<0))
682 return 0;
683 return diff_sec * MILLISEC_PER_SEC +
684 (diff_nsec + NANOSEC_PER_MILLISEC - 1) / NANOSEC_PER_MILLISEC;
687 /* _Xtime_diff_to_millis */
688 MSVCRT_long __cdecl _Xtime_diff_to_millis(const xtime *t)
690 xtime now;
692 TRACE("%p\n", t);
694 xtime_get(&now, 1);
695 return _Xtime_diff_to_millis2(t, &now);
697 #endif
699 #if _MSVCP_VER >= 90
700 unsigned int __cdecl _Random_device(void)
702 unsigned int ret;
704 TRACE("\n");
706 /* TODO: throw correct exception in case of failure */
707 if(rand_s(&ret))
708 throw_exception(EXCEPTION, "random number generator failed\n");
709 return ret;
711 #endif
713 #if _MSVCP_VER >= 110
714 #ifdef __ASM_USE_THISCALL_WRAPPER
716 extern void *call_thiscall_func;
717 __ASM_GLOBAL_FUNC(call_thiscall_func,
718 "popl %eax\n\t"
719 "popl %edx\n\t"
720 "popl %ecx\n\t"
721 "pushl %eax\n\t"
722 "jmp *%edx\n\t")
724 #define call_func1(func,this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)(func,this)
726 #else /* __i386__ */
728 #define call_func1(func,this) func(this)
730 #endif /* __i386__ */
732 #define MTX_PLAIN 0x1
733 #define MTX_TRY 0x2
734 #define MTX_TIMED 0x4
735 #define MTX_RECURSIVE 0x100
736 #define MTX_LOCKED 3
737 typedef struct
739 DWORD flags;
740 critical_section cs;
741 DWORD thread_id;
742 DWORD count;
743 } *_Mtx_t;
745 #if _MSVCP_VER >= 140
746 typedef _Mtx_t _Mtx_arg_t;
747 #define MTX_T_FROM_ARG(m) (m)
748 #define MTX_T_TO_ARG(m) (m)
749 #else
750 typedef _Mtx_t *_Mtx_arg_t;
751 #define MTX_T_FROM_ARG(m) (*(m))
752 #define MTX_T_TO_ARG(m) (&(m))
753 #endif
755 void __cdecl _Mtx_init_in_situ(_Mtx_t mtx, int flags)
757 if(flags & ~(MTX_PLAIN | MTX_TRY | MTX_TIMED | MTX_RECURSIVE))
758 FIXME("unknown flags ignored: %x\n", flags);
760 mtx->flags = flags;
761 call_func1(critical_section_ctor, &mtx->cs);
762 mtx->thread_id = -1;
763 mtx->count = 0;
766 int __cdecl _Mtx_init(_Mtx_t *mtx, int flags)
768 *mtx = MSVCRT_operator_new(sizeof(**mtx));
769 _Mtx_init_in_situ(*mtx, flags);
770 return 0;
773 void __cdecl _Mtx_destroy_in_situ(_Mtx_t mtx)
775 call_func1(critical_section_dtor, &mtx->cs);
778 void __cdecl _Mtx_destroy(_Mtx_arg_t mtx)
780 call_func1(critical_section_dtor, &MTX_T_FROM_ARG(mtx)->cs);
781 MSVCRT_operator_delete(MTX_T_FROM_ARG(mtx));
784 int __cdecl _Mtx_current_owns(_Mtx_arg_t mtx)
786 return MTX_T_FROM_ARG(mtx)->thread_id == GetCurrentThreadId();
789 int __cdecl _Mtx_lock(_Mtx_arg_t mtx)
791 if(MTX_T_FROM_ARG(mtx)->thread_id != GetCurrentThreadId()) {
792 call_func1(critical_section_lock, &MTX_T_FROM_ARG(mtx)->cs);
793 MTX_T_FROM_ARG(mtx)->thread_id = GetCurrentThreadId();
794 }else if(!(MTX_T_FROM_ARG(mtx)->flags & MTX_RECURSIVE)
795 && MTX_T_FROM_ARG(mtx)->flags != MTX_PLAIN) {
796 return MTX_LOCKED;
799 MTX_T_FROM_ARG(mtx)->count++;
800 return 0;
803 int __cdecl _Mtx_unlock(_Mtx_arg_t mtx)
805 if(--MTX_T_FROM_ARG(mtx)->count)
806 return 0;
808 MTX_T_FROM_ARG(mtx)->thread_id = -1;
809 call_func1(critical_section_unlock, &MTX_T_FROM_ARG(mtx)->cs);
810 return 0;
813 int __cdecl _Mtx_trylock(_Mtx_arg_t mtx)
815 if(MTX_T_FROM_ARG(mtx)->thread_id != GetCurrentThreadId()) {
816 if(!call_func1(critical_section_trylock, &MTX_T_FROM_ARG(mtx)->cs))
817 return MTX_LOCKED;
818 MTX_T_FROM_ARG(mtx)->thread_id = GetCurrentThreadId();
819 }else if(!(MTX_T_FROM_ARG(mtx)->flags & MTX_RECURSIVE)
820 && MTX_T_FROM_ARG(mtx)->flags != MTX_PLAIN) {
821 return MTX_LOCKED;
824 MTX_T_FROM_ARG(mtx)->count++;
825 return 0;
828 critical_section* __cdecl _Mtx_getconcrtcs(_Mtx_arg_t mtx)
830 return &MTX_T_FROM_ARG(mtx)->cs;
833 static inline LONG interlocked_dec_if_nonzero( LONG *dest )
835 LONG val, tmp;
836 for (val = *dest;; val = tmp)
838 if (!val || (tmp = InterlockedCompareExchange( dest, val - 1, val )) == val)
839 break;
841 return val;
844 #define CND_TIMEDOUT 2
846 typedef struct
848 CONDITION_VARIABLE cv;
849 } *_Cnd_t;
851 #if _MSVCP_VER >= 140
852 typedef _Cnd_t _Cnd_arg_t;
853 #define CND_T_FROM_ARG(c) (c)
854 #define CND_T_TO_ARG(c) (c)
855 #else
856 typedef _Cnd_t *_Cnd_arg_t;
857 #define CND_T_FROM_ARG(c) (*(c))
858 #define CND_T_TO_ARG(c) (&(c))
859 #endif
861 static HANDLE keyed_event;
863 void __cdecl _Cnd_init_in_situ(_Cnd_t cnd)
865 InitializeConditionVariable(&cnd->cv);
867 if(!keyed_event) {
868 HANDLE event;
870 NtCreateKeyedEvent(&event, GENERIC_READ|GENERIC_WRITE, NULL, 0);
871 if(InterlockedCompareExchangePointer(&keyed_event, event, NULL) != NULL)
872 NtClose(event);
876 int __cdecl _Cnd_init(_Cnd_t *cnd)
878 *cnd = MSVCRT_operator_new(sizeof(**cnd));
879 _Cnd_init_in_situ(*cnd);
880 return 0;
883 int __cdecl _Cnd_wait(_Cnd_arg_t cnd, _Mtx_arg_t mtx)
885 CONDITION_VARIABLE *cv = &CND_T_FROM_ARG(cnd)->cv;
887 InterlockedExchangeAdd( (LONG *)&cv->Ptr, 1 );
888 _Mtx_unlock(mtx);
890 NtWaitForKeyedEvent(keyed_event, &cv->Ptr, FALSE, NULL);
892 _Mtx_lock(mtx);
893 return 0;
896 int __cdecl _Cnd_timedwait(_Cnd_arg_t cnd, _Mtx_arg_t mtx, const xtime *xt)
898 CONDITION_VARIABLE *cv = &CND_T_FROM_ARG(cnd)->cv;
899 LARGE_INTEGER timeout;
900 NTSTATUS status;
902 InterlockedExchangeAdd( (LONG *)&cv->Ptr, 1 );
903 _Mtx_unlock(mtx);
905 timeout.QuadPart = (ULONGLONG)(ULONG)_Xtime_diff_to_millis(xt) * -10000;
906 status = NtWaitForKeyedEvent(keyed_event, &cv->Ptr, FALSE, &timeout);
907 if (status)
909 if (!interlocked_dec_if_nonzero( (LONG *)&cv->Ptr ))
910 status = NtWaitForKeyedEvent( keyed_event, &cv->Ptr, FALSE, NULL );
913 _Mtx_lock(mtx);
914 return status ? CND_TIMEDOUT : 0;
917 int __cdecl _Cnd_broadcast(_Cnd_arg_t cnd)
919 CONDITION_VARIABLE *cv = &CND_T_FROM_ARG(cnd)->cv;
920 LONG val = InterlockedExchange( (LONG *)&cv->Ptr, 0 );
921 while (val-- > 0)
922 NtReleaseKeyedEvent( keyed_event, &cv->Ptr, FALSE, NULL );
923 return 0;
926 int __cdecl _Cnd_signal(_Cnd_arg_t cnd)
928 CONDITION_VARIABLE *cv = &CND_T_FROM_ARG(cnd)->cv;
929 if (interlocked_dec_if_nonzero( (LONG *)&cv->Ptr ))
930 NtReleaseKeyedEvent( keyed_event, &cv->Ptr, FALSE, NULL );
931 return 0;
934 void __cdecl _Cnd_destroy_in_situ(_Cnd_t cnd)
936 _Cnd_broadcast(CND_T_TO_ARG(cnd));
939 void __cdecl _Cnd_destroy(_Cnd_arg_t cnd)
941 if(cnd) {
942 _Cnd_broadcast(cnd);
943 MSVCRT_operator_delete(CND_T_FROM_ARG(cnd));
947 static struct {
948 int used;
949 int size;
951 struct _to_broadcast {
952 DWORD thread_id;
953 _Cnd_arg_t cnd;
954 _Mtx_arg_t mtx;
955 int *p;
956 } *to_broadcast;
957 } broadcast_at_thread_exit;
959 static CRITICAL_SECTION broadcast_at_thread_exit_cs;
960 static CRITICAL_SECTION_DEBUG broadcast_at_thread_exit_cs_debug =
962 0, 0, &broadcast_at_thread_exit_cs,
963 { &broadcast_at_thread_exit_cs_debug.ProcessLocksList, &broadcast_at_thread_exit_cs_debug.ProcessLocksList },
964 0, 0, { (DWORD_PTR)(__FILE__ ": broadcast_at_thread_exit_cs") }
966 static CRITICAL_SECTION broadcast_at_thread_exit_cs = { &broadcast_at_thread_exit_cs_debug, -1, 0, 0, 0, 0 };
968 void __cdecl _Cnd_register_at_thread_exit(_Cnd_arg_t cnd, _Mtx_arg_t mtx, int *p)
970 struct _to_broadcast *add;
972 TRACE("(%p %p %p)\n", cnd, mtx, p);
974 EnterCriticalSection(&broadcast_at_thread_exit_cs);
975 if(!broadcast_at_thread_exit.size) {
976 broadcast_at_thread_exit.to_broadcast = HeapAlloc(GetProcessHeap(),
977 0, 8*sizeof(broadcast_at_thread_exit.to_broadcast[0]));
978 if(!broadcast_at_thread_exit.to_broadcast) {
979 LeaveCriticalSection(&broadcast_at_thread_exit_cs);
980 return;
982 broadcast_at_thread_exit.size = 8;
983 } else if(broadcast_at_thread_exit.size == broadcast_at_thread_exit.used) {
984 add = HeapReAlloc(GetProcessHeap(), 0, broadcast_at_thread_exit.to_broadcast,
985 broadcast_at_thread_exit.size*2*sizeof(broadcast_at_thread_exit.to_broadcast[0]));
986 if(!add) {
987 LeaveCriticalSection(&broadcast_at_thread_exit_cs);
988 return;
990 broadcast_at_thread_exit.to_broadcast = add;
991 broadcast_at_thread_exit.size *= 2;
994 add = broadcast_at_thread_exit.to_broadcast + broadcast_at_thread_exit.used++;
995 add->thread_id = GetCurrentThreadId();
996 add->cnd = cnd;
997 add->mtx = mtx;
998 add->p = p;
999 LeaveCriticalSection(&broadcast_at_thread_exit_cs);
1002 void __cdecl _Cnd_unregister_at_thread_exit(_Mtx_arg_t mtx)
1004 int i;
1006 TRACE("(%p)\n", mtx);
1008 EnterCriticalSection(&broadcast_at_thread_exit_cs);
1009 for(i=0; i<broadcast_at_thread_exit.used; i++) {
1010 if(broadcast_at_thread_exit.to_broadcast[i].mtx != mtx)
1011 continue;
1013 memmove(broadcast_at_thread_exit.to_broadcast+i, broadcast_at_thread_exit.to_broadcast+i+1,
1014 (broadcast_at_thread_exit.used-i-1)*sizeof(broadcast_at_thread_exit.to_broadcast[0]));
1015 broadcast_at_thread_exit.used--;
1016 i--;
1018 LeaveCriticalSection(&broadcast_at_thread_exit_cs);
1021 void __cdecl _Cnd_do_broadcast_at_thread_exit(void)
1023 int i, id = GetCurrentThreadId();
1025 TRACE("()\n");
1027 EnterCriticalSection(&broadcast_at_thread_exit_cs);
1028 for(i=0; i<broadcast_at_thread_exit.used; i++) {
1029 if(broadcast_at_thread_exit.to_broadcast[i].thread_id != id)
1030 continue;
1032 _Mtx_unlock(broadcast_at_thread_exit.to_broadcast[i].mtx);
1033 _Cnd_broadcast(broadcast_at_thread_exit.to_broadcast[i].cnd);
1034 if(broadcast_at_thread_exit.to_broadcast[i].p)
1035 *broadcast_at_thread_exit.to_broadcast[i].p = 1;
1037 memmove(broadcast_at_thread_exit.to_broadcast+i, broadcast_at_thread_exit.to_broadcast+i+1,
1038 (broadcast_at_thread_exit.used-i-1)*sizeof(broadcast_at_thread_exit.to_broadcast[0]));
1039 broadcast_at_thread_exit.used--;
1040 i--;
1042 LeaveCriticalSection(&broadcast_at_thread_exit_cs);
1045 #endif
1047 #if _MSVCP_VER == 100
1048 typedef struct {
1049 const vtable_ptr *vtable;
1050 } error_category;
1052 typedef struct {
1053 error_category base;
1054 const char *type;
1055 } custom_category;
1056 static custom_category iostream_category;
1058 DEFINE_RTTI_DATA0(error_category, 0, ".?AVerror_category@std@@")
1059 DEFINE_RTTI_DATA1(iostream_category, 0, &error_category_rtti_base_descriptor, ".?AV_Iostream_error_category@std@@")
1061 extern const vtable_ptr MSVCP_iostream_category_vtable;
1063 static void iostream_category_ctor(custom_category *this)
1065 this->base.vtable = &MSVCP_iostream_category_vtable;
1066 this->type = "iostream";
1069 DEFINE_THISCALL_WRAPPER(custom_category_vector_dtor, 8)
1070 custom_category* __thiscall custom_category_vector_dtor(custom_category *this, unsigned int flags)
1072 TRACE("(%p %x)\n", this, flags);
1073 if(flags & 2) {
1074 /* we have an array, with the number of elements stored before the first object */
1075 INT_PTR i, *ptr = (INT_PTR *)this-1;
1077 for(i=*ptr-1; i>=0; i--)
1078 MSVCRT_operator_delete(ptr);
1079 } else {
1080 if(flags & 1)
1081 MSVCRT_operator_delete(this);
1084 return this;
1087 DEFINE_THISCALL_WRAPPER(custom_category_name, 4)
1088 const char* __thiscall custom_category_name(const custom_category *this)
1090 return this->type;
1093 DEFINE_THISCALL_WRAPPER(custom_category_message, 12)
1094 basic_string_char* __thiscall custom_category_message(const custom_category *this,
1095 basic_string_char *ret, int err)
1097 return MSVCP_basic_string_char_ctor_cstr(ret, strerror(err));
1100 DEFINE_THISCALL_WRAPPER(custom_category_default_error_condition, 12)
1101 /*error_condition*/void* __thiscall custom_category_default_error_condition(
1102 custom_category *this, /*error_condition*/void *ret, int code)
1104 FIXME("(%p %p %x) stub\n", this, ret, code);
1105 return NULL;
1108 DEFINE_THISCALL_WRAPPER(custom_category_equivalent, 12)
1109 bool __thiscall custom_category_equivalent(const custom_category *this,
1110 int code, const /*error_condition*/void *condition)
1112 FIXME("(%p %x %p) stub\n", this, code, condition);
1113 return FALSE;
1116 DEFINE_THISCALL_WRAPPER(custom_category_equivalent_code, 12)
1117 bool __thiscall custom_category_equivalent_code(custom_category *this,
1118 const /*error_code*/void *code, int condition)
1120 FIXME("(%p %p %x) stub\n", this, code, condition);
1121 return FALSE;
1124 DEFINE_THISCALL_WRAPPER(iostream_category_message, 12)
1125 basic_string_char* __thiscall iostream_category_message(const custom_category *this,
1126 basic_string_char *ret, int err)
1128 if(err == 1) return MSVCP_basic_string_char_ctor_cstr(ret, "iostream error");
1129 return MSVCP_basic_string_char_ctor_cstr(ret, strerror(err));
1132 /* ?iostream_category@std@@YAABVerror_category@1@XZ */
1133 /* ?iostream_category@std@@YAAEBVerror_category@1@XZ */
1134 const error_category* __cdecl std_iostream_category(void)
1136 TRACE("()\n");
1137 return &iostream_category.base;
1140 static custom_category system_category;
1141 DEFINE_RTTI_DATA1(system_category, 0, &error_category_rtti_base_descriptor, ".?AV_System_error_category@std@@")
1143 extern const vtable_ptr MSVCP_system_category_vtable;
1145 static void system_category_ctor(custom_category *this)
1147 this->base.vtable = &MSVCP_system_category_vtable;
1148 this->type = "system";
1151 /* ?system_category@std@@YAABVerror_category@1@XZ */
1152 /* ?system_category@std@@YAAEBVerror_category@1@XZ */
1153 const error_category* __cdecl std_system_category(void)
1155 TRACE("()\n");
1156 return &system_category.base;
1159 static custom_category generic_category;
1160 DEFINE_RTTI_DATA1(generic_category, 0, &error_category_rtti_base_descriptor, ".?AV_Generic_error_category@std@@")
1162 extern const vtable_ptr MSVCP_generic_category_vtable;
1164 static void generic_category_ctor(custom_category *this)
1166 this->base.vtable = &MSVCP_generic_category_vtable;
1167 this->type = "generic";
1170 /* ?generic_category@std@@YAABVerror_category@1@XZ */
1171 /* ?generic_category@std@@YAAEBVerror_category@1@XZ */
1172 const error_category* __cdecl std_generic_category(void)
1174 TRACE("()\n");
1175 return &generic_category.base;
1177 #endif
1179 #if _MSVCP_VER >= 110
1180 static CRITICAL_SECTION call_once_cs;
1181 static CRITICAL_SECTION_DEBUG call_once_cs_debug =
1183 0, 0, &call_once_cs,
1184 { &call_once_cs_debug.ProcessLocksList, &call_once_cs_debug.ProcessLocksList },
1185 0, 0, { (DWORD_PTR)(__FILE__ ": call_once_cs") }
1187 static CRITICAL_SECTION call_once_cs = { &call_once_cs_debug, -1, 0, 0, 0, 0 };
1189 void __cdecl _Call_onceEx(int *once, void (__cdecl *func)(void*), void *argv)
1191 TRACE("%p %p %p\n", once, func, argv);
1193 EnterCriticalSection(&call_once_cs);
1194 if(!*once) {
1195 /* FIXME: handle exceptions */
1196 func(argv);
1197 *once = 1;
1199 LeaveCriticalSection(&call_once_cs);
1202 static void __cdecl call_once_func_wrapper(void *func)
1204 ((void (__cdecl*)(void))func)();
1207 void __cdecl _Call_once(int *once, void (__cdecl *func)(void))
1209 TRACE("%p %p\n", once, func);
1210 _Call_onceEx(once, call_once_func_wrapper, func);
1213 void __cdecl _Do_call(void *this)
1215 CALL_VTBL_FUNC(this, 0, void, (void*), (this));
1217 #endif
1219 #if _MSVCP_VER >= 110
1220 typedef struct
1222 HANDLE hnd;
1223 DWORD id;
1224 } _Thrd_t;
1226 typedef int (__cdecl *_Thrd_start_t)(void*);
1228 #define _THRD_ERROR 4
1230 int __cdecl _Thrd_equal(_Thrd_t a, _Thrd_t b)
1232 TRACE("(%p %u %p %u)\n", a.hnd, a.id, b.hnd, b.id);
1233 return a.id == b.id;
1236 int __cdecl _Thrd_lt(_Thrd_t a, _Thrd_t b)
1238 TRACE("(%p %u %p %u)\n", a.hnd, a.id, b.hnd, b.id);
1239 return a.id < b.id;
1242 void __cdecl _Thrd_sleep(const xtime *t)
1244 TRACE("(%p)\n", t);
1245 Sleep(_Xtime_diff_to_millis(t));
1248 void __cdecl _Thrd_yield(void)
1250 TRACE("()\n");
1251 Sleep(0);
1254 static _Thrd_t thread_current(void)
1256 _Thrd_t ret;
1258 if(DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
1259 GetCurrentProcess(), &ret.hnd, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
1260 CloseHandle(ret.hnd);
1261 } else {
1262 ret.hnd = 0;
1264 ret.id = GetCurrentThreadId();
1266 TRACE("(%p %u)\n", ret.hnd, ret.id);
1267 return ret;
1270 #ifndef __i386__
1271 _Thrd_t __cdecl _Thrd_current(void)
1273 return thread_current();
1275 #else
1276 ULONGLONG __cdecl _Thrd_current(void)
1278 union {
1279 _Thrd_t thr;
1280 ULONGLONG ull;
1281 } ret;
1283 C_ASSERT(sizeof(_Thrd_t) <= sizeof(ULONGLONG));
1285 ret.thr = thread_current();
1286 return ret.ull;
1288 #endif
1290 int __cdecl _Thrd_join(_Thrd_t thr, int *code)
1292 TRACE("(%p %u %p)\n", thr.hnd, thr.id, code);
1293 if (WaitForSingleObject(thr.hnd, INFINITE))
1294 return _THRD_ERROR;
1296 if (code)
1297 GetExitCodeThread(thr.hnd, (DWORD *)code);
1299 CloseHandle(thr.hnd);
1300 return 0;
1303 int __cdecl _Thrd_start(_Thrd_t *thr, LPTHREAD_START_ROUTINE proc, void *arg)
1305 TRACE("(%p %p %p)\n", thr, proc, arg);
1306 thr->hnd = CreateThread(NULL, 0, proc, arg, 0, &thr->id);
1307 return thr->hnd ? 0 : _THRD_ERROR;
1310 typedef struct
1312 _Thrd_start_t proc;
1313 void *arg;
1314 } thread_proc_arg;
1316 static DWORD WINAPI thread_proc_wrapper(void *arg)
1318 thread_proc_arg wrapped_arg = *((thread_proc_arg*)arg);
1319 free(arg);
1320 return wrapped_arg.proc(wrapped_arg.arg);
1323 int __cdecl _Thrd_create(_Thrd_t *thr, _Thrd_start_t proc, void *arg)
1325 thread_proc_arg *wrapped_arg;
1326 int ret;
1328 TRACE("(%p %p %p)\n", thr, proc, arg);
1330 wrapped_arg = malloc(sizeof(*wrapped_arg));
1331 if(!wrapped_arg)
1332 return _THRD_ERROR; /* TODO: probably different error should be returned here */
1334 wrapped_arg->proc = proc;
1335 wrapped_arg->arg = arg;
1336 ret = _Thrd_start(thr, thread_proc_wrapper, wrapped_arg);
1337 if(ret) free(wrapped_arg);
1338 return ret;
1341 int __cdecl _Thrd_detach(_Thrd_t thr)
1343 return CloseHandle(thr.hnd) ? 0 : _THRD_ERROR;
1346 typedef struct
1348 const vtable_ptr *vtable;
1349 _Cnd_t cnd;
1350 _Mtx_t mtx;
1351 bool launched;
1352 } _Pad;
1354 DEFINE_RTTI_DATA0(_Pad, 0, ".?AV_Pad@std@@")
1356 /* ??_7_Pad@std@@6B@ */
1357 extern const vtable_ptr MSVCP__Pad_vtable;
1359 unsigned int __cdecl _Thrd_hardware_concurrency(void)
1361 static unsigned int val = -1;
1363 TRACE("()\n");
1365 if(val == -1) {
1366 SYSTEM_INFO si;
1368 GetSystemInfo(&si);
1369 val = si.dwNumberOfProcessors;
1372 return val;
1375 unsigned int __cdecl _Thrd_id(void)
1377 TRACE("()\n");
1378 return GetCurrentThreadId();
1381 /* ??0_Pad@std@@QAE@XZ */
1382 /* ??0_Pad@std@@QEAA@XZ */
1383 DEFINE_THISCALL_WRAPPER(_Pad_ctor, 4)
1384 _Pad* __thiscall _Pad_ctor(_Pad *this)
1386 TRACE("(%p)\n", this);
1388 this->vtable = &MSVCP__Pad_vtable;
1389 _Cnd_init(&this->cnd);
1390 _Mtx_init(&this->mtx, 0);
1391 this->launched = FALSE;
1392 _Mtx_lock(MTX_T_TO_ARG(this->mtx));
1393 return this;
1396 /* ??4_Pad@std@@QAEAAV01@ABV01@@Z */
1397 /* ??4_Pad@std@@QEAAAEAV01@AEBV01@@Z */
1398 DEFINE_THISCALL_WRAPPER(_Pad_op_assign, 8)
1399 _Pad* __thiscall _Pad_op_assign(_Pad *this, const _Pad *copy)
1401 TRACE("(%p %p)\n", this, copy);
1403 this->cnd = copy->cnd;
1404 this->mtx = copy->mtx;
1405 this->launched = copy->launched;
1406 return this;
1409 /* ??0_Pad@std@@QAE@ABV01@@Z */
1410 /* ??0_Pad@std@@QEAA@AEBV01@@Z */
1411 DEFINE_THISCALL_WRAPPER(_Pad_copy_ctor, 8)
1412 _Pad* __thiscall _Pad_copy_ctor(_Pad *this, const _Pad *copy)
1414 TRACE("(%p %p)\n", this, copy);
1416 this->vtable = &MSVCP__Pad_vtable;
1417 return _Pad_op_assign(this, copy);
1420 /* ??1_Pad@std@@QAE@XZ */
1421 /* ??1_Pad@std@@QEAA@XZ */
1422 DEFINE_THISCALL_WRAPPER(_Pad_dtor, 4)
1423 void __thiscall _Pad_dtor(_Pad *this)
1425 TRACE("(%p)\n", this);
1427 _Mtx_unlock(MTX_T_TO_ARG(this->mtx));
1428 _Mtx_destroy(MTX_T_TO_ARG(this->mtx));
1429 _Cnd_destroy(CND_T_TO_ARG(this->cnd));
1432 DEFINE_THISCALL_WRAPPER(_Pad__Go, 4)
1433 #define call__Pad__Go(this) CALL_VTBL_FUNC(this, 0, unsigned int, (_Pad*), (this))
1434 unsigned int __thiscall _Pad__Go(_Pad *this)
1436 ERR("(%p) should not be called\n", this);
1437 return 0;
1440 static DWORD WINAPI launch_thread_proc(void *arg)
1442 _Pad *this = arg;
1443 return call__Pad__Go(this);
1446 /* ?_Launch@_Pad@std@@QAEXPAU_Thrd_imp_t@@@Z */
1447 /* ?_Launch@_Pad@std@@QEAAXPEAU_Thrd_imp_t@@@Z */
1448 DEFINE_THISCALL_WRAPPER(_Pad__Launch, 8)
1449 void __thiscall _Pad__Launch(_Pad *this, _Thrd_t *thr)
1451 TRACE("(%p %p)\n", this, thr);
1453 _Thrd_start(thr, launch_thread_proc, this);
1454 _Cnd_wait(CND_T_TO_ARG(this->cnd), MTX_T_TO_ARG(this->mtx));
1457 /* ?_Release@_Pad@std@@QAEXXZ */
1458 /* ?_Release@_Pad@std@@QEAAXXZ */
1459 DEFINE_THISCALL_WRAPPER(_Pad__Release, 4)
1460 void __thiscall _Pad__Release(_Pad *this)
1462 TRACE("(%p)\n", this);
1464 _Mtx_lock(MTX_T_TO_ARG(this->mtx));
1465 this->launched = TRUE;
1466 _Cnd_signal(CND_T_TO_ARG(this->cnd));
1467 _Mtx_unlock(MTX_T_TO_ARG(this->mtx));
1469 #endif
1471 #if _MSVCP_VER >= 100
1472 typedef struct _Page
1474 struct _Page *_Next;
1475 size_t _Mask;
1476 char data[1];
1477 } _Page;
1479 typedef struct
1481 LONG lock;
1482 _Page *head;
1483 _Page *tail;
1484 size_t head_pos;
1485 size_t tail_pos;
1486 } threadsafe_queue;
1488 #define QUEUES_NO 8
1489 typedef struct
1491 size_t tail_pos;
1492 size_t head_pos;
1493 threadsafe_queue queues[QUEUES_NO];
1494 } queue_data;
1496 typedef struct
1498 const vtable_ptr *vtable;
1499 queue_data *data; /* queue_data structure is not binary compatible */
1500 size_t alloc_count;
1501 size_t item_size;
1502 } _Concurrent_queue_base_v4;
1504 extern const vtable_ptr MSVCP__Concurrent_queue_base_v4_vtable;
1505 #if _MSVCP_VER == 100
1506 #define call__Concurrent_queue_base_v4__Move_item call__Concurrent_queue_base_v4__Copy_item
1507 #define call__Concurrent_queue_base_v4__Copy_item(this,dst,idx,src) CALL_VTBL_FUNC(this, \
1508 0, void, (_Concurrent_queue_base_v4*,_Page*,size_t,const void*), (this,dst,idx,src))
1509 #define call__Concurrent_queue_base_v4__Assign_and_destroy_item(this,dst,src,idx) CALL_VTBL_FUNC(this, \
1510 4, void, (_Concurrent_queue_base_v4*,void*,_Page*,size_t), (this,dst,src,idx))
1511 #define call__Concurrent_queue_base_v4__Allocate_page(this) CALL_VTBL_FUNC(this, \
1512 12, _Page*, (_Concurrent_queue_base_v4*), (this))
1513 #define call__Concurrent_queue_base_v4__Deallocate_page(this, page) CALL_VTBL_FUNC(this, \
1514 16, void, (_Concurrent_queue_base_v4*,_Page*), (this,page))
1515 #else
1516 #define call__Concurrent_queue_base_v4__Move_item(this,dst,idx,src) CALL_VTBL_FUNC(this, \
1517 0, void, (_Concurrent_queue_base_v4*,_Page*,size_t,void*), (this,dst,idx,src))
1518 #define call__Concurrent_queue_base_v4__Copy_item(this,dst,idx,src) CALL_VTBL_FUNC(this, \
1519 4, void, (_Concurrent_queue_base_v4*,_Page*,size_t,const void*), (this,dst,idx,src))
1520 #define call__Concurrent_queue_base_v4__Assign_and_destroy_item(this,dst,src,idx) CALL_VTBL_FUNC(this, \
1521 8, void, (_Concurrent_queue_base_v4*,void*,_Page*,size_t), (this,dst,src,idx))
1522 #define call__Concurrent_queue_base_v4__Allocate_page(this) CALL_VTBL_FUNC(this, \
1523 16, _Page*, (_Concurrent_queue_base_v4*), (this))
1524 #define call__Concurrent_queue_base_v4__Deallocate_page(this, page) CALL_VTBL_FUNC(this, \
1525 20, void, (_Concurrent_queue_base_v4*,_Page*), (this,page))
1526 #endif
1528 /* ?_Internal_throw_exception@_Concurrent_queue_base_v4@details@Concurrency@@IBEXXZ */
1529 /* ?_Internal_throw_exception@_Concurrent_queue_base_v4@details@Concurrency@@IEBAXXZ */
1530 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4__Internal_throw_exception, 4)
1531 void __thiscall _Concurrent_queue_base_v4__Internal_throw_exception(
1532 const _Concurrent_queue_base_v4 *this)
1534 TRACE("(%p)\n", this);
1535 throw_exception(EXCEPTION_BAD_ALLOC, NULL);
1538 /* ??0_Concurrent_queue_base_v4@details@Concurrency@@IAE@I@Z */
1539 /* ??0_Concurrent_queue_base_v4@details@Concurrency@@IEAA@_K@Z */
1540 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4_ctor, 8)
1541 _Concurrent_queue_base_v4* __thiscall _Concurrent_queue_base_v4_ctor(
1542 _Concurrent_queue_base_v4 *this, size_t size)
1544 TRACE("(%p %Iu)\n", this, size);
1546 this->data = MSVCRT_operator_new(sizeof(*this->data));
1547 memset(this->data, 0, sizeof(*this->data));
1549 this->vtable = &MSVCP__Concurrent_queue_base_v4_vtable;
1550 this->item_size = size;
1552 /* alloc_count needs to be power of 2 */
1553 this->alloc_count =
1554 size <= 8 ? 32 :
1555 size <= 16 ? 16 :
1556 size <= 32 ? 8 :
1557 size <= 64 ? 4 :
1558 size <= 128 ? 2 : 1;
1559 return this;
1562 /* ??1_Concurrent_queue_base_v4@details@Concurrency@@MAE@XZ */
1563 /* ??1_Concurrent_queue_base_v4@details@Concurrency@@MEAA@XZ */
1564 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4_dtor, 4)
1565 void __thiscall _Concurrent_queue_base_v4_dtor(_Concurrent_queue_base_v4 *this)
1567 TRACE("(%p)\n", this);
1568 MSVCRT_operator_delete(this->data);
1571 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4_vector_dtor, 8)
1572 _Concurrent_queue_base_v4* __thiscall _Concurrent_queue_base_v4_vector_dtor(
1573 _Concurrent_queue_base_v4 *this, unsigned int flags)
1575 TRACE("(%p %x)\n", this, flags);
1576 if(flags & 2) {
1577 /* we have an array, with the number of elements stored before the first object */
1578 INT_PTR i, *ptr = (INT_PTR *)this-1;
1580 for(i=*ptr-1; i>=0; i--)
1581 _Concurrent_queue_base_v4_dtor(this+i);
1582 MSVCRT_operator_delete(ptr);
1583 } else {
1584 if(flags & 1)
1585 _Concurrent_queue_base_v4_dtor(this);
1586 MSVCRT_operator_delete(this);
1589 return this;
1592 /* ?_Internal_finish_clear@_Concurrent_queue_base_v4@details@Concurrency@@IAEXXZ */
1593 /* ?_Internal_finish_clear@_Concurrent_queue_base_v4@details@Concurrency@@IEAAXXZ */
1594 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4__Internal_finish_clear, 4)
1595 void __thiscall _Concurrent_queue_base_v4__Internal_finish_clear(
1596 _Concurrent_queue_base_v4 *this)
1598 int i;
1600 TRACE("(%p)\n", this);
1602 for(i=0; i<QUEUES_NO; i++)
1604 if(this->data->queues[i].tail)
1605 call__Concurrent_queue_base_v4__Deallocate_page(this, this->data->queues[i].tail);
1609 /* ?_Internal_empty@_Concurrent_queue_base_v4@details@Concurrency@@IBE_NXZ */
1610 /* ?_Internal_empty@_Concurrent_queue_base_v4@details@Concurrency@@IEBA_NXZ */
1611 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4__Internal_empty, 4)
1612 bool __thiscall _Concurrent_queue_base_v4__Internal_empty(
1613 const _Concurrent_queue_base_v4 *this)
1615 TRACE("(%p)\n", this);
1616 return this->data->head_pos == this->data->tail_pos;
1619 /* ?_Internal_size@_Concurrent_queue_base_v4@details@Concurrency@@IBEIXZ */
1620 /* ?_Internal_size@_Concurrent_queue_base_v4@details@Concurrency@@IEBA_KXZ */
1621 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4__Internal_size, 4)
1622 size_t __thiscall _Concurrent_queue_base_v4__Internal_size(
1623 const _Concurrent_queue_base_v4 *this)
1625 TRACE("(%p)\n", this);
1626 return this->data->tail_pos - this->data->head_pos;
1629 static void spin_wait(int *counter)
1631 static int spin_limit = -1;
1633 if(spin_limit == -1)
1635 SYSTEM_INFO si;
1636 GetSystemInfo(&si);
1637 spin_limit = si.dwNumberOfProcessors>1 ? 4000 : 0;
1640 if(*counter >= spin_limit)
1642 *counter = 0;
1643 Sleep(0);
1645 else
1647 (*counter)++;
1651 #ifdef _WIN64
1652 static size_t InterlockedIncrementSizeT(size_t volatile *dest)
1654 size_t v;
1658 v = *dest;
1659 } while(InterlockedCompareExchange64((LONGLONG*)dest, v+1, v) != v);
1661 return v+1;
1663 #else
1664 #define InterlockedIncrementSizeT(dest) InterlockedIncrement((LONG*)dest)
1665 #endif
1667 static void CALLBACK queue_push_finally(BOOL normal, void *ctx)
1669 threadsafe_queue *queue = ctx;
1670 InterlockedIncrementSizeT(&queue->tail_pos);
1673 static void threadsafe_queue_push(threadsafe_queue *queue, size_t id,
1674 void *e, _Concurrent_queue_base_v4 *parent, BOOL copy)
1676 size_t page_id = id & ~(parent->alloc_count-1);
1677 int spin;
1678 _Page *p;
1680 spin = 0;
1681 while(queue->tail_pos != id)
1682 spin_wait(&spin);
1684 if(page_id == id)
1686 /* TODO: Add exception handling */
1687 p = call__Concurrent_queue_base_v4__Allocate_page(parent);
1688 p->_Next = NULL;
1689 p->_Mask = 0;
1691 spin = 0;
1692 while(InterlockedCompareExchange(&queue->lock, 1, 0))
1693 spin_wait(&spin);
1694 if(queue->tail)
1695 queue->tail->_Next = p;
1696 queue->tail = p;
1697 if(!queue->head)
1698 queue->head = p;
1699 queue->lock = 0;
1701 else
1703 p = queue->tail;
1706 __TRY
1708 if(copy)
1709 call__Concurrent_queue_base_v4__Copy_item(parent, p, id-page_id, e);
1710 else
1711 call__Concurrent_queue_base_v4__Move_item(parent, p, id-page_id, e);
1712 p->_Mask |= 1 << (id - page_id);
1714 __FINALLY_CTX(queue_push_finally, queue);
1717 static BOOL threadsafe_queue_pop(threadsafe_queue *queue, size_t id,
1718 void *e, _Concurrent_queue_base_v4 *parent)
1720 size_t page_id = id & ~(parent->alloc_count-1);
1721 int spin;
1722 _Page *p;
1723 BOOL ret = FALSE;
1725 spin = 0;
1726 while(queue->tail_pos <= id)
1727 spin_wait(&spin);
1729 spin = 0;
1730 while(queue->head_pos != id)
1731 spin_wait(&spin);
1733 p = queue->head;
1734 if(p->_Mask & (1 << (id-page_id)))
1736 /* TODO: Add exception handling */
1737 call__Concurrent_queue_base_v4__Assign_and_destroy_item(parent, e, p, id-page_id);
1738 ret = TRUE;
1741 if(id == page_id+parent->alloc_count-1)
1743 spin = 0;
1744 while(InterlockedCompareExchange(&queue->lock, 1, 0))
1745 spin_wait(&spin);
1746 queue->head = p->_Next;
1747 if(!queue->head)
1748 queue->tail = NULL;
1749 queue->lock = 0;
1751 /* TODO: Add exception handling */
1752 call__Concurrent_queue_base_v4__Deallocate_page(parent, p);
1755 InterlockedIncrementSizeT(&queue->head_pos);
1756 return ret;
1759 /* ?_Internal_push@_Concurrent_queue_base_v4@details@Concurrency@@IAEXPBX@Z */
1760 /* ?_Internal_push@_Concurrent_queue_base_v4@details@Concurrency@@IEAAXPEBX@Z */
1761 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4__Internal_push, 8)
1762 void __thiscall _Concurrent_queue_base_v4__Internal_push(
1763 _Concurrent_queue_base_v4 *this, void *e)
1765 size_t id;
1767 TRACE("(%p %p)\n", this, e);
1769 id = InterlockedIncrementSizeT(&this->data->tail_pos)-1;
1770 threadsafe_queue_push(this->data->queues + id % QUEUES_NO,
1771 id / QUEUES_NO, e, this, TRUE);
1774 /* ?_Internal_move_push@_Concurrent_queue_base_v4@details@Concurrency@@IAEXPAX@Z */
1775 /* ?_Internal_move_push@_Concurrent_queue_base_v4@details@Concurrency@@IEAAXPEAX@Z */
1776 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4__Internal_move_push, 8)
1777 void __thiscall _Concurrent_queue_base_v4__Internal_move_push(
1778 _Concurrent_queue_base_v4 *this, void *e)
1780 size_t id;
1782 TRACE("(%p %p)\n", this, e);
1784 id = InterlockedIncrementSizeT(&this->data->tail_pos)-1;
1785 threadsafe_queue_push(this->data->queues + id % QUEUES_NO,
1786 id / QUEUES_NO, e, this, FALSE);
1789 /* ?_Internal_pop_if_present@_Concurrent_queue_base_v4@details@Concurrency@@IAE_NPAX@Z */
1790 /* ?_Internal_pop_if_present@_Concurrent_queue_base_v4@details@Concurrency@@IEAA_NPEAX@Z */
1791 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4__Internal_pop_if_present, 8)
1792 bool __thiscall _Concurrent_queue_base_v4__Internal_pop_if_present(
1793 _Concurrent_queue_base_v4 *this, void *e)
1795 size_t id;
1797 TRACE("(%p %p)\n", this, e);
1803 id = this->data->head_pos;
1804 if(id == this->data->tail_pos) return FALSE;
1805 } while(InterlockedCompareExchangePointer((void**)&this->data->head_pos,
1806 (void*)(id+1), (void*)id) != (void*)id);
1807 } while(!threadsafe_queue_pop(this->data->queues + id % QUEUES_NO,
1808 id / QUEUES_NO, e, this));
1809 return TRUE;
1812 /* ?_Internal_swap@_Concurrent_queue_base_v4@details@Concurrency@@IAEXAAV123@@Z */
1813 /* ?_Internal_swap@_Concurrent_queue_base_v4@details@Concurrency@@IEAAXAEAV123@@Z */
1814 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4__Internal_swap, 8)
1815 void __thiscall _Concurrent_queue_base_v4__Internal_swap(
1816 _Concurrent_queue_base_v4 *this, _Concurrent_queue_base_v4 *r)
1818 FIXME("(%p %p) stub\n", this, r);
1821 DEFINE_THISCALL_WRAPPER(_Concurrent_queue_base_v4_dummy, 4)
1822 void __thiscall _Concurrent_queue_base_v4_dummy(_Concurrent_queue_base_v4 *this)
1824 ERR("unexpected call\n");
1827 DEFINE_RTTI_DATA0(_Concurrent_queue_base_v4, 0, ".?AV_Concurrent_queue_base_v4@details@Concurrency@@")
1829 static int _Runtime_object_id;
1831 typedef struct
1833 const vtable_ptr *vtable;
1834 int id;
1835 } _Runtime_object;
1837 extern const vtable_ptr MSVCP__Runtime_object_vtable;
1839 /* ??0_Runtime_object@details@Concurrency@@QAE@H@Z */
1840 /* ??0_Runtime_object@details@Concurrency@@QEAA@H@Z */
1841 DEFINE_THISCALL_WRAPPER(_Runtime_object_ctor_id, 8)
1842 _Runtime_object* __thiscall _Runtime_object_ctor_id(_Runtime_object *this, int id)
1844 TRACE("(%p %d)\n", this, id);
1845 this->vtable = &MSVCP__Runtime_object_vtable;
1846 this->id = id;
1847 return this;
1850 /* ??0_Runtime_object@details@Concurrency@@QAE@XZ */
1851 /* ??0_Runtime_object@details@Concurrency@@QEAA@XZ */
1852 DEFINE_THISCALL_WRAPPER(_Runtime_object_ctor, 4)
1853 _Runtime_object* __thiscall _Runtime_object_ctor(_Runtime_object *this)
1855 TRACE("(%p)\n", this);
1856 this->vtable = &MSVCP__Runtime_object_vtable;
1857 this->id = InterlockedExchangeAdd(&_Runtime_object_id, 2);
1858 return this;
1861 DEFINE_THISCALL_WRAPPER(_Runtime_object__GetId, 4)
1862 int __thiscall _Runtime_object__GetId(_Runtime_object *this)
1864 TRACE("(%p)\n", this);
1865 return this->id;
1868 DEFINE_RTTI_DATA0(_Runtime_object, 0, ".?AV_Runtime_object@details@Concurrency@@")
1870 #endif
1872 #if _MSVCP_VER >= 100
1873 typedef struct __Concurrent_vector_base_v4
1875 void* (__cdecl *allocator)(struct __Concurrent_vector_base_v4 *, size_t);
1876 void *storage[3];
1877 size_t first_block;
1878 size_t early_size;
1879 void **segment;
1880 } _Concurrent_vector_base_v4;
1882 #define STORAGE_SIZE ARRAY_SIZE(this->storage)
1883 #define SEGMENT_SIZE (sizeof(void*) * 8)
1885 typedef struct compact_block
1887 size_t first_block;
1888 void *blocks[SEGMENT_SIZE];
1889 int size_check;
1890 }compact_block;
1892 /* Return the integer base-2 logarithm of (x|1). Result is 0 for x == 0. */
1893 static inline unsigned int log2i(unsigned int x)
1895 unsigned int index;
1896 BitScanReverse(&index, x|1);
1897 return index;
1900 /* ?_Segment_index_of@_Concurrent_vector_base_v4@details@Concurrency@@KAII@Z */
1901 /* ?_Segment_index_of@_Concurrent_vector_base_v4@details@Concurrency@@KA_K_K@Z */
1902 size_t __cdecl _vector_base_v4__Segment_index_of(size_t x)
1904 unsigned int half;
1906 TRACE("(%Iu)\n", x);
1908 if((sizeof(x) == 8) && (half = x >> 32))
1909 return log2i(half) + 32;
1911 return log2i(x);
1914 /* ?_Internal_throw_exception@_Concurrent_vector_base_v4@details@Concurrency@@IBEXI@Z */
1915 /* ?_Internal_throw_exception@_Concurrent_vector_base_v4@details@Concurrency@@IEBAX_K@Z */
1916 DEFINE_THISCALL_WRAPPER(_vector_base_v4__Internal_throw_exception, 8)
1917 void __thiscall _vector_base_v4__Internal_throw_exception(void/*_vector_base_v4*/ *this, size_t idx)
1919 static const struct {
1920 exception_type type;
1921 const char *msg;
1922 } exceptions[] = {
1923 { EXCEPTION_OUT_OF_RANGE, "Index out of range" },
1924 { EXCEPTION_OUT_OF_RANGE, "Index out of segments table range" },
1925 { EXCEPTION_RANGE_ERROR, "Index is inside segment which failed to be allocated" },
1928 TRACE("(%p %Iu)\n", this, idx);
1930 if(idx < ARRAY_SIZE(exceptions))
1931 throw_exception(exceptions[idx].type, exceptions[idx].msg);
1934 #ifdef _WIN64
1935 #define InterlockedCompareExchangeSizeT(dest, exchange, cmp) InterlockedCompareExchangeSize((size_t *)dest, (size_t)exchange, (size_t)cmp)
1936 static size_t InterlockedCompareExchangeSize(size_t volatile *dest, size_t exchange, size_t cmp)
1938 size_t v;
1940 v = InterlockedCompareExchange64((LONGLONG*)dest, exchange, cmp);
1942 return v;
1944 #else
1945 #define InterlockedCompareExchangeSizeT(dest, exchange, cmp) InterlockedCompareExchange((LONG*)dest, (size_t)exchange, (size_t)cmp)
1946 #endif
1948 #define SEGMENT_ALLOC_MARKER ((void*)1)
1950 static void concurrent_vector_alloc_segment(_Concurrent_vector_base_v4 *this,
1951 size_t seg, size_t element_size)
1953 int spin;
1955 while(!this->segment[seg] || this->segment[seg] == SEGMENT_ALLOC_MARKER)
1957 spin = 0;
1958 while(this->segment[seg] == SEGMENT_ALLOC_MARKER)
1959 spin_wait(&spin);
1960 if(!InterlockedCompareExchangeSizeT((this->segment + seg),
1961 SEGMENT_ALLOC_MARKER, 0))
1962 __TRY
1964 if(seg == 0)
1965 this->segment[seg] = this->allocator(this, element_size * (1 << this->first_block));
1966 else if(seg < this->first_block)
1967 this->segment[seg] = (BYTE**)this->segment[0]
1968 + element_size * (1 << seg);
1969 else
1970 this->segment[seg] = this->allocator(this, element_size * (1 << seg));
1972 __EXCEPT_ALL
1974 this->segment[seg] = NULL;
1975 throw_exception(EXCEPTION_RERAISE, NULL);
1977 __ENDTRY
1978 if(!this->segment[seg])
1979 _vector_base_v4__Internal_throw_exception(this, 2);
1983 /* ??1_Concurrent_vector_base_v4@details@Concurrency@@IAE@XZ */
1984 /* ??1_Concurrent_vector_base_v4@details@Concurrency@@IEAA@XZ */
1985 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4_dtor, 4)
1986 void __thiscall _Concurrent_vector_base_v4_dtor(
1987 _Concurrent_vector_base_v4 *this)
1989 TRACE("(%p)\n", this);
1991 if(this->segment != this->storage)
1992 free(this->segment);
1995 /* ?_Internal_capacity@_Concurrent_vector_base_v4@details@Concurrency@@IBEIXZ */
1996 /* ?_Internal_capacity@_Concurrent_vector_base_v4@details@Concurrency@@IEBA_KXZ */
1997 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_capacity, 4)
1998 size_t __thiscall _Concurrent_vector_base_v4__Internal_capacity(
1999 const _Concurrent_vector_base_v4 *this)
2001 size_t last_block;
2002 int i;
2004 TRACE("(%p)\n", this);
2006 last_block = (this->segment == this->storage ? STORAGE_SIZE : SEGMENT_SIZE);
2007 for(i = 0; i < last_block; i++)
2009 if(!this->segment[i])
2010 return !i ? 0 : 1 << i;
2012 return 1 << i;
2015 /* ?_Internal_reserve@_Concurrent_vector_base_v4@details@Concurrency@@IAEXIII@Z */
2016 /* ?_Internal_reserve@_Concurrent_vector_base_v4@details@Concurrency@@IEAAX_K00@Z */
2017 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_reserve, 16)
2018 void __thiscall _Concurrent_vector_base_v4__Internal_reserve(
2019 _Concurrent_vector_base_v4 *this, size_t size,
2020 size_t element_size, size_t max_size)
2022 size_t block_idx, capacity;
2023 int i;
2024 void **new_segment;
2026 TRACE("(%p %Iu %Iu %Iu)\n", this, size, element_size, max_size);
2028 if(size > max_size) _vector_base_v4__Internal_throw_exception(this, 0);
2029 capacity = _Concurrent_vector_base_v4__Internal_capacity(this);
2030 if(size <= capacity) return;
2031 block_idx = _vector_base_v4__Segment_index_of(size - 1);
2032 if(!this->first_block)
2033 InterlockedCompareExchangeSizeT(&this->first_block, block_idx + 1, 0);
2034 i = _vector_base_v4__Segment_index_of(capacity);
2035 if(this->storage == this->segment) {
2036 for(; i <= block_idx && i < STORAGE_SIZE; i++)
2037 concurrent_vector_alloc_segment(this, i, element_size);
2038 if(block_idx >= STORAGE_SIZE) {
2039 new_segment = malloc(SEGMENT_SIZE * sizeof(void*));
2040 if(new_segment == NULL) _vector_base_v4__Internal_throw_exception(this, 2);
2041 memset(new_segment, 0, SEGMENT_SIZE * sizeof(*new_segment));
2042 memcpy(new_segment, this->storage, STORAGE_SIZE * sizeof(*new_segment));
2043 if(InterlockedCompareExchangePointer((void*)&this->segment, new_segment,
2044 this->storage) != this->storage)
2045 free(new_segment);
2048 for(; i <= block_idx; i++)
2049 concurrent_vector_alloc_segment(this, i, element_size);
2052 /* ?_Internal_clear@_Concurrent_vector_base_v4@details@Concurrency@@IAEIP6AXPAXI@Z@Z */
2053 /* ?_Internal_clear@_Concurrent_vector_base_v4@details@Concurrency@@IEAA_KP6AXPEAX_K@Z@Z */
2054 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_clear, 8)
2055 size_t __thiscall _Concurrent_vector_base_v4__Internal_clear(
2056 _Concurrent_vector_base_v4 *this, void (__cdecl *clear)(void*, size_t))
2058 size_t seg_no, elems;
2059 int i;
2061 TRACE("(%p %p)\n", this, clear);
2063 seg_no = this->early_size ? _vector_base_v4__Segment_index_of(this->early_size) + 1 : 0;
2064 for(i = seg_no - 1; i >= 0; i--) {
2065 elems = this->early_size - (1 << i & ~1);
2066 clear(this->segment[i], elems);
2067 this->early_size -= elems;
2069 while(seg_no < (this->segment == this->storage ? STORAGE_SIZE : SEGMENT_SIZE)) {
2070 if(!this->segment[seg_no]) break;
2071 seg_no++;
2073 return seg_no;
2076 /* ?_Internal_compact@_Concurrent_vector_base_v4@details@Concurrency@@IAEPAXIPAXP6AX0I@ZP6AX0PBXI@Z@Z */
2077 /* ?_Internal_compact@_Concurrent_vector_base_v4@details@Concurrency@@IEAAPEAX_KPEAXP6AX10@ZP6AX1PEBX0@Z@Z */
2078 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_compact, 20)
2079 void * __thiscall _Concurrent_vector_base_v4__Internal_compact(
2080 _Concurrent_vector_base_v4 *this, size_t element_size, void *v,
2081 void (__cdecl *clear)(void*, size_t),
2082 void (__cdecl *copy)(void*, const void*, size_t))
2084 compact_block *b;
2085 size_t size, alloc_size, seg_no, alloc_seg, copy_element, clear_element;
2086 int i;
2088 TRACE("(%p %Iu %p %p %p)\n", this, element_size, v, clear, copy);
2090 size = this->early_size;
2091 alloc_size = _Concurrent_vector_base_v4__Internal_capacity(this);
2092 if(alloc_size == 0) return NULL;
2093 alloc_seg = _vector_base_v4__Segment_index_of(alloc_size - 1);
2094 if(!size) {
2095 this->first_block = 0;
2096 b = v;
2097 b->first_block = alloc_seg + 1;
2098 memset(b->blocks, 0, sizeof(b->blocks));
2099 memcpy(b->blocks, this->segment,
2100 (alloc_seg + 1) * sizeof(this->segment[0]));
2101 memset(this->segment, 0, sizeof(this->segment[0]) * (alloc_seg + 1));
2102 return v;
2104 seg_no = _vector_base_v4__Segment_index_of(size - 1);
2105 if(this->first_block == (seg_no + 1) && seg_no == alloc_seg) return NULL;
2106 b = v;
2107 b->first_block = this->first_block;
2108 memset(b->blocks, 0, sizeof(b->blocks));
2109 memcpy(b->blocks, this->segment,
2110 (alloc_seg + 1) * sizeof(this->segment[0]));
2111 if(this->first_block == (seg_no + 1) && seg_no != alloc_seg) {
2112 memset(b->blocks, 0, sizeof(b->blocks[0]) * (seg_no + 1));
2113 memset(&this->segment[seg_no + 1], 0, sizeof(this->segment[0]) * (alloc_seg - seg_no));
2114 return v;
2116 memset(this->segment, 0,
2117 (alloc_seg + 1) * sizeof(this->segment[0]));
2118 this->first_block = 0;
2119 _Concurrent_vector_base_v4__Internal_reserve(this, size, element_size,
2120 MSVCP_SIZE_T_MAX / element_size);
2121 for(i = 0; i < seg_no; i++)
2122 copy(this->segment[i], b->blocks[i], i ? 1 << i : 2);
2123 copy_element = size - ((1 << seg_no) & ~1);
2124 if(copy_element > 0)
2125 copy(this->segment[seg_no], b->blocks[seg_no], copy_element);
2126 for(i = 0; i < seg_no; i++)
2127 clear(b->blocks[i], i ? 1 << i : 2);
2128 clear_element = size - ((1 << seg_no) & ~1);
2129 if(clear_element > 0)
2130 clear(b->blocks[seg_no], clear_element);
2131 return v;
2134 /* ?_Internal_copy@_Concurrent_vector_base_v4@details@Concurrency@@IAEXABV123@IP6AXPAXPBXI@Z@Z */
2135 /* ?_Internal_copy@_Concurrent_vector_base_v4@details@Concurrency@@IEAAXAEBV123@_KP6AXPEAXPEBX1@Z@Z */
2136 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_copy, 16)
2137 void __thiscall _Concurrent_vector_base_v4__Internal_copy(
2138 _Concurrent_vector_base_v4 *this, const _Concurrent_vector_base_v4 *v,
2139 size_t element_size, void (__cdecl *copy)(void*, const void*, size_t))
2141 size_t seg_no, v_size;
2142 int i;
2144 TRACE("(%p %p %Iu %p)\n", this, v, element_size, copy);
2146 v_size = v->early_size;
2147 if(!v_size) {
2148 this->early_size = 0;
2149 return;
2151 _Concurrent_vector_base_v4__Internal_reserve(this, v_size,
2152 element_size, MSVCP_SIZE_T_MAX / element_size);
2153 seg_no = _vector_base_v4__Segment_index_of(v_size - 1);
2154 for(i = 0; i < seg_no; i++)
2155 copy(this->segment[i], v->segment[i], i ? 1 << i : 2);
2156 copy(this->segment[i], v->segment[i], v_size - (1 << i & ~1));
2157 this->early_size = v_size;
2160 /* ?_Internal_assign@_Concurrent_vector_base_v4@details@Concurrency@@IAEXABV123@IP6AXPAXI@ZP6AX1PBXI@Z4@Z */
2161 /* ?_Internal_assign@_Concurrent_vector_base_v4@details@Concurrency@@IEAAXAEBV123@_KP6AXPEAX1@ZP6AX2PEBX1@Z5@Z */
2162 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_assign, 24)
2163 void __thiscall _Concurrent_vector_base_v4__Internal_assign(
2164 _Concurrent_vector_base_v4 *this, const _Concurrent_vector_base_v4 *v,
2165 size_t element_size, void (__cdecl *clear)(void*, size_t),
2166 void (__cdecl *assign)(void*, const void*, size_t),
2167 void (__cdecl *copy)(void*, const void*, size_t))
2169 size_t v_size, seg_no, v_seg_no, remain_element;
2170 int i;
2172 TRACE("(%p %p %Iu %p %p %p)\n", this, v, element_size, clear, assign, copy);
2174 v_size = v->early_size;
2175 if(!v_size) {
2176 _Concurrent_vector_base_v4__Internal_clear(this, clear);
2177 return;
2179 if(!this->early_size) {
2180 _Concurrent_vector_base_v4__Internal_copy(this, v, element_size, copy);
2181 return;
2183 seg_no = _vector_base_v4__Segment_index_of(this->early_size - 1);
2184 v_seg_no = _vector_base_v4__Segment_index_of(v_size - 1);
2186 for(i = 0; i < min(seg_no, v_seg_no); i++)
2187 assign(this->segment[i], v->segment[i], i ? 1 << i : 2);
2188 remain_element = min(this->early_size, v_size) - (1 << i & ~1);
2189 if(remain_element != 0)
2190 assign(this->segment[i], v->segment[i], remain_element);
2192 if(this->early_size > v_size)
2194 if((i ? 1 << i : 2) - remain_element > 0)
2195 clear((BYTE**)this->segment[i] + element_size * remain_element,
2196 (i ? 1 << i : 2) - remain_element);
2197 if(i < seg_no)
2199 for(i++; i < seg_no; i++)
2200 clear(this->segment[i], 1 << i);
2201 clear(this->segment[i], this->early_size - (1 << i));
2204 else if(this->early_size < v_size)
2206 if((i ? 1 << i : 2) - remain_element > 0)
2207 copy((BYTE**)this->segment[i] + element_size * remain_element,
2208 (BYTE**)v->segment[i] + element_size * remain_element,
2209 (i ? 1 << i : 2) - remain_element);
2210 if(i < v_seg_no)
2212 _Concurrent_vector_base_v4__Internal_reserve(this, v_size,
2213 element_size, MSVCP_SIZE_T_MAX / element_size);
2214 for(i++; i < v_seg_no; i++)
2215 copy(this->segment[i], v->segment[i], 1 << i);
2216 copy(this->segment[i], v->segment[i], v->early_size - (1 << i));
2219 this->early_size = v_size;
2222 /* ?_Internal_grow_by@_Concurrent_vector_base_v4@details@Concurrency@@IAEIIIP6AXPAXPBXI@Z1@Z */
2223 /* ?_Internal_grow_by@_Concurrent_vector_base_v4@details@Concurrency@@IEAA_K_K0P6AXPEAXPEBX0@Z2@Z */
2224 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_grow_by, 20)
2225 size_t __thiscall _Concurrent_vector_base_v4__Internal_grow_by(
2226 _Concurrent_vector_base_v4 *this, size_t count, size_t element_size,
2227 void (__cdecl *copy)(void*, const void*, size_t), const void *v)
2229 size_t size, seg_no, last_seg_no, remain_size;
2231 TRACE("(%p %Iu %Iu %p %p)\n", this, count, element_size, copy, v);
2233 if(count == 0) return this->early_size;
2234 do {
2235 size = this->early_size;
2236 _Concurrent_vector_base_v4__Internal_reserve(this, size + count, element_size,
2237 MSVCP_SIZE_T_MAX / element_size);
2238 } while(InterlockedCompareExchangeSizeT(&this->early_size, size + count, size) != size);
2240 seg_no = size ? _vector_base_v4__Segment_index_of(size - 1) : 0;
2241 last_seg_no = _vector_base_v4__Segment_index_of(size + count - 1);
2242 remain_size = min(size + count, 1 << (seg_no + 1)) - size;
2243 if(remain_size > 0)
2244 copy(((BYTE**)this->segment[seg_no] + element_size * (size - ((1 << seg_no) & ~1))), v,
2245 remain_size);
2246 if(seg_no != last_seg_no)
2248 for(seg_no++; seg_no < last_seg_no; seg_no++)
2249 copy(this->segment[seg_no], v, 1 << seg_no);
2250 copy(this->segment[last_seg_no], v, size + count - (1 << last_seg_no));
2252 return size;
2255 /* ?_Internal_grow_to_at_least_with_result@_Concurrent_vector_base_v4@details@Concurrency@@IAEIIIP6AXPAXPBXI@Z1@Z */
2256 /* ?_Internal_grow_to_at_least_with_result@_Concurrent_vector_base_v4@details@Concurrency@@IEAA_K_K0P6AXPEAXPEBX0@Z2@Z */
2257 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_grow_to_at_least_with_result, 20)
2258 size_t __thiscall _Concurrent_vector_base_v4__Internal_grow_to_at_least_with_result(
2259 _Concurrent_vector_base_v4 *this, size_t count, size_t element_size,
2260 void (__cdecl *copy)(void*, const void*, size_t), const void *v)
2262 size_t size, seg_no, last_seg_no, remain_size;
2264 TRACE("(%p %Iu %Iu %p %p)\n", this, count, element_size, copy, v);
2266 _Concurrent_vector_base_v4__Internal_reserve(this, count, element_size,
2267 MSVCP_SIZE_T_MAX / element_size);
2268 do {
2269 size = this->early_size;
2270 if(size >= count) return size;
2271 } while(InterlockedCompareExchangeSizeT(&this->early_size, count, size) != size);
2273 seg_no = size ? _vector_base_v4__Segment_index_of(size - 1) : 0;
2274 last_seg_no = _vector_base_v4__Segment_index_of(count - 1);
2275 remain_size = min(count, 1 << (seg_no + 1)) - size;
2276 if(remain_size > 0)
2277 copy(((BYTE**)this->segment[seg_no] + element_size * (size - ((1 << seg_no) & ~1))), v,
2278 remain_size);
2279 if(seg_no != last_seg_no)
2281 for(seg_no++; seg_no < last_seg_no; seg_no++)
2282 copy(this->segment[seg_no], v, 1 << seg_no);
2283 copy(this->segment[last_seg_no], v, count - (1 << last_seg_no));
2285 return size;
2288 /* ?_Internal_push_back@_Concurrent_vector_base_v4@details@Concurrency@@IAEPAXIAAI@Z */
2289 /* ?_Internal_push_back@_Concurrent_vector_base_v4@details@Concurrency@@IEAAPEAX_KAEA_K@Z */
2290 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_push_back, 12)
2291 void * __thiscall _Concurrent_vector_base_v4__Internal_push_back(
2292 _Concurrent_vector_base_v4 *this, size_t element_size, size_t *idx)
2294 size_t index, seg, segment_base;
2295 void *data;
2297 TRACE("(%p %Iu %p)\n", this, element_size, idx);
2299 do {
2300 index = this->early_size;
2301 _Concurrent_vector_base_v4__Internal_reserve(this, index + 1,
2302 element_size, MSVCP_SIZE_T_MAX / element_size);
2303 } while(InterlockedCompareExchangeSizeT(&this->early_size, index + 1, index) != index);
2304 seg = _vector_base_v4__Segment_index_of(index);
2305 segment_base = (seg == 0) ? 0 : (1 << seg);
2306 data = (BYTE*)this->segment[seg] + element_size * (index - segment_base);
2307 *idx = index;
2309 return data;
2312 /* ?_Internal_resize@_Concurrent_vector_base_v4@details@Concurrency@@IAEXIIIP6AXPAXI@ZP6AX0PBXI@Z2@Z */
2313 /* ?_Internal_resize@_Concurrent_vector_base_v4@details@Concurrency@@IEAAX_K00P6AXPEAX0@ZP6AX1PEBX0@Z3@Z */
2314 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_resize, 28)
2315 void __thiscall _Concurrent_vector_base_v4__Internal_resize(
2316 _Concurrent_vector_base_v4 *this, size_t resize, size_t element_size,
2317 size_t max_size, void (__cdecl *clear)(void*, size_t),
2318 void (__cdecl *copy)(void*, const void*, size_t), const void *v)
2320 size_t size, seg_no, end_seg_no, clear_element;
2322 TRACE("(%p %Iu %Iu %Iu %p %p %p)\n", this, resize, element_size, max_size, clear, copy, v);
2324 if(resize > max_size) _vector_base_v4__Internal_throw_exception(this, 0);
2325 size = this->early_size;
2326 if(resize > size)
2327 _Concurrent_vector_base_v4__Internal_grow_to_at_least_with_result(this,
2328 resize, element_size, copy, v);
2329 else if(resize == 0)
2330 _Concurrent_vector_base_v4__Internal_clear(this, clear);
2331 else if(resize < size)
2333 seg_no = _vector_base_v4__Segment_index_of(size - 1);
2334 end_seg_no = _vector_base_v4__Segment_index_of(resize - 1);
2335 clear_element = size - (seg_no ? 1 << seg_no : 2);
2336 if(clear_element > 0)
2337 clear(this->segment[seg_no], clear_element);
2338 if(seg_no) seg_no--;
2339 for(; seg_no > end_seg_no; seg_no--)
2340 clear(this->segment[seg_no], 1 << seg_no);
2341 clear_element = (1 << (end_seg_no + 1)) - resize;
2342 if(clear_element > 0)
2343 clear((BYTE**)this->segment[end_seg_no] + element_size * (resize - ((1 << end_seg_no) & ~1)),
2344 clear_element);
2345 this->early_size = resize;
2349 /* ?_Internal_swap@_Concurrent_vector_base_v4@details@Concurrency@@IAEXAAV123@@Z */
2350 /* ?_Internal_swap@_Concurrent_vector_base_v4@details@Concurrency@@IEAAXAEAV123@@Z */
2351 DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_swap, 8)
2352 void __thiscall _Concurrent_vector_base_v4__Internal_swap(
2353 _Concurrent_vector_base_v4 *this, _Concurrent_vector_base_v4 *v)
2355 _Concurrent_vector_base_v4 temp;
2357 TRACE("(%p %p)\n", this, v);
2359 temp = *this;
2360 *this = *v;
2361 *v = temp;
2362 if(v->segment == this->storage)
2363 v->segment = v->storage;
2364 if(this->segment == v->storage)
2365 this->segment = this->storage;
2367 #endif
2369 __ASM_BLOCK_BEGIN(vtables)
2370 #if _MSVCP_VER == 100
2371 __ASM_VTABLE(iostream_category,
2372 VTABLE_ADD_FUNC(custom_category_vector_dtor)
2373 VTABLE_ADD_FUNC(custom_category_name)
2374 VTABLE_ADD_FUNC(iostream_category_message)
2375 VTABLE_ADD_FUNC(custom_category_default_error_condition)
2376 VTABLE_ADD_FUNC(custom_category_equivalent)
2377 VTABLE_ADD_FUNC(custom_category_equivalent_code));
2378 __ASM_VTABLE(system_category,
2379 VTABLE_ADD_FUNC(custom_category_vector_dtor)
2380 VTABLE_ADD_FUNC(custom_category_name)
2381 VTABLE_ADD_FUNC(custom_category_message)
2382 VTABLE_ADD_FUNC(custom_category_default_error_condition)
2383 VTABLE_ADD_FUNC(custom_category_equivalent)
2384 VTABLE_ADD_FUNC(custom_category_equivalent_code));
2385 __ASM_VTABLE(generic_category,
2386 VTABLE_ADD_FUNC(custom_category_vector_dtor)
2387 VTABLE_ADD_FUNC(custom_category_name)
2388 VTABLE_ADD_FUNC(custom_category_message)
2389 VTABLE_ADD_FUNC(custom_category_default_error_condition)
2390 VTABLE_ADD_FUNC(custom_category_equivalent)
2391 VTABLE_ADD_FUNC(custom_category_equivalent_code));
2392 #endif
2393 #if _MSVCP_VER >= 100
2394 __ASM_VTABLE(_Concurrent_queue_base_v4,
2395 #if _MSVCP_VER >= 110
2396 VTABLE_ADD_FUNC(_Concurrent_queue_base_v4_dummy)
2397 #endif
2398 VTABLE_ADD_FUNC(_Concurrent_queue_base_v4_dummy)
2399 VTABLE_ADD_FUNC(_Concurrent_queue_base_v4_dummy)
2400 VTABLE_ADD_FUNC(_Concurrent_queue_base_v4_vector_dtor)
2401 VTABLE_ADD_FUNC(_Concurrent_queue_base_v4_dummy)
2402 VTABLE_ADD_FUNC(_Concurrent_queue_base_v4_dummy));
2403 __ASM_VTABLE(_Runtime_object,
2404 VTABLE_ADD_FUNC(_Runtime_object__GetId));
2405 #endif
2406 #if _MSVCP_VER >= 110
2407 __ASM_VTABLE(_Pad,
2408 VTABLE_ADD_FUNC(_Pad__Go));
2409 #endif
2410 __ASM_BLOCK_END
2412 /*********************************************************************
2413 * __crtInitializeCriticalSectionEx (MSVCP140.@)
2415 BOOL CDECL MSVCP__crtInitializeCriticalSectionEx(
2416 CRITICAL_SECTION *cs, DWORD spin_count, DWORD flags)
2418 TRACE("(%p %x %x)\n", cs, spin_count, flags);
2419 return InitializeCriticalSectionEx(cs, spin_count, flags);
2422 /*********************************************************************
2423 * __crtCreateEventExW (MSVCP140.@)
2425 HANDLE CDECL MSVCP__crtCreateEventExW(
2426 SECURITY_ATTRIBUTES *attribs, LPCWSTR name, DWORD flags, DWORD access)
2428 TRACE("(%p %s 0x%08x 0x%08x)\n", attribs, debugstr_w(name), flags, access);
2429 return CreateEventExW(attribs, name, flags, access);
2432 /*********************************************************************
2433 * __crtGetTickCount64 (MSVCP140.@)
2435 ULONGLONG CDECL MSVCP__crtGetTickCount64(void)
2437 return GetTickCount64();
2440 /*********************************************************************
2441 * __crtGetCurrentProcessorNumber (MSVCP140.@)
2443 DWORD CDECL MSVCP__crtGetCurrentProcessorNumber(void)
2445 return GetCurrentProcessorNumber();
2448 /*********************************************************************
2449 * __crtFlushProcessWriteBuffers (MSVCP140.@)
2451 VOID CDECL MSVCP__crtFlushProcessWriteBuffers(void)
2453 return FlushProcessWriteBuffers();
2456 /*********************************************************************
2457 * __crtCreateSemaphoreExW (MSVCP140.@)
2459 HANDLE CDECL MSVCP__crtCreateSemaphoreExW(
2460 SECURITY_ATTRIBUTES *attribs, LONG initial_count, LONG max_count, LPCWSTR name,
2461 DWORD flags, DWORD access)
2463 TRACE("(%p %d %d %s 0x%08x 0x%08x)\n", attribs, initial_count, max_count, debugstr_w(name),
2464 flags, access);
2465 return CreateSemaphoreExW(attribs, initial_count, max_count, name, flags, access);
2468 /*********************************************************************
2469 * __crtCreateThreadpoolTimer (MSVCP140.@)
2471 PTP_TIMER CDECL MSVCP__crtCreateThreadpoolTimer(PTP_TIMER_CALLBACK callback,
2472 PVOID userdata, TP_CALLBACK_ENVIRON *environment)
2474 TRACE("(%p %p %p)\n", callback, userdata, environment);
2475 return CreateThreadpoolTimer(callback, userdata, environment);
2478 /*********************************************************************
2479 * __crtCloseThreadpoolTimer (MSVCP140.@)
2481 VOID CDECL MSVCP__crtCloseThreadpoolTimer(TP_TIMER *timer)
2483 TRACE("(%p)\n", timer);
2484 CloseThreadpoolTimer(timer);
2487 /*********************************************************************
2488 * __crtSetThreadpoolTimer (MSVCP140.@)
2490 VOID CDECL MSVCP__crtSetThreadpoolTimer(TP_TIMER *timer,
2491 FILETIME *due_time, DWORD period, DWORD window_length)
2493 TRACE("(%p %p 0x%08x 0x%08x)\n", timer, due_time, period, window_length);
2494 return SetThreadpoolTimer(timer, due_time, period, window_length);
2497 /*********************************************************************
2498 * __crtWaitForThreadpoolTimerCallbacks (MSVCP140.@)
2500 VOID CDECL MSVCP__crtWaitForThreadpoolTimerCallbacks(TP_TIMER *timer, BOOL cancel)
2502 TRACE("(%p %d)\n", timer, cancel);
2503 WaitForThreadpoolTimerCallbacks(timer, cancel);
2506 /*********************************************************************
2507 * __crtCreateThreadpoolWait (MSVCP140.@)
2509 PTP_WAIT CDECL MSVCP__crtCreateThreadpoolWait(PTP_WAIT_CALLBACK callback,
2510 PVOID userdata, TP_CALLBACK_ENVIRON *environment)
2512 TRACE("(%p %p %p)\n", callback, userdata, environment);
2513 return CreateThreadpoolWait(callback, userdata, environment);
2516 /*********************************************************************
2517 * __crtCloseThreadpoolWait (MSVCP140.@)
2519 VOID CDECL MSVCP__crtCloseThreadpoolWait(TP_WAIT *wait)
2521 TRACE("(%p)\n", wait);
2522 CloseThreadpoolWait(wait);
2525 /*********************************************************************
2526 * __crtSetThreadpoolWait (MSVCP140.@)
2528 VOID CDECL MSVCP__crtSetThreadpoolWait(TP_WAIT *wait, HANDLE handle, FILETIME *due_time)
2530 TRACE("(%p %p %p)\n", wait, handle, due_time);
2531 return SetThreadpoolWait(wait, handle, due_time);
2534 /*********************************************************************
2535 * __crtFreeLibraryWhenCallbackReturns (MSVCP140.@)
2537 VOID CDECL MSVCP__crtFreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE instance, HMODULE mod)
2539 TRACE("(%p %p)\n", instance, mod);
2540 FreeLibraryWhenCallbackReturns(instance, mod);
2543 /* ?_Execute_once@std@@YAHAAUonce_flag@1@P6GHPAX1PAPAX@Z1@Z */
2544 /* ?_Execute_once@std@@YAHAEAUonce_flag@1@P6AHPEAX1PEAPEAX@Z1@Z */
2545 BOOL __cdecl _Execute_once(INIT_ONCE *flag, PINIT_ONCE_FN func, void *param)
2547 return InitOnceExecuteOnce(flag, func, param, NULL);
2550 #if _MSVCP_VER >= 100
2551 void init_misc(void *base)
2553 #ifdef __x86_64__
2554 #if _MSVCP_VER == 100
2555 init_error_category_rtti(base);
2556 init_iostream_category_rtti(base);
2557 init_system_category_rtti(base);
2558 init_generic_category_rtti(base);
2559 #endif
2560 #if _MSVCP_VER >= 100
2561 init__Concurrent_queue_base_v4_rtti(base);
2562 init__Runtime_object_rtti(base);
2563 #endif
2564 #if _MSVCP_VER >= 110
2565 init__Pad_rtti(base);
2566 #endif
2567 #endif
2569 #if _MSVCP_VER == 100
2570 iostream_category_ctor(&iostream_category);
2571 system_category_ctor(&system_category);
2572 generic_category_ctor(&generic_category);
2573 #endif
2576 void free_misc(void)
2578 #if _MSVCP_VER >= 110
2579 if(keyed_event)
2580 NtClose(keyed_event);
2581 HeapFree(GetProcessHeap(), 0, broadcast_at_thread_exit.to_broadcast);
2582 #endif
2584 #endif
2586 #if _MSVCP_VER >= 140
2587 LONGLONG __cdecl _Query_perf_counter(void)
2589 LARGE_INTEGER li;
2590 QueryPerformanceCounter(&li);
2591 return li.QuadPart;
2594 LONGLONG __cdecl _Query_perf_frequency(void)
2596 LARGE_INTEGER li;
2597 QueryPerformanceFrequency(&li);
2598 return li.QuadPart;
2600 #endif
2602 void __cdecl threads__Mtx_new(void **mtx)
2604 *mtx = MSVCRT_operator_new(sizeof(CRITICAL_SECTION));
2605 InitializeCriticalSection(*mtx);
2608 void __cdecl threads__Mtx_delete(void *mtx)
2610 DeleteCriticalSection(mtx);
2613 void __cdecl threads__Mtx_lock(void *mtx)
2615 EnterCriticalSection(mtx);
2618 void __cdecl threads__Mtx_unlock(void *mtx)
2620 LeaveCriticalSection(mtx);
2623 #if _MSVCP_VER >= 110
2624 static LONG shared_ptr_lock;
2626 void __cdecl _Lock_shared_ptr_spin_lock(void)
2628 LONG l = 0;
2630 while(InterlockedCompareExchange(&shared_ptr_lock, 1, 0) != 0) {
2631 if(l++ == 1000) {
2632 Sleep(0);
2633 l = 0;
2638 void __cdecl _Unlock_shared_ptr_spin_lock(void)
2640 shared_ptr_lock = 0;
2642 #endif
2644 #if _MSVCP_VER >= 100
2645 /* ?is_current_task_group_canceling@Concurrency@@YA_NXZ */
2646 bool __cdecl is_current_task_group_canceling(void)
2648 return Context_IsCurrentTaskCollectionCanceling();
2651 /* ?_GetCombinableSize@details@Concurrency@@YAIXZ */
2652 /* ?_GetCombinableSize@details@Concurrency@@YA_KXZ */
2653 size_t __cdecl _GetCombinableSize(void)
2655 FIXME("() stub\n");
2656 return 11;
2658 #endif
2660 #if _MSVCP_VER >= 140
2661 typedef struct {
2662 void *unk0;
2663 BYTE unk1;
2664 } task_continuation_context;
2666 /* ??0task_continuation_context@Concurrency@@AAE@XZ */
2667 /* ??0task_continuation_context@Concurrency@@AEAA@XZ */
2668 DEFINE_THISCALL_WRAPPER(task_continuation_context_ctor, 4)
2669 task_continuation_context* __thiscall task_continuation_context_ctor(task_continuation_context *this)
2671 TRACE("(%p)\n", this);
2672 memset(this, 0, sizeof(*this));
2673 return this;
2676 typedef struct {
2677 const vtable_ptr *vtable;
2678 void (__cdecl *func)(void);
2679 int unk[4];
2680 void *unk2[3];
2681 void *this;
2682 } function_void_cdecl_void;
2684 /* ?_Assign@_ContextCallback@details@Concurrency@@AAEXPAX@Z */
2685 /* ?_Assign@_ContextCallback@details@Concurrency@@AEAAXPEAX@Z */
2686 DEFINE_THISCALL_WRAPPER(_ContextCallback__Assign, 8)
2687 void __thiscall _ContextCallback__Assign(void *this, void *v)
2689 TRACE("(%p %p)\n", this, v);
2692 #define call_function_do_call(this) CALL_VTBL_FUNC(this, 8, void, (function_void_cdecl_void*), (this))
2693 #define call_function_do_clean(this,b) CALL_VTBL_FUNC(this, 16, void, (function_void_cdecl_void*,bool), (this, b))
2694 /* ?_CallInContext@_ContextCallback@details@Concurrency@@QBEXV?$function@$$A6AXXZ@std@@_N@Z */
2695 /* ?_CallInContext@_ContextCallback@details@Concurrency@@QEBAXV?$function@$$A6AXXZ@std@@_N@Z */
2696 DEFINE_THISCALL_WRAPPER(_ContextCallback__CallInContext, 48)
2697 void __thiscall _ContextCallback__CallInContext(const void *this, function_void_cdecl_void func, bool b)
2699 TRACE("(%p %p %x)\n", this, func.func, b);
2700 call_function_do_call(func.this);
2701 call_function_do_clean(func.this, func.this!=&func);
2704 /* ?_Capture@_ContextCallback@details@Concurrency@@AAEXXZ */
2705 /* ?_Capture@_ContextCallback@details@Concurrency@@AEAAXXZ */
2706 DEFINE_THISCALL_WRAPPER(_ContextCallback__Capture, 4)
2707 void __thiscall _ContextCallback__Capture(void *this)
2709 TRACE("(%p)\n", this);
2712 /* ?_Reset@_ContextCallback@details@Concurrency@@AAEXXZ */
2713 /* ?_Reset@_ContextCallback@details@Concurrency@@AEAAXXZ */
2714 DEFINE_THISCALL_WRAPPER(_ContextCallback__Reset, 4)
2715 void __thiscall _ContextCallback__Reset(void *this)
2717 TRACE("(%p)\n", this);
2720 /* ?_IsCurrentOriginSTA@_ContextCallback@details@Concurrency@@CA_NXZ */
2721 bool __cdecl _ContextCallback__IsCurrentOriginSTA(void *this)
2723 TRACE("(%p)\n", this);
2724 return FALSE;
2727 typedef struct {
2728 /*_Task_impl_base*/void *task;
2729 bool scheduled;
2730 bool started;
2731 } _TaskEventLogger;
2733 /* ?_LogCancelTask@_TaskEventLogger@details@Concurrency@@QAEXXZ */
2734 /* ?_LogCancelTask@_TaskEventLogger@details@Concurrency@@QEAAXXZ */
2735 DEFINE_THISCALL_WRAPPER(_TaskEventLogger__LogCancelTask, 4)
2736 void __thiscall _TaskEventLogger__LogCancelTask(_TaskEventLogger *this)
2738 TRACE("(%p)\n", this);
2741 /* ?_LogScheduleTask@_TaskEventLogger@details@Concurrency@@QAEX_N@Z */
2742 /* ?_LogScheduleTask@_TaskEventLogger@details@Concurrency@@QEAAX_N@Z */
2743 DEFINE_THISCALL_WRAPPER(_TaskEventLogger__LogScheduleTask, 8)
2744 void __thiscall _TaskEventLogger__LogScheduleTask(_TaskEventLogger *this, bool continuation)
2746 TRACE("(%p %x)\n", this, continuation);
2749 /* ?_LogTaskCompleted@_TaskEventLogger@details@Concurrency@@QAEXXZ */
2750 /* ?_LogTaskCompleted@_TaskEventLogger@details@Concurrency@@QEAAXXZ */
2751 DEFINE_THISCALL_WRAPPER(_TaskEventLogger__LogTaskCompleted, 4)
2752 void __thiscall _TaskEventLogger__LogTaskCompleted(_TaskEventLogger *this)
2754 TRACE("(%p)\n", this);
2757 /* ?_LogTaskExecutionCompleted@_TaskEventLogger@details@Concurrency@@QAEXXZ */
2758 /* ?_LogTaskExecutionCompleted@_TaskEventLogger@details@Concurrency@@QEAAXXZ */
2759 DEFINE_THISCALL_WRAPPER(_TaskEventLogger__LogTaskExecutionCompleted, 4)
2760 void __thiscall _TaskEventLogger__LogTaskExecutionCompleted(_TaskEventLogger *this)
2762 TRACE("(%p)\n", this);
2765 /* ?_LogWorkItemCompleted@_TaskEventLogger@details@Concurrency@@QAEXXZ */
2766 /* ?_LogWorkItemCompleted@_TaskEventLogger@details@Concurrency@@QEAAXXZ */
2767 DEFINE_THISCALL_WRAPPER(_TaskEventLogger__LogWorkItemCompleted, 4)
2768 void __thiscall _TaskEventLogger__LogWorkItemCompleted(_TaskEventLogger *this)
2770 TRACE("(%p)\n", this);
2773 /* ?_LogWorkItemStarted@_TaskEventLogger@details@Concurrency@@QAEXXZ */
2774 /* ?_LogWorkItemStarted@_TaskEventLogger@details@Concurrency@@QEAAXXZ */
2775 DEFINE_THISCALL_WRAPPER(_TaskEventLogger__LogWorkItemStarted, 4)
2776 void __thiscall _TaskEventLogger__LogWorkItemStarted(_TaskEventLogger *this)
2778 TRACE("(%p)\n", this);
2781 typedef struct {
2782 PTP_WORK work;
2783 void (__cdecl *callback)(void*);
2784 void *arg;
2785 } _Threadpool_chore;
2787 /* ?_Reschedule_chore@details@Concurrency@@YAHPBU_Threadpool_chore@12@@Z */
2788 /* ?_Reschedule_chore@details@Concurrency@@YAHPEBU_Threadpool_chore@12@@Z */
2789 int __cdecl _Reschedule_chore(const _Threadpool_chore *chore)
2791 TRACE("(%p)\n", chore);
2793 SubmitThreadpoolWork(chore->work);
2794 return 0;
2797 static void WINAPI threadpool_callback(PTP_CALLBACK_INSTANCE instance, void *context, PTP_WORK work)
2799 _Threadpool_chore *chore = context;
2800 TRACE("calling chore callback: %p\n", chore);
2801 if (chore->callback)
2802 chore->callback(chore->arg);
2805 /* ?_Schedule_chore@details@Concurrency@@YAHPAU_Threadpool_chore@12@@Z */
2806 /* ?_Schedule_chore@details@Concurrency@@YAHPEAU_Threadpool_chore@12@@Z */
2807 int __cdecl _Schedule_chore(_Threadpool_chore *chore)
2809 TRACE("(%p)\n", chore);
2811 chore->work = CreateThreadpoolWork(threadpool_callback, chore, NULL);
2812 /* FIXME: what should be returned in case of error */
2813 if(!chore->work)
2814 return -1;
2816 return _Reschedule_chore(chore);
2819 /* ?_Release_chore@details@Concurrency@@YAXPAU_Threadpool_chore@12@@Z */
2820 /* ?_Release_chore@details@Concurrency@@YAXPEAU_Threadpool_chore@12@@Z */
2821 void __cdecl _Release_chore(_Threadpool_chore *chore)
2823 TRACE("(%p)\n", chore);
2825 if(!chore->work) return;
2826 CloseThreadpoolWork(chore->work);
2827 chore->work = NULL;
2829 #endif
2831 #if _MSVCP_VER >= 110 && _MSVCP_VER <= 120
2832 typedef struct {
2833 char dummy;
2834 } _Ph;
2836 /* ?_1@placeholders@std@@3V?$_Ph@$00@2@A */
2837 /* ?_20@placeholders@std@@3V?$_Ph@$0BE@@2@A */
2838 _Ph _Ph_1 = {0}, _Ph_2 = {0}, _Ph_3 = {0}, _Ph_4 = {0}, _Ph_5 = {0};
2839 _Ph _Ph_6 = {0}, _Ph_7 = {0}, _Ph_8 = {0}, _Ph_9 = {0}, _Ph_10 = {0};
2840 _Ph _Ph_11 = {0}, _Ph_12 = {0}, _Ph_13 = {0}, _Ph_14 = {0}, _Ph_15 = {0};
2841 _Ph _Ph_16 = {0}, _Ph_17 = {0}, _Ph_18 = {0}, _Ph_19 = {0}, _Ph_20 = {0};
2842 #endif
2844 #if _MSVCP_VER >= 140
2845 /* ?_IsNonBlockingThread@_Task_impl_base@details@Concurrency@@SA_NXZ */
2846 bool __cdecl _Task_impl_base__IsNonBlockingThread(void)
2848 FIXME("() stub\n");
2849 return FALSE;
2851 #endif
2853 #if _MSVCP_VER >= 110
2854 /* ?_Syserror_map@std@@YAPBDH@Z */
2855 /* ?_Syserror_map@std@@YAPEBDH@Z */
2856 const char* __cdecl _Syserror_map(int err)
2858 int i;
2860 TRACE("(%d)\n", err);
2862 for(i = 0; i < ARRAY_SIZE(syserror_map); i++)
2864 if(syserror_map[i].err == err)
2865 return syserror_map[i].str;
2867 #if _MSVCP_VER >= 140
2868 return "unknown error";
2869 #else
2870 return NULL;
2871 #endif
2873 #endif
2875 #if _MSVCP_VER >= 140
2876 /* ?_Winerror_message@std@@YAKKPADK@Z */
2877 /* ?_Winerror_message@std@@YAKKPEADK@Z */
2878 ULONG __cdecl _Winerror_message(ULONG err, char *buf, ULONG size)
2880 TRACE("(%u %p %u)\n", err, buf, size);
2882 return FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
2883 NULL, err, 0, buf, size, NULL);
2886 /* ?_Winerror_map@std@@YAHH@Z */
2887 int __cdecl _Winerror_map(int err)
2889 int low = 0, high = ARRAY_SIZE(winerror_map) - 1, mid;
2891 while(low <= high)
2893 mid = (low + high) / 2;
2895 if(err == winerror_map[mid].winerr)
2896 return winerror_map[mid].doserr;
2897 if(err > winerror_map[mid].winerr)
2898 low = mid + 1;
2899 else
2900 high = mid - 1;
2903 return 0;
2905 #endif