Module: wine Branch: master Commit: 4f0c07acea299b9929eddd2250bd539745932a91 URL: https://gitlab.winehq.org/wine/wine/-/commit/4f0c07acea299b9929eddd2250bd539...
Author: Alexandre Julliard julliard@winehq.org Date: Tue May 21 20:33:25 2024 +0200
msvcrt: Unify call_copy_ctor/call_dtor implementations.
---
dlls/msvcrt/cppexcept.h | 17 +++++++++++++++++ dlls/msvcrt/except.c | 8 +------- dlls/msvcrt/except_i386.c | 3 --- dlls/msvcrt/exception_ptr.c | 44 +++++++++----------------------------------- 4 files changed, 27 insertions(+), 45 deletions(-)
diff --git a/dlls/msvcrt/cppexcept.h b/dlls/msvcrt/cppexcept.h index adde30b6d15..550033d1da0 100644 --- a/dlls/msvcrt/cppexcept.h +++ b/dlls/msvcrt/cppexcept.h @@ -101,6 +101,23 @@ static inline void *get_this_pointer( const this_ptr_offsets *off, void *object return object; }
+#ifdef __ASM_USE_THISCALL_WRAPPER +extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase ); +extern void call_dtor( void *func, void *this ); +#else +static inline void call_copy_ctor( void *func, void *this, void *src, int has_vbase ) +{ + if (has_vbase) + ((void (__thiscall*)(void*, void*, BOOL))func)(this, src, 1); + else + ((void (__thiscall*)(void*, void*))func)(this, src); +} +static inline void call_dtor( void *func, void *this ) +{ + ((void (__thiscall*)(void*))func)( this ); +} +#endif + #if _MSVCR_VER >= 80 #define EXCEPTION_MANGLED_NAME ".?AVexception@std@@" #else diff --git a/dlls/msvcrt/except.c b/dlls/msvcrt/except.c index e61e1e74e54..a7f0ed8e852 100644 --- a/dlls/msvcrt/except.c +++ b/dlls/msvcrt/except.c @@ -448,13 +448,7 @@ void CDECL __DestructExceptionObject(EXCEPTION_RECORD *rec) if (!info || !info->destructor) return;
-#if defined(__i386__) - __asm__ __volatile__("call *%0" : : "r" (info->destructor), "c" (object) : "eax", "edx", "memory" ); -#elif defined(__x86_64__) - ((void (__cdecl*)(void*))(info->destructor+rec->ExceptionInformation[3]))(object); -#else - ((void (__cdecl*)(void*))info->destructor)(object); -#endif + call_dtor( rtti_rva( info->destructor, rec->ExceptionInformation[3] ), object ); }
/********************************************************************* diff --git a/dlls/msvcrt/except_i386.c b/dlls/msvcrt/except_i386.c index 1bba898d1da..780c81a1327 100644 --- a/dlls/msvcrt/except_i386.c +++ b/dlls/msvcrt/except_i386.c @@ -148,9 +148,6 @@ DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame const cxx_function_descr *descr, catch_func_nested_frame* nested_frame );
-/* call a copy constructor */ -extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase ); - /* continue execution to the specified address after exception is caught */ extern void DECLSPEC_NORETURN continue_after_catch( cxx_exception_frame* frame, void *addr );
diff --git a/dlls/msvcrt/exception_ptr.c b/dlls/msvcrt/exception_ptr.c index b84c76822d2..d4f86d713ca 100644 --- a/dlls/msvcrt/exception_ptr.c +++ b/dlls/msvcrt/exception_ptr.c @@ -28,10 +28,8 @@ #include "msvcrt.h" #include "cppexcept.h"
-#ifdef __i386__ - -extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase ); - +/* call a copy constructor */ +#ifdef __ASM_USE_THISCALL_WRAPPER __ASM_GLOBAL_FUNC( call_copy_ctor, "pushl %ebp\n\t" __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") @@ -45,18 +43,11 @@ __ASM_GLOBAL_FUNC( call_copy_ctor, "leave\n" __ASM_CFI(".cfi_def_cfa %esp,4\n\t") __ASM_CFI(".cfi_same_value %ebp\n\t") - "ret" ); - -#elif _MSVCR_VER >= 100 - -static inline void call_copy_ctor( void *func, void *this, void *src, int has_vbase ) -{ - if (has_vbase) - ((void (__cdecl*)(void*, void*, BOOL))func)(this, src, 1); - else - ((void (__cdecl*)(void*, void*))func)(this, src); -} - + "ret" ) +__ASM_GLOBAL_FUNC( call_dtor, + "movl 8(%esp),%ecx\n\t" + "call *4(%esp)\n\t" + "ret" ) #endif
#if _MSVCR_VER >= 100 @@ -75,24 +66,6 @@ void __cdecl __ExceptionPtrCreate(exception_ptr *ep) ep->ref = NULL; }
-#ifdef __ASM_USE_THISCALL_WRAPPER -extern void call_dtor(const cxx_exception_type *type, void *func, void *object); - -__ASM_GLOBAL_FUNC( call_dtor, - "movl 12(%esp),%ecx\n\t" - "call *8(%esp)\n\t" - "ret" ); -#elif __x86_64__ -static inline void call_dtor(const cxx_exception_type *type, unsigned int dtor, void *object) -{ - char *base = RtlPcToFileHeader((void*)type, (void**)&base); - void (__cdecl *func)(void*) = (void*)(base + dtor); - func(object); -} -#else -#define call_dtor(type, func, object) ((void (__thiscall*)(void*))(func))(object) -#endif - /********************************************************************* * ?__ExceptionPtrDestroy@@YAXPAX@Z * ?__ExceptionPtrDestroy@@YAXPEAX@Z @@ -110,8 +83,9 @@ void __cdecl __ExceptionPtrDestroy(exception_ptr *ep) { const cxx_exception_type *type = (void*)ep->rec->ExceptionInformation[2]; void *obj = (void*)ep->rec->ExceptionInformation[1]; + uintptr_t base = rtti_rva_base( type );
- if (type && type->destructor) call_dtor(type, type->destructor, obj); + if (type && type->destructor) call_dtor( rtti_rva(type->destructor, base), obj ); HeapFree(GetProcessHeap(), 0, obj); }