Module: wine Branch: master Commit: ea81150e3a02f70c702a7c865156f3653dd95f09 URL: https://gitlab.winehq.org/wine/wine/-/commit/ea81150e3a02f70c702a7c865156f36...
Author: Alexandre Julliard julliard@winehq.org Date: Fri May 17 13:00:16 2024 +0200
msvcrt: Unify checks for valid C++ exception.
---
dlls/msvcrt/cpp.c | 10 ++-------- dlls/msvcrt/cppexcept.h | 8 ++++++++ dlls/msvcrt/except.c | 15 ++------------- dlls/msvcrt/except_i386.c | 5 +---- 4 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/dlls/msvcrt/cpp.c b/dlls/msvcrt/cpp.c index b4966641204..943f5936a19 100644 --- a/dlls/msvcrt/cpp.c +++ b/dlls/msvcrt/cpp.c @@ -1048,10 +1048,7 @@ int __cdecl _is_exception_typeof(const type_info *ti, EXCEPTION_POINTERS *ep) { EXCEPTION_RECORD *rec = ep->ExceptionRecord;
- if (rec->ExceptionCode==CXX_EXCEPTION && rec->NumberParameters==3 && - (rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC6 || - rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC7 || - rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC8)) + if (is_cxx_exception( rec )) { const cxx_type_info_table *tit = ((cxx_exception_type*)rec->ExceptionInformation[2])->type_info_table; int i; @@ -1086,10 +1083,7 @@ int __cdecl _is_exception_typeof(const type_info *ti, EXCEPTION_POINTERS *ep) { EXCEPTION_RECORD *rec = ep->ExceptionRecord;
- if (rec->ExceptionCode==CXX_EXCEPTION && rec->NumberParameters==4 && - (rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC6 || - rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC7 || - rec->ExceptionInformation[0]==CXX_FRAME_MAGIC_VC8)) + if (is_cxx_exception( rec )) { const cxx_exception_type *et = (cxx_exception_type*)rec->ExceptionInformation[2]; const cxx_type_info_table *tit = (const cxx_type_info_table*)(rec->ExceptionInformation[3]+et->type_info_table); diff --git a/dlls/msvcrt/cppexcept.h b/dlls/msvcrt/cppexcept.h index d5ad0f8a0f6..48b370d1be6 100644 --- a/dlls/msvcrt/cppexcept.h +++ b/dlls/msvcrt/cppexcept.h @@ -51,6 +51,14 @@ typedef DWORD (*cxx_exc_custom_handler)( PEXCEPTION_RECORD, struct __cxx_excepti void WINAPI _CxxThrowException(void*,const cxx_exception_type*); int CDECL _XcptFilter(NTSTATUS, PEXCEPTION_POINTERS);
+static inline BOOL is_cxx_exception( EXCEPTION_RECORD *rec ) +{ + if (rec->ExceptionCode != CXX_EXCEPTION) return FALSE; + if (rec->NumberParameters != CXX_EXCEPTION_PARAMS) return FALSE; + return (rec->ExceptionInformation[0] >= CXX_FRAME_MAGIC_VC6 && + rec->ExceptionInformation[0] <= CXX_FRAME_MAGIC_VC8); +} + typedef struct { EXCEPTION_RECORD *rec; diff --git a/dlls/msvcrt/except.c b/dlls/msvcrt/except.c index ce1a7525d4a..e61e1e74e54 100644 --- a/dlls/msvcrt/except.c +++ b/dlls/msvcrt/except.c @@ -298,11 +298,7 @@ BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs) return FALSE;
rec = ptrs->ExceptionRecord; - - if (rec->ExceptionCode == CXX_EXCEPTION && - rec->NumberParameters == CXX_EXCEPTION_PARAMS && - rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 && - rec->ExceptionInformation[2]) + if (is_cxx_exception( rec ) && rec->ExceptionInformation[2]) { ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record; return TRUE; @@ -447,14 +443,7 @@ void CDECL __DestructExceptionObject(EXCEPTION_RECORD *rec)
TRACE("(%p)\n", rec);
- if (rec->ExceptionCode != CXX_EXCEPTION) return; -#ifndef __x86_64__ - if (rec->NumberParameters != 3) return; -#else - if (rec->NumberParameters != 4) return; -#endif - if (rec->ExceptionInformation[0] < CXX_FRAME_MAGIC_VC6 || - rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8) return; + if (!is_cxx_exception( rec )) return;
if (!info || !info->destructor) return; diff --git a/dlls/msvcrt/except_i386.c b/dlls/msvcrt/except_i386.c index 8ae6056ff8f..1bba898d1da 100644 --- a/dlls/msvcrt/except_i386.c +++ b/dlls/msvcrt/except_i386.c @@ -477,10 +477,7 @@ int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs, if (!ti) return EXCEPTION_EXECUTE_HANDLER;
rec = ptrs->ExceptionRecord; - if (rec->ExceptionCode != CXX_EXCEPTION || rec->NumberParameters != 3 || - rec->ExceptionInformation[0] < CXX_FRAME_MAGIC_VC6 || - rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8) - return EXCEPTION_CONTINUE_SEARCH; + if (!is_cxx_exception( rec )) return EXCEPTION_CONTINUE_SEARCH;
if (rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0) {