From: Piotr Caban piotr@codeweavers.com
--- dlls/msvcp90/exception.c | 14 +++----- dlls/msvcp90/misc.c | 70 ++++++++++++++++++++++++++-------------- dlls/msvcp90/msvcp90.h | 14 ++++++++ 3 files changed, 63 insertions(+), 35 deletions(-)
diff --git a/dlls/msvcp90/exception.c b/dlls/msvcp90/exception.c index 63c698f3c6c..949b896bb2e 100644 --- a/dlls/msvcp90/exception.c +++ b/dlls/msvcp90/exception.c @@ -637,7 +637,7 @@ DEFINE_CXX_DATA1(runtime_error, &exception_cxx_type_info, MSVCP_runtime_error_dt typedef struct { runtime_error base; #if _MSVCP_VER > 90 - int err; + error_code code; #endif } system_error; typedef system_error _System_error; @@ -648,8 +648,8 @@ static failure* MSVCP_failure_ctor( failure *this, exception_name name ) TRACE("%p %s\n", this, EXCEPTION_STR(name)); MSVCP_runtime_error_ctor(&this->base, name); #if _MSVCP_VER > 90 - /* FIXME: set err correctly */ - this->err = 0; + this->code.code = 1; + this->code.category = std_iostream_category(); #endif this->base.e.vtable = &failure_vtable; return this; @@ -662,7 +662,7 @@ failure* __thiscall failure_copy_ctor( TRACE("%p %p\n", this, rhs); runtime_error_copy_ctor(&this->base, &rhs->base); #if _MSVCP_VER > 90 - this->err = rhs->err; + this->code = rhs->code; #endif this->base.e.vtable = &failure_vtable; return this; @@ -948,12 +948,6 @@ bool __cdecl MSVCP__uncaught_exception(void) }
#if _MSVCP_VER >= 110 -typedef struct -{ - int code; - void *category; -} error_code; - typedef struct { logic_error base; diff --git a/dlls/msvcp90/misc.c b/dlls/msvcp90/misc.c index 103eca6f4a3..8b9514c6edb 100644 --- a/dlls/msvcp90/misc.c +++ b/dlls/msvcp90/misc.c @@ -997,11 +997,7 @@ void __cdecl _Cnd_do_broadcast_at_thread_exit(void)
#endif
-#if _MSVCP_VER == 100 -typedef struct { - const vtable_ptr *vtable; -} error_category; - +#if _MSVCP_VER >= 100 typedef struct { error_category base; const char *type; @@ -1009,14 +1005,22 @@ typedef struct { static custom_category iostream_category;
DEFINE_RTTI_DATA0(error_category, 0, ".?AVerror_category@std@@") +DEFINE_RTTI_DATA1(generic_category, 0, &error_category_rtti_base_descriptor, ".?AV_Generic_error_category@std@@") +#if _MSVCP_VER == 100 DEFINE_RTTI_DATA1(iostream_category, 0, &error_category_rtti_base_descriptor, ".?AV_Iostream_error_category@std@@") +#else +DEFINE_RTTI_DATA2(iostream_category, 0, &generic_category_rtti_base_descriptor, + &error_category_rtti_base_descriptor, ".?AV_Iostream_error_category@std@@") +#endif
extern const vtable_ptr iostream_category_vtable;
static void iostream_category_ctor(custom_category *this) { this->base.vtable = &iostream_category_vtable; +#if _MSVCP_VER == 100 this->type = "iostream"; +#endif }
DEFINE_THISCALL_WRAPPER(custom_category_vector_dtor, 8) @@ -1037,19 +1041,6 @@ custom_category* __thiscall custom_category_vector_dtor(custom_category *this, u return this; }
-DEFINE_THISCALL_WRAPPER(custom_category_name, 4) -const char* __thiscall custom_category_name(const custom_category *this) -{ - return this->type; -} - -DEFINE_THISCALL_WRAPPER(custom_category_message, 12) -basic_string_char* __thiscall custom_category_message(const custom_category *this, - basic_string_char *ret, int err) -{ - return MSVCP_basic_string_char_ctor_cstr(ret, strerror(err)); -} - DEFINE_THISCALL_WRAPPER(custom_category_default_error_condition, 12) /*error_condition*/void* __thiscall custom_category_default_error_condition( custom_category *this, /*error_condition*/void *ret, int code) @@ -1068,12 +1059,22 @@ bool __thiscall custom_category_equivalent(const custom_category *this,
DEFINE_THISCALL_WRAPPER(custom_category_equivalent_code, 12) bool __thiscall custom_category_equivalent_code(custom_category *this, - const /*error_code*/void *code, int condition) + const error_code *code, int condition) { FIXME("(%p %p %x) stub\n", this, code, condition); return FALSE; }
+DEFINE_THISCALL_WRAPPER(iostream_category_name, 4) +const char* __thiscall iostream_category_name(const custom_category *this) +{ +#if _MSVCP_VER == 100 + return this->type; +#else + return "iostream"; +#endif +} + DEFINE_THISCALL_WRAPPER(iostream_category_message, 12) basic_string_char* __thiscall iostream_category_message(const custom_category *this, basic_string_char *ret, int err) @@ -1089,7 +1090,9 @@ const error_category* __cdecl std_iostream_category(void) TRACE("()\n"); return &iostream_category.base; } +#endif
+#if _MSVCP_VER == 100 static custom_category system_category; DEFINE_RTTI_DATA1(system_category, 0, &error_category_rtti_base_descriptor, ".?AV_System_error_category@std@@")
@@ -1101,6 +1104,19 @@ static void system_category_ctor(custom_category *this) this->type = "system"; }
+DEFINE_THISCALL_WRAPPER(custom_category_name, 4) +const char* __thiscall custom_category_name(const custom_category *this) +{ + return this->type; +} + +DEFINE_THISCALL_WRAPPER(custom_category_message, 12) +basic_string_char* __thiscall custom_category_message(const custom_category *this, + basic_string_char *ret, int err) +{ + return MSVCP_basic_string_char_ctor_cstr(ret, strerror(err)); +} + /* ?system_category@std@@YAABVerror_category@1@XZ */ /* ?system_category@std@@YAAEBVerror_category@1@XZ */ const error_category* __cdecl std_system_category(void) @@ -1110,7 +1126,6 @@ const error_category* __cdecl std_system_category(void) }
static custom_category generic_category; -DEFINE_RTTI_DATA1(generic_category, 0, &error_category_rtti_base_descriptor, ".?AV_Generic_error_category@std@@")
extern const vtable_ptr generic_category_vtable;
@@ -1686,14 +1701,14 @@ int __cdecl _Winerror_map(int err)
#if _MSVCP_VER >= 100 __ASM_BLOCK_BEGIN(misc_vtables) -#if _MSVCP_VER == 100 __ASM_VTABLE(iostream_category, VTABLE_ADD_FUNC(custom_category_vector_dtor) - VTABLE_ADD_FUNC(custom_category_name) + VTABLE_ADD_FUNC(iostream_category_name) VTABLE_ADD_FUNC(iostream_category_message) VTABLE_ADD_FUNC(custom_category_default_error_condition) VTABLE_ADD_FUNC(custom_category_equivalent) VTABLE_ADD_FUNC(custom_category_equivalent_code)); +#if _MSVCP_VER == 100 __ASM_VTABLE(system_category, VTABLE_ADD_FUNC(custom_category_vector_dtor) VTABLE_ADD_FUNC(custom_category_name) @@ -1718,19 +1733,24 @@ __ASM_BLOCK_END void init_misc(void *base) { #ifdef __x86_64__ -#if _MSVCP_VER == 100 +#if _MSVCP_VER >= 100 init_error_category_rtti(base); + init_generic_category_rtti(base); init_iostream_category_rtti(base); +#endif +#if _MSVCP_VER == 100 init_system_category_rtti(base); - init_generic_category_rtti(base); #endif #if _MSVCP_VER >= 110 init__Pad_rtti(base); #endif #endif
-#if _MSVCP_VER == 100 +#if _MSVCP_VER >= 100 iostream_category_ctor(&iostream_category); +#endif + +#if _MSVCP_VER == 100 system_category_ctor(&system_category); generic_category_ctor(&generic_category); #endif diff --git a/dlls/msvcp90/msvcp90.h b/dlls/msvcp90/msvcp90.h index c9e8e05566c..a674d0704b1 100644 --- a/dlls/msvcp90/msvcp90.h +++ b/dlls/msvcp90/msvcp90.h @@ -668,6 +668,20 @@ typedef struct { double imag; } complex_double;
+#if _MSVCP_VER >= 100 +typedef struct { + const vtable_ptr *vtable; +} error_category; + +const error_category* __cdecl std_iostream_category(void); + +typedef struct +{ + int code; + const error_category *category; +} error_code; +#endif + #if _MSVCP_VER < 80 static inline int memcpy_wrapper( void *dst, size_t size, const void *src, size_t count ) {
From: Piotr Caban piotr@codeweavers.com
--- dlls/msvcp110/msvcp110.spec | 2 +- dlls/msvcp120/msvcp120.spec | 2 +- dlls/msvcp120_app/msvcp120_app.spec | 2 +- dlls/msvcp140/msvcp140.spec | 2 +- dlls/msvcp90/exception.c | 52 +++++++++++++++++++++++++++-- dlls/msvcp90/misc.c | 34 +++++++++++++------ dlls/msvcp90/msvcp90.h | 1 + dlls/msvcp_win/msvcp_win.spec | 2 +- 8 files changed, 80 insertions(+), 17 deletions(-)
diff --git a/dlls/msvcp110/msvcp110.spec b/dlls/msvcp110/msvcp110.spec index 4326e9a4589..1a100676743 100644 --- a/dlls/msvcp110/msvcp110.spec +++ b/dlls/msvcp110/msvcp110.spec @@ -1778,7 +1778,7 @@ @ extern ?_Sync@ios_base@std@@0_NA ios_base_Sync @ cdecl -arch=win32 ?_Syserror_map@std@@YAPBDH@Z(long) _Syserror_map @ cdecl -arch=win64 ?_Syserror_map@std@@YAPEBDH@Z(long) _Syserror_map -@ stub ?_Throw_C_error@std@@YAXH@Z +@ cdecl ?_Throw_C_error@std@@YAXH@Z(long) _Throw_C_error @ stub ?_Throw_Cpp_error@std@@YAXH@Z @ cdecl -arch=win32 ?_Throw_future_error@std@@YAXABVerror_code@1@@Z(ptr) _Throw_future_error @ cdecl -arch=win64 ?_Throw_future_error@std@@YAXAEBVerror_code@1@@Z(ptr) _Throw_future_error diff --git a/dlls/msvcp120/msvcp120.spec b/dlls/msvcp120/msvcp120.spec index 615172a3376..b95330179e5 100644 --- a/dlls/msvcp120/msvcp120.spec +++ b/dlls/msvcp120/msvcp120.spec @@ -1739,7 +1739,7 @@ @ extern ?_Sync@ios_base@std@@0_NA ios_base_Sync @ cdecl -arch=win32 ?_Syserror_map@std@@YAPBDH@Z(long) _Syserror_map @ cdecl -arch=win64 ?_Syserror_map@std@@YAPEBDH@Z(long) _Syserror_map -@ stub ?_Throw_C_error@std@@YAXH@Z +@ cdecl ?_Throw_C_error@std@@YAXH@Z(long) _Throw_C_error @ stub ?_Throw_Cpp_error@std@@YAXH@Z @ cdecl -arch=win32 ?_Throw_future_error@std@@YAXABVerror_code@1@@Z(ptr) _Throw_future_error @ cdecl -arch=win64 ?_Throw_future_error@std@@YAXAEBVerror_code@1@@Z(ptr) _Throw_future_error diff --git a/dlls/msvcp120_app/msvcp120_app.spec b/dlls/msvcp120_app/msvcp120_app.spec index b8f7e4b69e2..9155a90e554 100644 --- a/dlls/msvcp120_app/msvcp120_app.spec +++ b/dlls/msvcp120_app/msvcp120_app.spec @@ -1739,7 +1739,7 @@ @ extern ?_Sync@ios_base@std@@0_NA msvcp120.?_Sync@ios_base@std@@0_NA @ cdecl -arch=win32 ?_Syserror_map@std@@YAPBDH@Z(long) msvcp120.?_Syserror_map@std@@YAPBDH@Z @ cdecl -arch=win64 ?_Syserror_map@std@@YAPEBDH@Z(long) msvcp120.?_Syserror_map@std@@YAPEBDH@Z -@ stub ?_Throw_C_error@std@@YAXH@Z +@ cdecl ?_Throw_C_error@std@@YAXH@Z(long) msvcp120.?_Throw_C_error@std@@YAXH@Z @ stub ?_Throw_Cpp_error@std@@YAXH@Z @ cdecl -arch=win32 ?_Throw_future_error@std@@YAXABVerror_code@1@@Z(ptr) msvcp120.?_Throw_future_error@std@@YAXABVerror_code@1@@Z @ cdecl -arch=win64 ?_Throw_future_error@std@@YAXAEBVerror_code@1@@Z(ptr) msvcp120.?_Throw_future_error@std@@YAXAEBVerror_code@1@@Z diff --git a/dlls/msvcp140/msvcp140.spec b/dlls/msvcp140/msvcp140.spec index 258a5acc648..a1a33787f31 100644 --- a/dlls/msvcp140/msvcp140.spec +++ b/dlls/msvcp140/msvcp140.spec @@ -1623,7 +1623,7 @@ @ extern ?_Sync@ios_base@std@@0_NA ios_base_Sync @ cdecl -arch=win32 ?_Syserror_map@std@@YAPBDH@Z(long) _Syserror_map @ cdecl -arch=win64 ?_Syserror_map@std@@YAPEBDH@Z(long) _Syserror_map -@ stub ?_Throw_C_error@std@@YAXH@Z +@ cdecl ?_Throw_C_error@std@@YAXH@Z(long) _Throw_C_error @ stub ?_Throw_Cpp_error@std@@YAXH@Z @ cdecl -arch=win32 ?_Throw_future_error@std@@YAXABVerror_code@1@@Z(ptr) _Throw_future_error @ cdecl -arch=win64 ?_Throw_future_error@std@@YAXAEBVerror_code@1@@Z(ptr) _Throw_future_error diff --git a/dlls/msvcp90/exception.c b/dlls/msvcp90/exception.c index 949b896bb2e..ee59dbf2112 100644 --- a/dlls/msvcp90/exception.c +++ b/dlls/msvcp90/exception.c @@ -16,6 +16,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#include <errno.h> #include <stdarg.h>
#include "msvcp90.h" @@ -722,7 +723,9 @@ DEFINE_RTTI_DATA4(failure, 0, &system_error_rtti_base_descriptor, &_System_error_rtti_base_descriptor, &runtime_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVfailure@ios_base@std@@") DEFINE_CXX_TYPE_INFO(_System_error) -DEFINE_CXX_TYPE_INFO(system_error); +DEFINE_CXX_DATA3(system_error, &_System_error_cxx_type_info, + &runtime_error_cxx_type_info, &exception_cxx_type_info, + MSVCP_runtime_error_dtor) DEFINE_CXX_DATA4(failure, &system_error_cxx_type_info, &_System_error_cxx_type_info, &runtime_error_cxx_type_info, &exception_cxx_type_info, MSVCP_runtime_error_dtor) @@ -732,7 +735,12 @@ DEFINE_RTTI_DATA2(system_error, 0, &runtime_error_rtti_base_descriptor, DEFINE_RTTI_DATA3(failure, 0, &system_error_rtti_base_descriptor, &runtime_error_rtti_base_descriptor, &exception_rtti_base_descriptor, ".?AVfailure@ios_base@std@@") +#if _MSVCP_VER == 100 DEFINE_CXX_TYPE_INFO(system_error); +#else +DEFINE_CXX_DATA2(system_error, &runtime_error_cxx_type_info, + &exception_cxx_type_info, MSVCP_runtime_error_dtor) +#endif DEFINE_CXX_DATA3(failure, &system_error_cxx_type_info, &runtime_error_cxx_type_info, &exception_cxx_type_info, MSVCP_runtime_error_dtor) #else @@ -1033,6 +1041,44 @@ void __cdecl _Rethrow_future_exception(const exception_ptr ep) { exception_ptr_rethrow(&ep); } + +/* ?_Throw_C_error@std@@YAXH@Z */ +void __cdecl _Throw_C_error(int code) +{ + system_error se; + const char *msg; + errno_t err; + + TRACE("(%d)\n", code); + + switch(code) + { + case 1: + case 2: + err = EAGAIN; + break; + case 3: + err = EBUSY; + break; + case 4: + err = EINVAL; + break; + default: +#if _MSVCP_VER >= 140 + abort(); +#else + return; +#endif + } + + msg = strerror(err); + MSVCP_runtime_error_ctor(&se.base, &msg); + se.code.code = err; + se.code.category = std_generic_category(); + se.base.e.vtable = &system_error_vtable; + + _CxxThrowException(&se, &system_error_cxx_type); +} #endif
#if _MSVCP_VER >= 140 @@ -1509,8 +1555,10 @@ void init_exception(void *base) #if _MSVCP_VER > 110 init__System_error_cxx_type_info(base); #endif -#if _MSVCP_VER > 90 +#if _MSVCP_VER == 100 init_system_error_cxx_type_info(base); +#elif _MSVCP_VER > 100 + init_system_error_cxx(base); #endif init_failure_cxx(base); init_range_error_cxx(base); diff --git a/dlls/msvcp90/misc.c b/dlls/msvcp90/misc.c index 8b9514c6edb..ada8ee967d8 100644 --- a/dlls/msvcp90/misc.c +++ b/dlls/msvcp90/misc.c @@ -1110,13 +1110,6 @@ const char* __thiscall custom_category_name(const custom_category *this) return this->type; }
-DEFINE_THISCALL_WRAPPER(custom_category_message, 12) -basic_string_char* __thiscall custom_category_message(const custom_category *this, - basic_string_char *ret, int err) -{ - return MSVCP_basic_string_char_ctor_cstr(ret, strerror(err)); -} - /* ?system_category@std@@YAABVerror_category@1@XZ */ /* ?system_category@std@@YAAEBVerror_category@1@XZ */ const error_category* __cdecl std_system_category(void) @@ -1124,7 +1117,9 @@ const error_category* __cdecl std_system_category(void) TRACE("()\n"); return &system_category.base; } +#endif
+#if _MSVCP_VER >= 100 static custom_category generic_category;
extern const vtable_ptr generic_category_vtable; @@ -1132,7 +1127,26 @@ extern const vtable_ptr generic_category_vtable; static void generic_category_ctor(custom_category *this) { this->base.vtable = &generic_category_vtable; +#if _MSVCP_VER == 100 this->type = "generic"; +#endif +} + +DEFINE_THISCALL_WRAPPER(generic_category_name, 4) +const char* __thiscall generic_category_name(const custom_category *this) +{ +#if _MSVCP_VER == 100 + return this->type; +#else + return "generic"; +#endif +} + +DEFINE_THISCALL_WRAPPER(custom_category_message, 12) +basic_string_char* __thiscall custom_category_message(const custom_category *this, + basic_string_char *ret, int err) +{ + return MSVCP_basic_string_char_ctor_cstr(ret, strerror(err)); }
/* ?generic_category@std@@YAABVerror_category@1@XZ */ @@ -1716,14 +1730,14 @@ __ASM_BLOCK_BEGIN(misc_vtables) VTABLE_ADD_FUNC(custom_category_default_error_condition) VTABLE_ADD_FUNC(custom_category_equivalent) VTABLE_ADD_FUNC(custom_category_equivalent_code)); +#endif __ASM_VTABLE(generic_category, VTABLE_ADD_FUNC(custom_category_vector_dtor) - VTABLE_ADD_FUNC(custom_category_name) + VTABLE_ADD_FUNC(generic_category_name) VTABLE_ADD_FUNC(custom_category_message) VTABLE_ADD_FUNC(custom_category_default_error_condition) VTABLE_ADD_FUNC(custom_category_equivalent) VTABLE_ADD_FUNC(custom_category_equivalent_code)); -#endif #if _MSVCP_VER >= 110 __ASM_VTABLE(_Pad, VTABLE_ADD_FUNC(_Pad__Go)); @@ -1748,11 +1762,11 @@ void init_misc(void *base)
#if _MSVCP_VER >= 100 iostream_category_ctor(&iostream_category); + generic_category_ctor(&generic_category); #endif
#if _MSVCP_VER == 100 system_category_ctor(&system_category); - generic_category_ctor(&generic_category); #endif }
diff --git a/dlls/msvcp90/msvcp90.h b/dlls/msvcp90/msvcp90.h index a674d0704b1..69f1785a32b 100644 --- a/dlls/msvcp90/msvcp90.h +++ b/dlls/msvcp90/msvcp90.h @@ -674,6 +674,7 @@ typedef struct { } error_category;
const error_category* __cdecl std_iostream_category(void); +const error_category* __cdecl std_generic_category(void);
typedef struct { diff --git a/dlls/msvcp_win/msvcp_win.spec b/dlls/msvcp_win/msvcp_win.spec index 99b34ccc9ac..a2107ea198a 100644 --- a/dlls/msvcp_win/msvcp_win.spec +++ b/dlls/msvcp_win/msvcp_win.spec @@ -1623,7 +1623,7 @@ @ extern ?_Sync@ios_base@std@@0_NA msvcp140.?_Sync@ios_base@std@@0_NA @ cdecl -arch=win32 ?_Syserror_map@std@@YAPBDH@Z(long) msvcp140.?_Syserror_map@std@@YAPBDH@Z @ cdecl -arch=win64 ?_Syserror_map@std@@YAPEBDH@Z(long) msvcp140.?_Syserror_map@std@@YAPEBDH@Z -@ stub ?_Throw_C_error@std@@YAXH@Z +@ cdecl ?_Throw_C_error@std@@YAXH@Z(long) msvcp140.?_Throw_C_error@std@@YAXH@Z @ stub ?_Throw_Cpp_error@std@@YAXH@Z @ cdecl -arch=win32 ?_Throw_future_error@std@@YAXABVerror_code@1@@Z(ptr) msvcp140.?_Throw_future_error@std@@YAXABVerror_code@1@@Z @ cdecl -arch=win64 ?_Throw_future_error@std@@YAXAEBVerror_code@1@@Z(ptr) msvcp140.?_Throw_future_error@std@@YAXAEBVerror_code@1@@Z