2 * Copyright 2010 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
29 #include "wine/exception.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(msvcp
);
33 /* error strings generated with glibc strerror */
34 static const char str_EPERM
[] = "operation not permitted";
35 static const char str_ENOENT
[] = "no such file or directory";
36 static const char str_ESRCH
[] = "no such process";
37 static const char str_EINTR
[] = "interrupted system call";
38 static const char str_EIO
[] = "input/output error";
39 static const char str_ENXIO
[] = "no such device or address";
40 static const char str_E2BIG
[] = "argument list too long";
41 static const char str_ENOEXEC
[] = "exec format error";
42 static const char str_EBADF
[] = "bad file descriptor";
43 static const char str_ECHILD
[] = "no child processes";
44 static const char str_EAGAIN
[] = "resource temporarily unavailable";
45 static const char str_ENOMEM
[] = "cannot allocate memory";
46 static const char str_EACCES
[] = "permission denied";
47 static const char str_EFAULT
[] = "bad address";
48 static const char str_EBUSY
[] = "device or resource busy";
49 static const char str_EEXIST
[] = "file exists";
50 static const char str_EXDEV
[] = "invalid cross-device link";
51 static const char str_ENODEV
[] = "no such device";
52 static const char str_ENOTDIR
[] = "not a directory";
53 static const char str_EISDIR
[] = "is a directory";
54 static const char str_EINVAL
[] = "invalid argument";
55 static const char str_ENFILE
[] = "too many open files in system";
56 static const char str_EMFILE
[] = "too many open files";
57 static const char str_ENOTTY
[] = "inappropriate ioctl for device";
58 static const char str_EFBIG
[] = "file too large";
59 static const char str_ENOSPC
[] = "no space left on device";
60 static const char str_ESPIPE
[] = "illegal seek";
61 static const char str_EROFS
[] = "read-only file system";
62 static const char str_EMLINK
[] = "too many links";
63 static const char str_EPIPE
[] = "broken pipe";
64 static const char str_EDOM
[] = "numerical argument out of domain";
65 static const char str_ERANGE
[] = "numerical result out of range";
66 static const char str_EDEADLK
[] = "resource deadlock avoided";
67 static const char str_ENAMETOOLONG
[] = "file name too long";
68 static const char str_ENOLCK
[] = "no locks available";
69 static const char str_ENOSYS
[] = "function not implemented";
70 static const char str_ENOTEMPTY
[] = "directory not empty";
71 static const char str_EILSEQ
[] = "invalid or incomplete multibyte or wide character";
72 static const char str_EADDRINUSE
[] = "address already in use";
73 static const char str_EADDRNOTAVAIL
[] = "cannot assign requested address";
74 static const char str_EAFNOSUPPORT
[] = "address family not supported by protocol";
75 static const char str_EALREADY
[] = "operation already in progress";
76 static const char str_EBADMSG
[] = "not a data message";
77 static const char str_ECANCELED
[] = "operation Canceled";
78 static const char str_ECONNABORTED
[] = "software caused connection abort";
79 static const char str_ECONNREFUSED
[] = "connection refused";
80 static const char str_ECONNRESET
[] = "connection reset by peer";
81 static const char str_EDESTADDRREQ
[] = "destination address required";
82 static const char str_EHOSTUNREACH
[] = "no route to host";
83 static const char str_EIDRM
[] = "identifier removed";
84 static const char str_EINPROGRESS
[] = "operation now in progress";
85 static const char str_EISCONN
[] = "transport endpoint is already connected";
86 static const char str_ELOOP
[] = "too many symbolic links encountered";
87 static const char str_EMSGSIZE
[] = "message too long";
88 static const char str_ENETDOWN
[] = "network is down";
89 static const char str_ENETRESET
[] = "network dropped connection because of reset";
90 static const char str_ENETUNREACH
[] = "network is unreachable";
91 static const char str_ENOBUFS
[] = "no buffer space available";
92 static const char str_ENODATA
[] = "no data available";
93 static const char str_ENOLINK
[] = "link has been severed";
94 static const char str_ENOMSG
[] = "no message of desired type";
95 static const char str_ENOPROTOOPT
[] = "protocol not available";
96 static const char str_ENOSR
[] = "out of streams resources";
97 static const char str_ENOSTR
[] = "device not a stream";
98 static const char str_ENOTCONN
[] = "transport endpoint is not connected";
99 static const char str_ENOTRECOVERABLE
[] = "state not recoverable";
100 static const char str_ENOTSOCK
[] = "socket operation on non-socket";
101 static const char str_ENOTSUP
[] = "not supported";
102 static const char str_EOPNOTSUPP
[] = "operation not supported on transport endpoint";
103 static const char str_EOVERFLOW
[] = "value too large for defined data type";
104 static const char str_EOWNERDEAD
[] = "owner died";
105 static const char str_EPROTO
[] = "protocol error";
106 static const char str_EPROTONOSUPPORT
[] = "protocol not supported";
107 static const char str_EPROTOTYPE
[] = "protocol wrong type for socket";
108 static const char str_ETIME
[] = "timer expired";
109 static const char str_ETIMEDOUT
[] = "connection timed out";
110 static const char str_ETXTBSY
[] = "text file busy";
111 static const char str_EWOULDBLOCK
[] = "operation would block";
113 static const struct {
119 {ENOENT
, str_ENOENT
},
125 {ENOEXEC
, str_ENOEXEC
},
127 {ECHILD
, str_ECHILD
},
128 {EAGAIN
, str_EAGAIN
},
129 {ENOMEM
, str_ENOMEM
},
130 {EACCES
, str_EACCES
},
131 {EFAULT
, str_EFAULT
},
133 {EEXIST
, str_EEXIST
},
135 {ENODEV
, str_ENODEV
},
136 {ENOTDIR
, str_ENOTDIR
},
137 {EISDIR
, str_EISDIR
},
138 {EINVAL
, str_EINVAL
},
139 {ENFILE
, str_ENFILE
},
140 {EMFILE
, str_EMFILE
},
141 {ENOTTY
, str_ENOTTY
},
143 {ENOSPC
, str_ENOSPC
},
144 {ESPIPE
, str_ESPIPE
},
146 {EMLINK
, str_EMLINK
},
149 {ERANGE
, str_ERANGE
},
150 {EDEADLK
, str_EDEADLK
},
151 {ENAMETOOLONG
, str_ENAMETOOLONG
},
152 {ENOLCK
, str_ENOLCK
},
153 {ENOSYS
, str_ENOSYS
},
154 {ENOTEMPTY
, str_ENOTEMPTY
},
155 {EILSEQ
, str_EILSEQ
},
156 {EADDRINUSE
, str_EADDRINUSE
},
157 {EADDRNOTAVAIL
, str_EADDRNOTAVAIL
},
158 {EAFNOSUPPORT
, str_EAFNOSUPPORT
},
159 {EALREADY
, str_EALREADY
},
160 {EBADMSG
, str_EBADMSG
},
161 {ECANCELED
, str_ECANCELED
},
162 {ECONNABORTED
, str_ECONNABORTED
},
163 {ECONNREFUSED
, str_ECONNREFUSED
},
164 {ECONNRESET
, str_ECONNRESET
},
165 {EDESTADDRREQ
, str_EDESTADDRREQ
},
166 {EHOSTUNREACH
, str_EHOSTUNREACH
},
168 {EINPROGRESS
, str_EINPROGRESS
},
169 {EISCONN
, str_EISCONN
},
171 {EMSGSIZE
, str_EMSGSIZE
},
172 {ENETDOWN
, str_ENETDOWN
},
173 {ENETRESET
, str_ENETRESET
},
174 {ENETUNREACH
, str_ENETUNREACH
},
175 {ENOBUFS
, str_ENOBUFS
},
176 {ENODATA
, str_ENODATA
},
177 {ENOLINK
, str_ENOLINK
},
178 {ENOMSG
, str_ENOMSG
},
179 {ENOPROTOOPT
, str_ENOPROTOOPT
},
181 {ENOSTR
, str_ENOSTR
},
182 {ENOTCONN
, str_ENOTCONN
},
183 {ENOTRECOVERABLE
, str_ENOTRECOVERABLE
},
184 {ENOTSOCK
, str_ENOTSOCK
},
185 {ENOTSUP
, str_ENOTSUP
},
186 {EOPNOTSUPP
, str_EOPNOTSUPP
},
187 {EOVERFLOW
, str_EOVERFLOW
},
188 {EOWNERDEAD
, str_EOWNERDEAD
},
189 {EPROTO
, str_EPROTO
},
190 {EPROTONOSUPPORT
, str_EPROTONOSUPPORT
},
191 {EPROTOTYPE
, str_EPROTOTYPE
},
193 {ETIMEDOUT
, str_ETIMEDOUT
},
194 {ETXTBSY
, str_ETXTBSY
},
195 {EWOULDBLOCK
, str_EWOULDBLOCK
},
199 #if _MSVCP_VER >= 140
200 static const struct {
205 {ERROR_INVALID_FUNCTION
, ENOSYS
}, {ERROR_FILE_NOT_FOUND
, ENOENT
},
206 {ERROR_PATH_NOT_FOUND
, ENOENT
}, {ERROR_TOO_MANY_OPEN_FILES
, EMFILE
},
207 {ERROR_ACCESS_DENIED
, EACCES
}, {ERROR_INVALID_HANDLE
, EINVAL
},
208 {ERROR_NOT_ENOUGH_MEMORY
, ENOMEM
}, {ERROR_INVALID_ACCESS
, EACCES
},
209 {ERROR_OUTOFMEMORY
, ENOMEM
}, {ERROR_INVALID_DRIVE
, ENODEV
},
210 {ERROR_CURRENT_DIRECTORY
, EACCES
}, {ERROR_NOT_SAME_DEVICE
, EXDEV
},
211 {ERROR_WRITE_PROTECT
, EACCES
}, {ERROR_BAD_UNIT
, ENODEV
},
212 {ERROR_NOT_READY
, EAGAIN
}, {ERROR_SEEK
, EIO
}, {ERROR_WRITE_FAULT
, EIO
},
213 {ERROR_READ_FAULT
, EIO
}, {ERROR_SHARING_VIOLATION
, EACCES
},
214 {ERROR_LOCK_VIOLATION
, ENOLCK
}, {ERROR_HANDLE_DISK_FULL
, ENOSPC
},
215 {ERROR_NOT_SUPPORTED
, ENOTSUP
}, {ERROR_DEV_NOT_EXIST
, ENODEV
},
216 {ERROR_FILE_EXISTS
, EEXIST
}, {ERROR_CANNOT_MAKE
, EACCES
},
217 {ERROR_INVALID_PARAMETER
, EINVAL
}, {ERROR_OPEN_FAILED
, EIO
},
218 {ERROR_BUFFER_OVERFLOW
, ENAMETOOLONG
}, {ERROR_DISK_FULL
, ENOSPC
},
219 {ERROR_INVALID_NAME
, 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
}
244 struct __Container_proxy
;
247 struct __Container_proxy
*proxy
;
250 typedef struct __Iterator_base12
{
251 struct __Container_proxy
*proxy
;
252 struct __Iterator_base12
*next
;
255 typedef struct __Container_proxy
{
256 const _Container_base12
*cont
;
257 _Iterator_base12
*head
;
260 /* ??0_Mutex@std@@QAE@XZ */
261 /* ??0_Mutex@std@@QEAA@XZ */
262 DEFINE_THISCALL_WRAPPER(mutex_ctor
, 4)
263 mutex
* __thiscall
mutex_ctor(mutex
*this)
265 CRITICAL_SECTION
*cs
= MSVCRT_operator_new(sizeof(*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");
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
)
310 /* ?_Mutex_Unlock@_Mutex@std@@CAXPAV12@@Z */
311 /* ?_Mutex_Unlock@_Mutex@std@@CAXPEAV12@@Z */
312 void CDECL
mutex_mutex_unlock(mutex
*m
)
317 /* ?_Mutex_ctor@_Mutex@std@@CAXPAV12@@Z */
318 /* ?_Mutex_ctor@_Mutex@std@@CAXPEAV12@@Z */
319 void CDECL
mutex_mutex_ctor(mutex
*m
)
324 /* ?_Mutex_dtor@_Mutex@std@@CAXPAV12@@Z */
325 /* ?_Mutex_dtor@_Mutex@std@@CAXPEAV12@@Z */
326 void CDECL
mutex_mutex_dtor(mutex
*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)
349 EnterCriticalSection(&init_locks_cs
);
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");
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);
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)
377 EnterCriticalSection(&init_locks_cs
);
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);
399 static inline int get_locktype( _Lockit
*lockit
) { return lockit
->locktype
; }
400 static inline void set_locktype( _Lockit
*lockit
, int type
) { lockit
->locktype
= type
; }
402 static inline int get_locktype( _Lockit
*lockit
) { return 0; }
403 static inline void set_locktype( _Lockit
*lockit
, int type
) { }
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
);
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);
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);
467 unsigned short __cdecl
wctype(const char *property
)
469 static const struct {
473 { "alnum", _DIGIT
|_ALPHA
},
475 { "cntrl", _CONTROL
},
477 { "graph", _DIGIT
|_PUNCT
|_ALPHA
},
479 { "print", _DIGIT
|_PUNCT
|_BLANK
|_ALPHA
},
487 for(i
= 0; i
< ARRAY_SIZE(properties
); i
++)
488 if(!strcmp(property
, properties
[i
].name
))
489 return properties
[i
].mask
;
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
)
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
);
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
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
)
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
)
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)
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
)
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
;
609 this->proxy
= that
->proxy
;
613 this->proxy
->cont
= this;
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
;
637 /* _Xtime_get_ticks */
638 LONGLONG __cdecl
_Xtime_get_ticks(void)
644 GetSystemTimeAsFileTime(&ft
);
645 return ((LONGLONG
)ft
.dwHighDateTime
<<32) + ft
.dwLowDateTime
- TICKS_1601_TO_1970
;
649 int __cdecl
xtime_get(xtime
* t
, int unknown
)
658 ticks
= _Xtime_get_ticks();
659 t
->sec
= ticks
/ TICKSPERSEC
;
660 t
->nsec
= ticks
% TICKSPERSEC
* 100;
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
;
678 diff_nsec
+= NANOSEC_PER_SEC
;
681 if (diff_sec
<0 || (diff_sec
==0 && diff_nsec
<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
)
695 return _Xtime_diff_to_millis2(t
, &now
);
700 unsigned int __cdecl
_Random_device(void)
706 /* TODO: throw correct exception in case of failure */
708 throw_exception(EXCEPTION
, "random number generator failed\n");
713 #if _MSVCP_VER >= 110
714 #ifdef __ASM_USE_THISCALL_WRAPPER
716 extern void *call_thiscall_func
;
717 __ASM_GLOBAL_FUNC(call_thiscall_func
,
724 #define call_func1(func,this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)(func,this)
728 #define call_func1(func,this) func(this)
730 #endif /* __i386__ */
732 #define MTX_PLAIN 0x1
734 #define MTX_TIMED 0x4
735 #define MTX_RECURSIVE 0x100
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)
750 typedef _Mtx_t
*_Mtx_arg_t
;
751 #define MTX_T_FROM_ARG(m) (*(m))
752 #define MTX_T_TO_ARG(m) (&(m))
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
);
761 call_func1(critical_section_ctor
, &mtx
->cs
);
766 int __cdecl
_Mtx_init(_Mtx_t
*mtx
, int flags
)
768 *mtx
= MSVCRT_operator_new(sizeof(**mtx
));
769 _Mtx_init_in_situ(*mtx
, flags
);
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
) {
799 MTX_T_FROM_ARG(mtx
)->count
++;
803 int __cdecl
_Mtx_unlock(_Mtx_arg_t mtx
)
805 if(--MTX_T_FROM_ARG(mtx
)->count
)
808 MTX_T_FROM_ARG(mtx
)->thread_id
= -1;
809 call_func1(critical_section_unlock
, &MTX_T_FROM_ARG(mtx
)->cs
);
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
))
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
) {
824 MTX_T_FROM_ARG(mtx
)->count
++;
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
)
836 for (val
= *dest
;; val
= tmp
)
838 if (!val
|| (tmp
= InterlockedCompareExchange( dest
, val
- 1, val
)) == val
)
844 #define CND_TIMEDOUT 2
848 CONDITION_VARIABLE cv
;
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)
856 typedef _Cnd_t
*_Cnd_arg_t
;
857 #define CND_T_FROM_ARG(c) (*(c))
858 #define CND_T_TO_ARG(c) (&(c))
861 static HANDLE keyed_event
;
863 void __cdecl
_Cnd_init_in_situ(_Cnd_t cnd
)
865 InitializeConditionVariable(&cnd
->cv
);
870 NtCreateKeyedEvent(&event
, GENERIC_READ
|GENERIC_WRITE
, NULL
, 0);
871 if(InterlockedCompareExchangePointer(&keyed_event
, event
, NULL
) != NULL
)
876 int __cdecl
_Cnd_init(_Cnd_t
*cnd
)
878 *cnd
= MSVCRT_operator_new(sizeof(**cnd
));
879 _Cnd_init_in_situ(*cnd
);
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 );
890 NtWaitForKeyedEvent(keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
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
;
902 InterlockedExchangeAdd( (LONG
*)&cv
->Ptr
, 1 );
905 timeout
.QuadPart
= (ULONGLONG
)(ULONG
)_Xtime_diff_to_millis(xt
) * -10000;
906 status
= NtWaitForKeyedEvent(keyed_event
, &cv
->Ptr
, FALSE
, &timeout
);
909 if (!interlocked_dec_if_nonzero( (LONG
*)&cv
->Ptr
))
910 status
= NtWaitForKeyedEvent( keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
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 );
922 NtReleaseKeyedEvent( keyed_event
, &cv
->Ptr
, FALSE
, NULL
);
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
);
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
)
943 MSVCRT_operator_delete(CND_T_FROM_ARG(cnd
));
951 struct _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
);
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]));
987 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
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();
999 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
1002 void __cdecl
_Cnd_unregister_at_thread_exit(_Mtx_arg_t mtx
)
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
)
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
--;
1018 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
1021 void __cdecl
_Cnd_do_broadcast_at_thread_exit(void)
1023 int i
, id
= GetCurrentThreadId();
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
)
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
--;
1042 LeaveCriticalSection(&broadcast_at_thread_exit_cs
);
1047 #if _MSVCP_VER == 100
1049 const vtable_ptr
*vtable
;
1053 error_category base
;
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
);
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
);
1081 MSVCRT_operator_delete(this);
1087 DEFINE_THISCALL_WRAPPER(custom_category_name
, 4)
1088 const char* __thiscall
custom_category_name(const custom_category
*this)
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
);
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
);
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
);
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)
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)
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)
1175 return &generic_category
.base
;
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
);
1195 /* FIXME: handle exceptions */
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));
1219 #if _MSVCP_VER >= 110
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
);
1242 void __cdecl
_Thrd_sleep(const xtime
*t
)
1245 Sleep(_Xtime_diff_to_millis(t
));
1248 void __cdecl
_Thrd_yield(void)
1254 static _Thrd_t
thread_current(void)
1258 if(DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
1259 GetCurrentProcess(), &ret
.hnd
, 0, FALSE
, DUPLICATE_SAME_ACCESS
)) {
1260 CloseHandle(ret
.hnd
);
1264 ret
.id
= GetCurrentThreadId();
1266 TRACE("(%p %u)\n", ret
.hnd
, ret
.id
);
1271 _Thrd_t __cdecl
_Thrd_current(void)
1273 return thread_current();
1276 ULONGLONG __cdecl
_Thrd_current(void)
1283 C_ASSERT(sizeof(_Thrd_t
) <= sizeof(ULONGLONG
));
1285 ret
.thr
= thread_current();
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
))
1297 GetExitCodeThread(thr
.hnd
, (DWORD
*)code
);
1299 CloseHandle(thr
.hnd
);
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
;
1316 static DWORD WINAPI
thread_proc_wrapper(void *arg
)
1318 thread_proc_arg wrapped_arg
= *((thread_proc_arg
*)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
;
1328 TRACE("(%p %p %p)\n", thr
, proc
, arg
);
1330 wrapped_arg
= malloc(sizeof(*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
);
1341 int __cdecl
_Thrd_detach(_Thrd_t thr
)
1343 return CloseHandle(thr
.hnd
) ? 0 : _THRD_ERROR
;
1348 const vtable_ptr
*vtable
;
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;
1369 val
= si
.dwNumberOfProcessors
;
1375 unsigned int __cdecl
_Thrd_id(void)
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
));
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
;
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);
1440 static DWORD WINAPI
launch_thread_proc(void *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
));
1471 #if _MSVCP_VER >= 100
1472 typedef struct _Page
1474 struct _Page
*_Next
;
1493 threadsafe_queue queues
[QUEUES_NO
];
1498 const vtable_ptr
*vtable
;
1499 queue_data
*data
; /* queue_data structure is not binary compatible */
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))
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))
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 */
1558 size
<= 128 ? 2 : 1;
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
);
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
);
1585 _Concurrent_queue_base_v4_dtor(this);
1586 MSVCRT_operator_delete(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)
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)
1637 spin_limit
= si
.dwNumberOfProcessors
>1 ? 4000 : 0;
1640 if(*counter
>= spin_limit
)
1652 static size_t InterlockedIncrementSizeT(size_t volatile *dest
)
1659 } while(InterlockedCompareExchange64((LONGLONG
*)dest
, v
+1, v
) != v
);
1664 #define InterlockedIncrementSizeT(dest) InterlockedIncrement((LONG*)dest)
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);
1681 while(queue
->tail_pos
!= id
)
1686 /* TODO: Add exception handling */
1687 p
= call__Concurrent_queue_base_v4__Allocate_page(parent
);
1692 while(InterlockedCompareExchange(&queue
->lock
, 1, 0))
1695 queue
->tail
->_Next
= p
;
1709 call__Concurrent_queue_base_v4__Copy_item(parent
, p
, id
-page_id
, e
);
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);
1726 while(queue
->tail_pos
<= id
)
1730 while(queue
->head_pos
!= id
)
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
);
1741 if(id
== page_id
+parent
->alloc_count
-1)
1744 while(InterlockedCompareExchange(&queue
->lock
, 1, 0))
1746 queue
->head
= p
->_Next
;
1751 /* TODO: Add exception handling */
1752 call__Concurrent_queue_base_v4__Deallocate_page(parent
, p
);
1755 InterlockedIncrementSizeT(&queue
->head_pos
);
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
)
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
)
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
)
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));
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
;
1833 const vtable_ptr
*vtable
;
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
;
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);
1861 DEFINE_THISCALL_WRAPPER(_Runtime_object__GetId
, 4)
1862 int __thiscall
_Runtime_object__GetId(_Runtime_object
*this)
1864 TRACE("(%p)\n", this);
1868 DEFINE_RTTI_DATA0(_Runtime_object
, 0, ".?AV_Runtime_object@details@Concurrency@@")
1872 #if _MSVCP_VER >= 100
1873 typedef struct __Concurrent_vector_base_v4
1875 void* (__cdecl
*allocator
)(struct __Concurrent_vector_base_v4
*, size_t);
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
1888 void *blocks
[SEGMENT_SIZE
];
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
)
1896 BitScanReverse(&index
, x
|1);
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
)
1906 TRACE("(%Iu)\n", x
);
1908 if((sizeof(x
) == 8) && (half
= x
>> 32))
1909 return log2i(half
) + 32;
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
;
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
);
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
)
1940 v
= InterlockedCompareExchange64((LONGLONG
*)dest
, exchange
, cmp
);
1945 #define InterlockedCompareExchangeSizeT(dest, exchange, cmp) InterlockedCompareExchange((LONG*)dest, (size_t)exchange, (size_t)cmp)
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
)
1955 while(!this->segment
[seg
] || this->segment
[seg
] == SEGMENT_ALLOC_MARKER
)
1958 while(this->segment
[seg
] == SEGMENT_ALLOC_MARKER
)
1960 if(!InterlockedCompareExchangeSizeT((this->segment
+ seg
),
1961 SEGMENT_ALLOC_MARKER
, 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
);
1970 this->segment
[seg
] = this->allocator(this, element_size
* (1 << seg
));
1974 this->segment
[seg
] = NULL
;
1975 throw_exception(EXCEPTION_RERAISE
, NULL
);
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)
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
;
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
;
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
)
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
;
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;
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))
2085 size_t size
, alloc_size
, seg_no
, alloc_seg
, copy_element
, clear_element
;
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);
2095 this->first_block
= 0;
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));
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
;
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
));
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
);
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
;
2144 TRACE("(%p %p %Iu %p)\n", this, v
, element_size
, copy
);
2146 v_size
= v
->early_size
;
2148 this->early_size
= 0;
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
;
2172 TRACE("(%p %p %Iu %p %p %p)\n", this, v
, element_size
, clear
, assign
, copy
);
2174 v_size
= v
->early_size
;
2176 _Concurrent_vector_base_v4__Internal_clear(this, clear
);
2179 if(!this->early_size
) {
2180 _Concurrent_vector_base_v4__Internal_copy(this, v
, element_size
, copy
);
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
);
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
);
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
;
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
;
2244 copy(((BYTE
**)this->segment
[seg_no
] + element_size
* (size
- ((1 << seg_no
) & ~1))), v
,
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
));
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
);
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
;
2277 copy(((BYTE
**)this->segment
[seg_no
] + element_size
* (size
- ((1 << seg_no
) & ~1))), v
,
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
));
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
;
2297 TRACE("(%p %Iu %p)\n", this, element_size
, idx
);
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
);
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
;
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)),
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
);
2362 if(v
->segment
== this->storage
)
2363 v
->segment
= v
->storage
;
2364 if(this->segment
== v
->storage
)
2365 this->segment
= this->storage
;
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
));
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
)
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
));
2406 #if _MSVCP_VER >= 110
2408 VTABLE_ADD_FUNC(_Pad__Go
));
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
),
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
)
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
);
2560 #if _MSVCP_VER >= 100
2561 init__Concurrent_queue_base_v4_rtti(base
);
2562 init__Runtime_object_rtti(base
);
2564 #if _MSVCP_VER >= 110
2565 init__Pad_rtti(base
);
2569 #if _MSVCP_VER == 100
2570 iostream_category_ctor(&iostream_category
);
2571 system_category_ctor(&system_category
);
2572 generic_category_ctor(&generic_category
);
2576 void free_misc(void)
2578 #if _MSVCP_VER >= 110
2580 NtClose(keyed_event
);
2581 HeapFree(GetProcessHeap(), 0, broadcast_at_thread_exit
.to_broadcast
);
2586 #if _MSVCP_VER >= 140
2587 LONGLONG __cdecl
_Query_perf_counter(void)
2590 QueryPerformanceCounter(&li
);
2594 LONGLONG __cdecl
_Query_perf_frequency(void)
2597 QueryPerformanceFrequency(&li
);
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)
2630 while(InterlockedCompareExchange(&shared_ptr_lock
, 1, 0) != 0) {
2638 void __cdecl
_Unlock_shared_ptr_spin_lock(void)
2640 shared_ptr_lock
= 0;
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)
2660 #if _MSVCP_VER >= 140
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));
2677 const vtable_ptr
*vtable
;
2678 void (__cdecl
*func
)(void);
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);
2728 /*_Task_impl_base*/void *task
;
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);
2783 void (__cdecl
*callback
)(void*);
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
);
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 */
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
);
2831 #if _MSVCP_VER >= 110 && _MSVCP_VER <= 120
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};
2844 #if _MSVCP_VER >= 140
2845 /* ?_IsNonBlockingThread@_Task_impl_base@details@Concurrency@@SA_NXZ */
2846 bool __cdecl
_Task_impl_base__IsNonBlockingThread(void)
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
)
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";
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
;
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
)