From 98dbaf2bdee7392d65a5fe3a42f149f2c3db1647 Mon Sep 17 00:00:00 2001 From: Andi McClure Date: Tue, 8 Mar 2016 16:44:49 -0500 Subject: [PATCH] Fix an assert in checked-build GC mode The pinvoke implementation in the failure case was creating a managed exception object while in blocking mode, a rules violation. This patch puts a redundant lookup early so that any exceptions occur before blocking mode is entered. (The "real" lookup is unchanged because the current pattern is optimized well by the JIT.) --- mono/metadata/marshal.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mono/metadata/marshal.c b/mono/metadata/marshal.c index 5163e5def96..696b97deca3 100644 --- a/mono/metadata/marshal.c +++ b/mono/metadata/marshal.c @@ -7298,7 +7298,16 @@ mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, MonoM tmp_locals [i] = emit_marshal (&m, i + param_shift, sig->params [i], mspecs [i + 1], 0, &csig->params [i], MARSHAL_ACTION_CONV_IN); } + // In coop mode need to register blocking state during native call if (mono_threads_is_coop_enabled ()) { + // Perform an extra, early lookup of the function address, so any exceptions + // potentially resulting from the lookup occur before entering blocking mode. + if (!func_param && !MONO_CLASS_IS_IMPORT (mb->method->klass) && aot) { + mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX); + mono_mb_emit_op (mb, CEE_MONO_ICALL_ADDR, &piinfo->method); + mono_mb_emit_byte (mb, CEE_POP); // Result not needed yet + } + clause->try_offset = mono_mb_get_label (mb); mono_mb_emit_ldloc_addr (mb, coop_gc_stack_dummy); -- 2.11.4.GIT