msvcrt: Unify call_copy_ctor/call_dtor implementations.

This commit is contained in:
Alexandre Julliard 2024-05-21 20:33:25 +02:00
parent f25a4043dd
commit 4f0c07acea
4 changed files with 27 additions and 45 deletions

View file

@ -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

View file

@ -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 );
}
/*********************************************************************

View file

@ -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 );

View file

@ -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);
}