Module: wine Branch: master Commit: 28f5e7ac9ad054ec3c7723be4d718834c83d03c7 URL: https://gitlab.winehq.org/wine/wine/-/commit/28f5e7ac9ad054ec3c7723be4d71883...
Author: Alexandre Julliard julliard@winehq.org Date: Fri May 31 12:08:14 2024 +0200
msvcrt: Share the find_caught_type() helper between platforms.
---
dlls/msvcrt/cppexcept.h | 27 +++++++++++++++++++++++++++ dlls/msvcrt/except_i386.c | 30 ++---------------------------- dlls/msvcrt/except_x86_64.c | 27 --------------------------- dlls/msvcrt/handler4.c | 26 -------------------------- 4 files changed, 29 insertions(+), 81 deletions(-)
diff --git a/dlls/msvcrt/cppexcept.h b/dlls/msvcrt/cppexcept.h index ef8a2944c04..37a498c41d8 100644 --- a/dlls/msvcrt/cppexcept.h +++ b/dlls/msvcrt/cppexcept.h @@ -203,6 +203,33 @@ static inline void call_dtor( void *func, void *this ) } #endif
+/* check if the exception type is caught by a given catch block, and return the type that matched */ +static inline const cxx_type_info *find_caught_type( cxx_exception_type *exc_type, uintptr_t base, + const type_info *catch_ti, UINT catch_flags ) +{ + const cxx_type_info_table *type_info_table = rtti_rva( exc_type->type_info_table, base ); + UINT i; + + for (i = 0; i < type_info_table->count; i++) + { + const cxx_type_info *type = rtti_rva( type_info_table->info[i], base ); + const type_info *ti = rtti_rva( type->type_info, base ); + + if (!catch_ti) return type; /* catch(...) matches any type */ + if (catch_ti != ti) + { + if (strcmp( catch_ti->mangled, ti->mangled )) continue; + } + /* type is the same, now check the flags */ + if ((exc_type->flags & TYPE_FLAG_CONST) && + !(catch_flags & TYPE_FLAG_CONST)) continue; + if ((exc_type->flags & TYPE_FLAG_VOLATILE) && + !(catch_flags & TYPE_FLAG_VOLATILE)) continue; + return type; /* it matched */ + } + return NULL; +} + #if _MSVCR_VER >= 80 #define EXCEPTION_MANGLED_NAME ".?AVexception@std@@" #else diff --git a/dlls/msvcrt/except_i386.c b/dlls/msvcrt/except_i386.c index d20b08d00c3..c326b24d54c 100644 --- a/dlls/msvcrt/except_i386.c +++ b/dlls/msvcrt/except_i386.c @@ -206,32 +206,6 @@ static void dump_function_descr( const cxx_function_descr *descr ) TRACE( "flags: %08x\n", descr->flags ); }
-/* check if the exception type is caught by a given catch block, and return the type that matched */ -static const cxx_type_info *find_caught_type( cxx_exception_type *exc_type, - const type_info *catch_ti, UINT catch_flags ) -{ - UINT i; - - for (i = 0; i < exc_type->type_info_table->count; i++) - { - const cxx_type_info *type = exc_type->type_info_table->info[i]; - - if (!catch_ti) return type; /* catch(...) matches any type */ - if (catch_ti != type->type_info) - { - if (strcmp( catch_ti->mangled, type->type_info->mangled )) continue; - } - /* type is the same, now check the flags */ - if ((exc_type->flags & TYPE_FLAG_CONST) && - !(catch_flags & TYPE_FLAG_CONST)) continue; - if ((exc_type->flags & TYPE_FLAG_VOLATILE) && - !(catch_flags & TYPE_FLAG_VOLATILE)) continue; - return type; /* it matched */ - } - return NULL; -} - - /* copy the exception object where the catch block wants it */ static void copy_exception( void *object, cxx_exception_frame *frame, const catchblock_info *catchblock, const cxx_type_info *type ) @@ -363,7 +337,7 @@ static inline void call_catch_block( PEXCEPTION_RECORD rec, CONTEXT *context, const catchblock_info *catchblock = &tryblock->catchblock[j]; if(info) { - const cxx_type_info *type = find_caught_type( info, + const cxx_type_info *type = find_caught_type( info, 0, catchblock->type_info, catchblock->flags ); if (!type) continue;
@@ -444,7 +418,7 @@ int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs, if (!rec) return EXCEPTION_CONTINUE_SEARCH; }
- type = find_caught_type( (cxx_exception_type*)rec->ExceptionInformation[2], ti, flags ); + type = find_caught_type( (cxx_exception_type*)rec->ExceptionInformation[2], 0, ti, flags ); if (!type) return EXCEPTION_CONTINUE_SEARCH;
if (copy) diff --git a/dlls/msvcrt/except_x86_64.c b/dlls/msvcrt/except_x86_64.c index ed82755e182..2afbdc821da 100644 --- a/dlls/msvcrt/except_x86_64.c +++ b/dlls/msvcrt/except_x86_64.c @@ -151,33 +151,6 @@ static inline int ip_to_state(ipmap_info *ipmap, UINT count, int ip) return ipmap[low].state; }
-/* check if the exception type is caught by a given catch block, and return the type that matched */ -static const cxx_type_info *find_caught_type(cxx_exception_type *exc_type, ULONG64 exc_base, - const type_info *catch_ti, UINT catch_flags) -{ - const cxx_type_info_table *type_info_table = rva_to_ptr(exc_type->type_info_table, exc_base); - UINT i; - - for (i = 0; i < type_info_table->count; i++) - { - const cxx_type_info *type = rva_to_ptr(type_info_table->info[i], exc_base); - const type_info *ti = rva_to_ptr(type->type_info, exc_base); - - if (!catch_ti) return type; /* catch(...) matches any type */ - if (catch_ti != ti) - { - if (strcmp( catch_ti->mangled, ti->mangled )) continue; - } - /* type is the same, now check the flags */ - if ((exc_type->flags & TYPE_FLAG_CONST) && - !(catch_flags & TYPE_FLAG_CONST)) continue; - if ((exc_type->flags & TYPE_FLAG_VOLATILE) && - !(catch_flags & TYPE_FLAG_VOLATILE)) continue; - return type; /* it matched */ - } - return NULL; -} - static inline void copy_exception(void *object, ULONG64 frame, DISPATCHER_CONTEXT *dispatch, const catchblock_info *catchblock, diff --git a/dlls/msvcrt/handler4.c b/dlls/msvcrt/handler4.c index 560302d7d64..9bfde4b7ca2 100644 --- a/dlls/msvcrt/handler4.c +++ b/dlls/msvcrt/handler4.c @@ -359,32 +359,6 @@ static inline int ip_to_state4(BYTE *ip_map, UINT count, DISPATCHER_CONTEXT *dis return ret; }
-static const cxx_type_info *find_caught_type(cxx_exception_type *exc_type, ULONG64 exc_base, - const type_info *catch_ti, UINT catch_flags) -{ - const cxx_type_info_table *type_info_table = rva_to_ptr(exc_type->type_info_table, exc_base); - UINT i; - - for (i = 0; i < type_info_table->count; i++) - { - const cxx_type_info *type = rva_to_ptr(type_info_table->info[i], exc_base); - const type_info *ti = rva_to_ptr(type->type_info, exc_base); - - if (!catch_ti) return type; /* catch(...) matches any type */ - if (catch_ti != ti) - { - if (strcmp( catch_ti->mangled, ti->mangled )) continue; - } - /* type is the same, now check the flags */ - if ((exc_type->flags & TYPE_FLAG_CONST) && - !(catch_flags & TYPE_FLAG_CONST)) continue; - if ((exc_type->flags & TYPE_FLAG_VOLATILE) && - !(catch_flags & TYPE_FLAG_VOLATILE)) continue; - return type; /* it matched */ - } - return NULL; -} - static inline void copy_exception(void *object, ULONG64 frame, DISPATCHER_CONTEXT *dispatch, const catchblock_info_v4 *catchblock, const cxx_type_info *type, ULONG64 exc_base) {