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
23 #define ALIGNED_SIZE(size, alignment) (((size)+((alignment)-1))/(alignment)*(alignment))
25 typedef unsigned char MSVCP_bool
;
26 typedef SIZE_T MSVCP_size_t
;
29 typedef __int64
DECLSPEC_ALIGN(8) streamoff
;
30 typedef __int64
DECLSPEC_ALIGN(8) streamsize
;
31 #define STREAMOFF_BITS 64
32 #define STREAMSIZE_BITS 64
34 typedef SSIZE_T streamoff
;
35 typedef SSIZE_T streamsize
;
36 #define STREAMOFF_BITS 32
37 #define STREAMSIZE_BITS 32
40 void __cdecl
_invalid_parameter(const wchar_t*, const wchar_t*,
41 const wchar_t*, unsigned int, uintptr_t);
42 BOOL __cdecl
__uncaught_exception(void);
44 extern void* (__cdecl
*MSVCRT_operator_new
)(MSVCP_size_t
);
45 extern void (__cdecl
*MSVCRT_operator_delete
)(void*);
46 extern void* (__cdecl
*MSVCRT_set_new_handler
)(void*);
49 /* keep in sync with msvcrt/lock.c */
50 typedef struct cs_queue
52 struct cs_queue
*next
;
59 ULONG_PTR unk_thread_id
;
66 extern critical_section
* (__thiscall
*critical_section_ctor
)(critical_section
*);
67 extern void (__thiscall
*critical_section_dtor
)(critical_section
*);
68 extern void (__thiscall
*critical_section_lock
)(critical_section
*);
69 extern void (__thiscall
*critical_section_unlock
)(critical_section
*);
70 extern MSVCP_bool (__thiscall
*critical_section_trylock
)(critical_section
*);
73 /* basic_string<char, char_traits<char>, allocator<char>> */
81 #define BUF_SIZE_CHAR 16
82 char buf
[BUF_SIZE_CHAR
];
93 basic_string_char
* __thiscall
MSVCP_basic_string_char_ctor(basic_string_char
*);
94 basic_string_char
* __thiscall
MSVCP_basic_string_char_ctor_cstr(basic_string_char
*, const char*);
95 basic_string_char
* __thiscall
MSVCP_basic_string_char_ctor_cstr_len(basic_string_char
*, const char*, MSVCP_size_t
);
96 basic_string_char
* __thiscall
MSVCP_basic_string_char_copy_ctor(basic_string_char
*, const basic_string_char
*);
97 void __thiscall
MSVCP_basic_string_char_dtor(basic_string_char
*);
98 const char* __thiscall
MSVCP_basic_string_char_c_str(const basic_string_char
*);
99 void __thiscall
MSVCP_basic_string_char_clear(basic_string_char
*);
100 basic_string_char
* __thiscall
MSVCP_basic_string_char_append_ch(basic_string_char
*, char);
101 MSVCP_size_t __thiscall
MSVCP_basic_string_char_length(const basic_string_char
*);
102 basic_string_char
* __thiscall
MSVCP_basic_string_char_assign(basic_string_char
*, const basic_string_char
*);
111 #define BUF_SIZE_WCHAR 8
112 wchar_t buf
[BUF_SIZE_WCHAR
];
118 #if _MSVCP_VER == 100
121 } basic_string_wchar
;
123 basic_string_wchar
* __thiscall
MSVCP_basic_string_wchar_ctor(basic_string_wchar
*);
124 basic_string_wchar
* __thiscall
MSVCP_basic_string_wchar_ctor_cstr(basic_string_wchar
*, const wchar_t*);
125 basic_string_wchar
* __thiscall
MSVCP_basic_string_wchar_ctor_cstr_len(basic_string_wchar
*, const wchar_t*, MSVCP_size_t
);
126 void __thiscall
MSVCP_basic_string_wchar_dtor(basic_string_wchar
*);
127 const wchar_t* __thiscall
MSVCP_basic_string_wchar_c_str(const basic_string_wchar
*);
128 void __thiscall
MSVCP_basic_string_wchar_clear(basic_string_wchar
*);
129 basic_string_wchar
* __thiscall
MSVCP_basic_string_wchar_append_ch(basic_string_wchar
*, wchar_t);
130 MSVCP_size_t __thiscall
MSVCP_basic_string_wchar_length(const basic_string_wchar
*);
132 char* __thiscall
MSVCP_allocator_char_allocate(void*, MSVCP_size_t
);
133 void __thiscall
MSVCP_allocator_char_deallocate(void*, char*, MSVCP_size_t
);
134 MSVCP_size_t __thiscall
MSVCP_allocator_char_max_size(const void*);
135 wchar_t* __thiscall
MSVCP_allocator_wchar_allocate(void*, MSVCP_size_t
);
136 void __thiscall
MSVCP_allocator_wchar_deallocate(void*, wchar_t*, MSVCP_size_t
);
137 MSVCP_size_t __thiscall
MSVCP_allocator_wchar_max_size(const void*);
145 _Yarn_char
* __thiscall
_Yarn_char_ctor_cstr(_Yarn_char
*, const char*);
146 _Yarn_char
* __thiscall
_Yarn_char_copy_ctor(_Yarn_char
*, const _Yarn_char
*);
147 const char* __thiscall
_Yarn_char_c_str(const _Yarn_char
*);
148 void __thiscall
_Yarn_char_dtor(_Yarn_char
*);
149 _Yarn_char
* __thiscall
_Yarn_char_op_assign(_Yarn_char
*, const _Yarn_char
*);
151 /* class locale::facet */
153 const vtable_ptr
*vtable
;
162 } codecvt_base_result
;
171 #if _MSVCP_VER >= 110
176 /* class codecvt_base */
181 /* class codecvt<char> */
186 MSVCP_bool __thiscall
codecvt_base_always_noconv(const codecvt_base
*);
187 int __thiscall
codecvt_char_unshift(const codecvt_char
*, int*, char*, char*, char**);
188 int __thiscall
codecvt_char_out(const codecvt_char
*, int*, const char*,
189 const char*, const char**, char*, char*, char**);
190 int __thiscall
codecvt_char_in(const codecvt_char
*, int*, const char*,
191 const char*, const char**, char*, char*, char**);
192 int __thiscall
codecvt_base_max_length(const codecvt_base
*);
199 /* class codecvt<wchar> */
205 int __thiscall
codecvt_wchar_unshift(const codecvt_wchar
*, int*, char*, char*, char**);
206 int __thiscall
codecvt_wchar_out(const codecvt_wchar
*, int*, const wchar_t*,
207 const wchar_t*, const wchar_t**, char*, char*, char**);
208 int __thiscall
codecvt_wchar_in(const codecvt_wchar
*, int*, const char*,
209 const char*, const char**, wchar_t*, wchar_t*, wchar_t**);
211 /* class ctype_base */
216 /* class ctype<char> */
222 MSVCP_bool __thiscall
ctype_char_is_ch(const ctype_char
*, short, char);
223 char __thiscall
ctype_char_narrow_ch(const ctype_char
*, char, char);
224 char __thiscall
ctype_char_widen_ch(const ctype_char
*, char);
226 /* class ctype<wchar> */
233 MSVCP_bool __thiscall
ctype_wchar_is_ch(const ctype_wchar
*, short, wchar_t);
234 char __thiscall
ctype_wchar_narrow_ch(const ctype_wchar
*, wchar_t, char);
235 wchar_t __thiscall
ctype_wchar_widen_ch(const ctype_wchar
*, char);
240 struct _locale__Locimp
*ptr
;
243 locale
* __thiscall
locale_ctor(locale
*);
244 locale
* __thiscall
locale_copy_ctor(locale
*, const locale
*);
245 locale
* __thiscall
locale_operator_assign(locale
*, const locale
*);
246 void __thiscall
locale_dtor(locale
*);
247 void free_locale(void);
248 codecvt_char
* codecvt_char_use_facet(const locale
*);
249 codecvt_wchar
* codecvt_wchar_use_facet(const locale
*);
250 codecvt_wchar
* codecvt_short_use_facet(const locale
*);
251 ctype_char
* ctype_char_use_facet(const locale
*);
252 ctype_wchar
* ctype_wchar_use_facet(const locale
*);
253 ctype_wchar
* ctype_short_use_facet(const locale
*);
264 #define _LOCK_LOCALE 0
265 #define _LOCK_MALLOC 1
266 #define _LOCK_STREAM 2
267 #define _LOCK_DEBUG 3
270 void init_lockit(void);
271 void free_lockit(void);
272 _Lockit
* __thiscall
_Lockit_ctor_locktype(_Lockit
*, int);
273 void __thiscall
_Lockit_dtor(_Lockit
*);
280 mutex
* __thiscall
mutex_ctor(mutex
*);
281 void __thiscall
mutex_dtor(mutex
*);
282 void __thiscall
mutex_lock(mutex
*);
283 void __thiscall
mutex_unlock(mutex
*);
286 FMTFLAG_skipws
= 0x0001,
287 FMTFLAG_unitbuf
= 0x0002,
288 FMTFLAG_uppercase
= 0x0004,
289 FMTFLAG_showbase
= 0x0008,
290 FMTFLAG_showpoint
= 0x0010,
291 FMTFLAG_showpos
= 0x0020,
292 FMTFLAG_left
= 0x0040,
293 FMTFLAG_right
= 0x0080,
294 FMTFLAG_internal
= 0x0100,
295 FMTFLAG_dec
= 0x0200,
296 FMTFLAG_oct
= 0x0400,
297 FMTFLAG_hex
= 0x0800,
298 FMTFLAG_scientific
= 0x1000,
299 FMTFLAG_fixed
= 0x2000,
300 FMTFLAG_hexfloat
= 0x3000,
301 FMTFLAG_boolalpha
= 0x4000,
302 FMTFLAG_stdio
= 0x8000,
303 FMTFLAG_adjustfield
= FMTFLAG_left
|FMTFLAG_right
|FMTFLAG_internal
,
304 FMTFLAG_basefield
= FMTFLAG_dec
|FMTFLAG_oct
|FMTFLAG_hex
,
305 FMTFLAG_floatfield
= FMTFLAG_scientific
|FMTFLAG_fixed
,
306 FMTFLAG_mask
= 0xffff
314 OPENMODE_trunc
= 0x10,
315 OPENMODE__Nocreate
= 0x40,
316 OPENMODE__Noreplace
= 0x80,
317 OPENMODE_binary
= 0x20,
329 IOSTATE_goodbit
= 0x00,
330 IOSTATE_eofbit
= 0x01,
331 IOSTATE_failbit
= 0x02,
332 IOSTATE_badbit
= 0x04,
333 IOSTATE__Hardfail
= 0x10,
337 typedef struct _iosarray
{
338 struct _iosarray
*next
;
351 typedef void (CDECL
*IOS_BASE_event_callback
)(IOS_BASE_event
, struct _ios_base
*, int);
352 typedef struct _fnarray
{
353 struct _fnarray
*next
;
355 IOS_BASE_event_callback event_handler
;
359 typedef struct _ios_base
{
360 const vtable_ptr
*vtable
;
361 #if _MSVCP_VER >= 100
362 MSVCP_size_t
DECLSPEC_ALIGN(8) stdstr
;
363 #elif _MSVCP_VER >= 71
371 IOS_BASE_iosarray
*arr
;
372 IOS_BASE_fnarray
*calls
;
383 /* class basic_streambuf<char> */
385 const vtable_ptr
*vtable
;
386 #if _MSVCP_VER >= 70 && _MSVCP_VER <= 100
406 } basic_streambuf_char
;
409 basic_streambuf_char
*strbuf
;
412 } istreambuf_iterator_char
;
416 void *iter_container
;
419 basic_streambuf_char
*strbuf
;
420 } ostreambuf_iterator_char
;
422 int __thiscall
basic_streambuf_char_sgetc(basic_streambuf_char
*);
423 int __thiscall
basic_streambuf_char_sbumpc(basic_streambuf_char
*);
424 int __thiscall
basic_streambuf_char_sputc(basic_streambuf_char
*, char);
426 /* class basic_streambuf<wchar> */
428 const vtable_ptr
*vtable
;
429 #if _MSVCP_VER >= 70 && _MSVCP_VER <= 100
449 } basic_streambuf_wchar
;
452 basic_streambuf_wchar
*strbuf
;
455 } istreambuf_iterator_wchar
;
459 void *iter_container
;
462 basic_streambuf_wchar
*strbuf
;
463 } ostreambuf_iterator_wchar
;
465 unsigned short __thiscall
basic_streambuf_wchar_sgetc(basic_streambuf_wchar
*);
466 unsigned short __thiscall
basic_streambuf_wchar_sbumpc(basic_streambuf_wchar
*);
467 unsigned short __thiscall
basic_streambuf_wchar_sputc(basic_streambuf_wchar
*, wchar_t);
470 #define IOS_LOCALE(ios) (&(ios)->loc)
472 #define IOS_LOCALE(ios) ((ios)->loc)
475 /* class num_get<char> */
481 num_get
* num_get_char_use_facet(const locale
*);
482 istreambuf_iterator_char
* __thiscall
num_get_char_get_long(const num_get
*, istreambuf_iterator_char
*,
483 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, LONG
*);
484 istreambuf_iterator_char
* __thiscall
num_get_char_get_ushort(const num_get
*, istreambuf_iterator_char
*,
485 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, unsigned short*);
486 istreambuf_iterator_char
* __thiscall
num_get_char_get_uint(const num_get
*, istreambuf_iterator_char
*,
487 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, unsigned int*);
488 istreambuf_iterator_char
* __thiscall
num_get_char_get_ulong(const num_get
*, istreambuf_iterator_char
*,
489 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, ULONG
*);
490 istreambuf_iterator_char
* __thiscall
num_get_char_get_float(const num_get
*, istreambuf_iterator_char
*,
491 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, float*);
492 istreambuf_iterator_char
*__thiscall
num_get_char_get_double(const num_get
*, istreambuf_iterator_char
*,
493 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, double*);
494 istreambuf_iterator_char
*__thiscall
num_get_char_get_ldouble(const num_get
*, istreambuf_iterator_char
*,
495 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, double*);
496 istreambuf_iterator_char
*__thiscall
num_get_char_get_void(const num_get
*, istreambuf_iterator_char
*,
497 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, void**);
498 istreambuf_iterator_char
*__thiscall
num_get_char_get_int64(const num_get
*, istreambuf_iterator_char
*,
499 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, LONGLONG
*);
500 istreambuf_iterator_char
*__thiscall
num_get_char_get_uint64(const num_get
*, istreambuf_iterator_char
*,
501 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, ULONGLONG
*);
502 istreambuf_iterator_char
*__thiscall
num_get_char_get_bool(const num_get
*, istreambuf_iterator_char
*,
503 istreambuf_iterator_char
, istreambuf_iterator_char
, ios_base
*, int*, MSVCP_bool
*);
505 num_get
* num_get_wchar_use_facet(const locale
*);
506 num_get
* num_get_short_use_facet(const locale
*);
507 istreambuf_iterator_wchar
* __thiscall
num_get_wchar_get_long(const num_get
*, istreambuf_iterator_wchar
*,
508 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, LONG
*);
509 istreambuf_iterator_wchar
* __thiscall
num_get_wchar_get_ushort(const num_get
*, istreambuf_iterator_wchar
*,
510 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, unsigned short*);
511 istreambuf_iterator_wchar
* __thiscall
num_get_wchar_get_uint(const num_get
*, istreambuf_iterator_wchar
*,
512 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, unsigned int*);
513 istreambuf_iterator_wchar
* __thiscall
num_get_wchar_get_ulong(const num_get
*, istreambuf_iterator_wchar
*,
514 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, ULONG
*);
515 istreambuf_iterator_wchar
* __thiscall
num_get_wchar_get_float(const num_get
*, istreambuf_iterator_wchar
*,
516 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, float*);
517 istreambuf_iterator_wchar
*__thiscall
num_get_wchar_get_double(const num_get
*, istreambuf_iterator_wchar
*,
518 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, double*);
519 istreambuf_iterator_wchar
*__thiscall
num_get_wchar_get_ldouble(const num_get
*, istreambuf_iterator_wchar
*,
520 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, double*);
521 istreambuf_iterator_wchar
*__thiscall
num_get_wchar_get_void(const num_get
*, istreambuf_iterator_wchar
*,
522 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, void**);
523 istreambuf_iterator_wchar
*__thiscall
num_get_wchar_get_int64(const num_get
*, istreambuf_iterator_wchar
*,
524 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, LONGLONG
*);
525 istreambuf_iterator_wchar
*__thiscall
num_get_wchar_get_uint64(const num_get
*, istreambuf_iterator_wchar
*,
526 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, ULONGLONG
*);
527 istreambuf_iterator_wchar
*__thiscall
num_get_wchar_get_bool(const num_get
*, istreambuf_iterator_wchar
*,
528 istreambuf_iterator_wchar
, istreambuf_iterator_wchar
, ios_base
*, int*, MSVCP_bool
*);
530 /* class num_put<char> */
531 /* class num_put<wchar> */
537 num_put
* num_put_char_use_facet(const locale
*);
538 ostreambuf_iterator_char
* __thiscall
num_put_char_put_long(const num_put
*, ostreambuf_iterator_char
*,
539 ostreambuf_iterator_char
, ios_base
*, char, LONG
);
540 ostreambuf_iterator_char
* __thiscall
num_put_char_put_ulong(const num_put
*, ostreambuf_iterator_char
*,
541 ostreambuf_iterator_char
, ios_base
*, char, ULONG
);
542 ostreambuf_iterator_char
* __thiscall
num_put_char_put_double(const num_put
*, ostreambuf_iterator_char
*,
543 ostreambuf_iterator_char
, ios_base
*, char, double);
544 ostreambuf_iterator_char
* __thiscall
num_put_char_put_ldouble(const num_put
*, ostreambuf_iterator_char
*,
545 ostreambuf_iterator_char
, ios_base
*, char, double);
546 ostreambuf_iterator_char
* __thiscall
num_put_char_put_ptr(const num_put
*, ostreambuf_iterator_char
*,
547 ostreambuf_iterator_char
, ios_base
*, char, const void*);
548 ostreambuf_iterator_char
* __thiscall
num_put_char_put_int64(const num_put
*, ostreambuf_iterator_char
*,
549 ostreambuf_iterator_char
, ios_base
*, char, __int64
);
550 ostreambuf_iterator_char
* __thiscall
num_put_char_put_uint64(const num_put
*, ostreambuf_iterator_char
*,
551 ostreambuf_iterator_char
, ios_base
*, char, unsigned __int64
);
552 ostreambuf_iterator_char
* __thiscall
num_put_char_put_bool(const num_put
*, ostreambuf_iterator_char
*,
553 ostreambuf_iterator_char
, ios_base
*, char, MSVCP_bool
);
555 num_put
* num_put_wchar_use_facet(const locale
*);
556 num_put
* num_put_short_use_facet(const locale
*);
557 ostreambuf_iterator_wchar
* __thiscall
num_put_wchar_put_long(const num_put
*, ostreambuf_iterator_wchar
*,
558 ostreambuf_iterator_wchar
, ios_base
*, wchar_t, LONG
);
559 ostreambuf_iterator_wchar
* __thiscall
num_put_wchar_put_ulong(const num_put
*, ostreambuf_iterator_wchar
*,
560 ostreambuf_iterator_wchar
, ios_base
*, wchar_t, ULONG
);
561 ostreambuf_iterator_wchar
* __thiscall
num_put_wchar_put_double(const num_put
*, ostreambuf_iterator_wchar
*,
562 ostreambuf_iterator_wchar
, ios_base
*, wchar_t, double);
563 ostreambuf_iterator_wchar
* __thiscall
num_put_wchar_put_ldouble(const num_put
*, ostreambuf_iterator_wchar
*,
564 ostreambuf_iterator_wchar
, ios_base
*, wchar_t, double);
565 ostreambuf_iterator_wchar
* __thiscall
num_put_wchar_put_ptr(const num_put
*, ostreambuf_iterator_wchar
*,
566 ostreambuf_iterator_wchar
, ios_base
*, wchar_t, const void*);
567 ostreambuf_iterator_wchar
* __thiscall
num_put_wchar_put_int64(const num_put
*, ostreambuf_iterator_wchar
*,
568 ostreambuf_iterator_wchar
, ios_base
*, wchar_t, __int64
);
569 ostreambuf_iterator_wchar
* __thiscall
num_put_wchar_put_uint64(const num_put
*, ostreambuf_iterator_wchar
*,
570 ostreambuf_iterator_wchar
, ios_base
*, wchar_t, unsigned __int64
);
571 ostreambuf_iterator_wchar
* __thiscall
num_put_wchar_put_bool(const num_put
*, ostreambuf_iterator_wchar
*,
572 ostreambuf_iterator_wchar
, ios_base
*, wchar_t, MSVCP_bool
);
574 void init_exception(void*);
575 void init_locale(void*);
578 void init_misc(void*);
580 /* class complex<float> */
586 /* class complex<double> */
587 /* class complex<long double> */
594 static inline int memcpy_wrapper( void *dst
, size_t size
, const void *src
, size_t count
)
596 memcpy( dst
, src
, count
);
599 static inline int memmove_wrapper( void *dst
, size_t size
, const void *src
, size_t count
)
601 memmove( dst
, src
, count
);
604 static inline int mbstowcs_wrapper( size_t *ret
, wchar_t *wcs
, size_t size
, const char *mbs
, size_t count
)
606 mbstowcs( wcs
, mbs
, count
);
609 #define memcpy_s( dst, size, src, count ) memcpy_wrapper( dst, size, src, count )
610 #define memmove_s( dst, size, src, count ) memmove_wrapper( dst, size, src, count )
611 #define mbstowcs_s( ret, wcs, size, mbs, count ) mbstowcs_wrapper( ret, wcs, size, mbs, count )
612 #define hypotf( x, y ) ((float)hypot( (double)(x), (double)(y) ))