From 61126f5d957b6089e8e97604a0fc79c3b4c3ee5a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 1 Aug 2024 12:23:05 -0700 Subject: [PATCH] [release/9.0-preview7] Add swiftcall signature check for `mono_class_try_get_swift_error_class` (#105813) * Add signature check for swiftcall * Handle null values for swift_error_ptr --------- Co-authored-by: Milos Kotlar --- src/mono/mono/metadata/marshal.c | 2 +- src/mono/mono/mini/interp/transform.c | 4 ++-- src/mono/mono/mini/mini-amd64.c | 4 ++-- src/mono/mono/mini/mini-arm64.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index 96b8a5fe96de0..5e8fcc4dfd408 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 2b5e4c2c3fe61..1af7c2d514b23 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 = 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 096fcea3e01d9..a73b59782eea4 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 d7f5c395829f5..36ee5a2411131 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)) {