From 6d2426840ab24b21842e187ecc1428f2f97e1a9e Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Wed, 24 Jul 2024 15:14:22 +0200 Subject: [PATCH 1/2] Add signature check for swiftcall --- src/mono/mono/mini/interp/transform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 2b5e4c2c3fe619..f77a4a85e6e627 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -4486,8 +4486,6 @@ interp_method_compute_offsets (TransformData *td, InterpMethod *imethod, MonoMet #ifdef MONO_ARCH_HAVE_SWIFTCALL int swift_error_index = -1; imethod->swift_error_offset = -1; - MonoClass *swift_error = mono_class_try_get_swift_error_class (); - MonoClass *swift_error_ptr = mono_class_create_ptr (m_class_get_this_arg (swift_error)); #endif /* @@ -4517,6 +4515,8 @@ interp_method_compute_offsets (TransformData *td, InterpMethod *imethod, MonoMet #ifdef MONO_ARCH_HAVE_SWIFTCALL if (swift_error_index < 0 && mono_method_signature_has_ext_callconv (sig, MONO_EXT_CALLCONV_SWIFTCALL)) { + MonoClass *swift_error = mono_class_try_get_swift_error_class (); + MonoClass *swift_error_ptr = mono_class_create_ptr (m_class_get_this_arg (swift_error)); MonoClass *klass = mono_class_from_mono_type_internal (type); if (klass == swift_error_ptr) swift_error_index = i; From 6481c1440526051302b8cb861e380bf2d1d2f238 Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Thu, 25 Jul 2024 14:52:58 +0200 Subject: [PATCH 2/2] Handle null values for swift_error_ptr --- src/mono/mono/metadata/marshal.c | 2 +- src/mono/mono/mini/interp/transform.c | 2 +- src/mono/mono/mini/mini-amd64.c | 4 ++-- src/mono/mono/mini/mini-arm64.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index 96b8a5fe96de05..5e8fcc4dfd4081 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -3702,7 +3702,7 @@ mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions, MonoClass *swift_self_t = mono_class_try_get_swift_self_t_class (); MonoClass *swift_error = mono_class_try_get_swift_error_class (); MonoClass *swift_indirect_result = mono_class_try_get_swift_indirect_result_class (); - MonoClass *swift_error_ptr = mono_class_create_ptr (m_class_get_this_arg (swift_error)); + MonoClass *swift_error_ptr = swift_error ? mono_class_create_ptr (m_class_get_this_arg (swift_error)) : NULL; int swift_error_args = 0, swift_self_args = 0, swift_indirect_result_args = 0; for (int i = 0; i < method->signature->param_count; ++i) { MonoClass *param_klass = mono_class_from_mono_type_internal (method->signature->params [i]); diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index f77a4a85e6e627..1af7c2d514b234 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -4516,7 +4516,7 @@ interp_method_compute_offsets (TransformData *td, InterpMethod *imethod, MonoMet #ifdef MONO_ARCH_HAVE_SWIFTCALL if (swift_error_index < 0 && mono_method_signature_has_ext_callconv (sig, MONO_EXT_CALLCONV_SWIFTCALL)) { MonoClass *swift_error = mono_class_try_get_swift_error_class (); - MonoClass *swift_error_ptr = mono_class_create_ptr (m_class_get_this_arg (swift_error)); + MonoClass *swift_error_ptr = swift_error ? mono_class_create_ptr (m_class_get_this_arg (swift_error)) : NULL; MonoClass *klass = mono_class_from_mono_type_internal (type); if (klass == swift_error_ptr) swift_error_index = i; diff --git a/src/mono/mono/mini/mini-amd64.c b/src/mono/mono/mini/mini-amd64.c index 096fcea3e01d90..a73b59782eea42 100644 --- a/src/mono/mono/mini/mini-amd64.c +++ b/src/mono/mono/mini/mini-amd64.c @@ -1089,7 +1089,7 @@ get_call_info (MonoMemPool *mp, MonoMethodSignature *sig) MonoClass *swift_self = mono_class_try_get_swift_self_class (); MonoClass *swift_error = mono_class_try_get_swift_error_class (); MonoClass *swift_indirect_result = mono_class_try_get_swift_indirect_result_class (); - MonoClass *swift_error_ptr = mono_class_create_ptr (m_class_get_this_arg (swift_error)); + MonoClass *swift_error_ptr = swift_error ? mono_class_create_ptr (m_class_get_this_arg (swift_error)) : NULL; MonoClass *klass = mono_class_from_mono_type_internal (sig->params [i]); if (klass == swift_indirect_result) cinfo->need_swift_return_buffer = TRUE; @@ -1553,7 +1553,7 @@ gpointer mono_arch_get_swift_error (CallContext *ccontext, MonoMethodSignature *sig, int *arg_index) { MonoClass *swift_error = mono_class_try_get_swift_error_class (); - MonoClass *swift_error_ptr = mono_class_create_ptr (m_class_get_this_arg (swift_error)); + MonoClass *swift_error_ptr = swift_error ? mono_class_create_ptr (m_class_get_this_arg (swift_error)) : NULL; for (guint i = 0; i < sig->param_count + sig->hasthis; i++) { MonoClass *klass = mono_class_from_mono_type_internal (sig->params [i]); if (klass && (klass == swift_error || klass == swift_error_ptr)) { diff --git a/src/mono/mono/mini/mini-arm64.c b/src/mono/mono/mini/mini-arm64.c index d7f5c395829f5b..36ee5a2411131e 100644 --- a/src/mono/mono/mini/mini-arm64.c +++ b/src/mono/mono/mini/mini-arm64.c @@ -1916,7 +1916,7 @@ get_call_info (MonoMemPool *mp, MonoMethodSignature *sig) MonoClass *swift_self = mono_class_try_get_swift_self_class (); MonoClass *swift_error = mono_class_try_get_swift_error_class (); MonoClass *swift_indirect_result = mono_class_try_get_swift_indirect_result_class (); - MonoClass *swift_error_ptr = mono_class_create_ptr (m_class_get_this_arg (swift_error)); + MonoClass *swift_error_ptr = swift_error ? mono_class_create_ptr (m_class_get_this_arg (swift_error)) : NULL; MonoClass *klass = mono_class_from_mono_type_internal (sig->params [pindex]); if ((klass == swift_self || klass == swift_indirect_result) && sig->pinvoke) { guint32 align; @@ -2269,7 +2269,7 @@ gpointer mono_arch_get_swift_error (CallContext *ccontext, MonoMethodSignature *sig, int *arg_index) { MonoClass *swift_error = mono_class_try_get_swift_error_class (); - MonoClass *swift_error_ptr = mono_class_create_ptr (m_class_get_this_arg (swift_error)); + MonoClass *swift_error_ptr = swift_error ? mono_class_create_ptr (m_class_get_this_arg (swift_error)) : NULL; for (guint i = 0; i < sig->param_count + sig->hasthis; i++) { MonoClass *klass = mono_class_from_mono_type_internal (sig->params [i]); if (klass && (klass == swift_error || klass == swift_error_ptr)) {