Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bef7cb

Browse files
monojenkinsvargaz
andauthored
[jit] Avoid calling mono_marshal_get_native_wrapper () too early, it needs to be called when the pinvoke method is first called. (dotnet#40063)
Co-authored-by: vargaz <[email protected]>
1 parent b7f809d commit 3bef7cb

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/mono/mono/mini/method-to-ir.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7233,8 +7233,17 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
72337233
} else if ((cmethod->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) && direct_icalls_enabled (cfg, cmethod)) {
72347234
direct_icall = TRUE;
72357235
} else if (fsig->pinvoke) {
7236-
MonoMethod *wrapper = mono_marshal_get_native_wrapper (cmethod, TRUE, cfg->compile_aot);
7237-
fsig = mono_method_signature_internal (wrapper);
7236+
if (cmethod->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
7237+
/*
7238+
* Avoid calling mono_marshal_get_native_wrapper () too early, it might call managed
7239+
* callbacks on netcore.
7240+
*/
7241+
fsig = mono_metadata_signature_dup_mempool (cfg->mempool, fsig);
7242+
fsig->pinvoke = FALSE;
7243+
} else {
7244+
MonoMethod *wrapper = mono_marshal_get_native_wrapper (cmethod, TRUE, cfg->compile_aot);
7245+
fsig = mono_method_signature_internal (wrapper);
7246+
}
72387247
} else if (constrained_class) {
72397248
} else {
72407249
fsig = mono_method_get_signature_checked (cmethod, image, token, generic_context, cfg->error);
@@ -7397,8 +7406,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
73977406
int costs;
73987407
gboolean always = FALSE;
73997408

7400-
if ((cmethod->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
7401-
(cmethod->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)) {
7409+
if (cmethod->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) {
74027410
/* Prevent inlining of methods that call wrappers */
74037411
INLINE_FAILURE ("wrapper call");
74047412
// FIXME? Does this write to cmethod impact tailcall_supported? Probably not.

0 commit comments

Comments
 (0)