Skip to content

Commit

Permalink
[mono][aot] Fix/cleanup the encoding/decoding of runtime invoke wrapp…
Browse files Browse the repository at this point in the history
…ers. (dotnet#95523)
  • Loading branch information
vargaz authored Dec 2, 2023
1 parent a0891ab commit 0e50fb1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
14 changes: 12 additions & 2 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3918,10 +3918,20 @@ encode_method_ref (MonoAotCompile *acfg, MonoMethod *method, guint8 *buf, guint8
case MONO_WRAPPER_RUNTIME_INVOKE: {
g_assert (info);
encode_value (info->subtype, p, &p);
if (info->subtype == WRAPPER_SUBTYPE_RUNTIME_INVOKE_DIRECT || info->subtype == WRAPPER_SUBTYPE_RUNTIME_INVOKE_VIRTUAL)
switch (info->subtype) {
case WRAPPER_SUBTYPE_RUNTIME_INVOKE_DIRECT:
case WRAPPER_SUBTYPE_RUNTIME_INVOKE_VIRTUAL:
encode_method_ref (acfg, info->d.runtime_invoke.method, p, &p);
else if (info->subtype == WRAPPER_SUBTYPE_RUNTIME_INVOKE_NORMAL)
break;
case WRAPPER_SUBTYPE_RUNTIME_INVOKE_NORMAL:
encode_signature (acfg, info->d.runtime_invoke.sig, p, &p);
break;
case WRAPPER_SUBTYPE_RUNTIME_INVOKE_DYNAMIC:
break;
default:
g_assert_not_reached ();
break;
}
break;
}
case MONO_WRAPPER_DELEGATE_INVOKE:
Expand Down
48 changes: 19 additions & 29 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,43 +1195,33 @@ decode_method_ref_with_target (MonoAotModule *module, MethodRef *ref, MonoMethod
case MONO_WRAPPER_RUNTIME_INVOKE: {
int subtype = decode_value (p, &p);

if (!target)
return FALSE;

if (subtype == WRAPPER_SUBTYPE_RUNTIME_INVOKE_DYNAMIC) {
if (strcmp (target->name, "runtime_invoke_dynamic") != 0)
return FALSE;
ref->method = target;
} else if (subtype == WRAPPER_SUBTYPE_RUNTIME_INVOKE_DIRECT) {
/* Direct wrapper */
switch (subtype) {
case WRAPPER_SUBTYPE_RUNTIME_INVOKE_DYNAMIC: {
ref->method = mono_marshal_get_runtime_invoke_dynamic ();
break;
}
case WRAPPER_SUBTYPE_RUNTIME_INVOKE_DIRECT: {
MonoMethod *m = decode_resolve_method_ref (module, p, &p, error);
if (!m)
return FALSE;
ref->method = mono_marshal_get_runtime_invoke (m, FALSE);
} else if (subtype == WRAPPER_SUBTYPE_RUNTIME_INVOKE_VIRTUAL) {
/* Virtual direct wrapper */
break;
}
case WRAPPER_SUBTYPE_RUNTIME_INVOKE_VIRTUAL: {
MonoMethod *m = decode_resolve_method_ref (module, p, &p, error);
if (!m)
return FALSE;
ref->method = mono_marshal_get_runtime_invoke (m, TRUE);
} else {
MonoMethodSignature *sig;

sig = decode_signature_with_target (module, NULL, p, &p);
info = mono_marshal_get_wrapper_info (target);
g_assert (info);

if (info->subtype != subtype) {
g_free (sig);
return FALSE;
}
g_assert (info->d.runtime_invoke.sig);
const gboolean same_sig = mono_metadata_signature_equal (sig, info->d.runtime_invoke.sig);
g_free (sig);
if (same_sig)
ref->method = target;
else
return FALSE;
break;
}
case WRAPPER_SUBTYPE_RUNTIME_INVOKE_NORMAL: {
MonoMethodSignature *sig = decode_signature_with_target (module, NULL, p, &p);
ref->method = mono_marshal_get_runtime_invoke_for_sig (sig);
break;
}
default:
g_assert_not_reached ();
break;
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2787,6 +2787,7 @@ mono_jit_compile_method_with_opt (MonoMethod *method, guint32 opt, gboolean jit_
if (!jit_only && !code && mono_aot_only && mono_use_interpreter && method->wrapper_type != MONO_WRAPPER_OTHER) {
if (mono_llvm_only) {
/* Signal to the caller that AOTed code is not found */
g_assert (method->wrapper_type != MONO_WRAPPER_RUNTIME_INVOKE);
return NULL;
}
code = mini_get_interp_callbacks ()->create_method_pointer (method, TRUE, error);
Expand Down

0 comments on commit 0e50fb1

Please sign in to comment.