From c57f5d98aba8bdf5f41be665dd74d8cd7b5a3113 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Tue, 12 Sep 2023 20:53:53 +0200 Subject: [PATCH] msvcp110: Add _Throw_C_error implementation. --- 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 #include #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 -- 2.11.4.GIT