Skip to content

Commit

Permalink
[reflection] Return n2m wrapper from RuntimeMethodHandle.GetFunctionP…
Browse files Browse the repository at this point in the history
…ointer (#60200)

for functions marked with UnmanagedCallersOnlyAttribute, return a pointer to
the n2m wrapper for calls to GetFunctionPointer

Contributes to #59815
  • Loading branch information
lambdageek authored Oct 11, 2021
1 parent 5f3062d commit bda8727
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -6293,6 +6293,11 @@ ves_icall_System_Environment_get_TickCount64 (void)
gpointer
ves_icall_RuntimeMethodHandle_GetFunctionPointer (MonoMethod *method, MonoError *error)
{
/* WISH: we should do this in managed */
if (G_UNLIKELY (mono_method_has_unmanaged_callers_only_attribute (method))) {
method = mono_marshal_get_managed_wrapper (method, NULL, (MonoGCHandle)0, error);
return_val_if_nok (error, NULL);
}
return mono_get_runtime_callbacks ()->get_ftnptr (method, error);
}

Expand Down
13 changes: 10 additions & 3 deletions src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6542,9 +6542,16 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;

MonoMethod *cmethod = LOCAL_VAR (ip [2], MonoMethod*);

InterpMethod *m = mono_interp_get_imethod (cmethod, error);
mono_error_assert_ok (error);
LOCAL_VAR (ip [1], gpointer) = imethod_to_ftnptr (m, FALSE);
if (G_UNLIKELY (mono_method_has_unmanaged_callers_only_attribute (cmethod))) {
cmethod = mono_marshal_get_managed_wrapper (cmethod, NULL, (MonoGCHandle)0, error);
mono_error_assert_ok (error);
gpointer addr = mini_get_interp_callbacks ()->create_method_pointer (cmethod, TRUE, error);
LOCAL_VAR (ip [1], gpointer) = addr;
} else {
InterpMethod *m = mono_interp_get_imethod (cmethod, error);
mono_error_assert_ok (error);
LOCAL_VAR (ip [1], gpointer) = imethod_to_ftnptr (m, FALSE);
}
ip += 3;
MINT_IN_BREAK;
}
Expand Down

0 comments on commit bda8727

Please sign in to comment.