Skip to content

Commit

Permalink
[release/9.0-preview7] Add swiftcall signature check for `mono_class_…
Browse files Browse the repository at this point in the history
…try_get_swift_error_class` (#105813)

* Add signature check for swiftcall

* Handle null values for swift_error_ptr

---------

Co-authored-by: Milos Kotlar <kotlarmilos@gmail.com>
  • Loading branch information
github-actions[bot] and kotlarmilos authored Aug 1, 2024
1 parent 4c12625 commit 61126f5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/mini/mini-amd64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/mini/mini-arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 61126f5

Please sign in to comment.