Skip to content

Commit 2e26fbd

Browse files
authored
[mono][interp] Tweaks to x86 call convention handling (#88466)
First, we no longer assert that the call convetion is cdecl on the slowpath. The pinvoke trampoline on x86 restores the saved stack pointer so it doesn't matter if the pinvoke callee pops or not the stack. Therefore both stdcall and cdecl calls should be supported with the same path. Untested. Second, we use the fastpath (which uses the C call convention) only if the pinvoke signature is also cdecl, otherwise we have cconv mismatch.
1 parent 104752a commit 2e26fbd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/mono/mono/mini/interp/transform.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,10 +3787,20 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
37873787
if (native && !method->dynamic)
37883788
icall_sig = interp_get_icall_sig (csignature);
37893789
#endif
3790+
gboolean default_cconv = TRUE;
3791+
#ifdef TARGET_X86
3792+
#ifdef TARGET_WIN32
3793+
// Platform that we don't actively support ?
3794+
default_cconv = csignature->call_convention == MONO_CALL_C;
3795+
#else
3796+
default_cconv = csignature->call_convention == MONO_CALL_DEFAULT || csignature->call_convention == MONO_CALL_C;
3797+
#endif
3798+
#endif
3799+
37903800
// FIXME calli receives both the args offset and sometimes another arg for the frame pointer,
37913801
// therefore some args are in the param area, while the fp is not. We should differentiate for
37923802
// this, probably once we will have an explicit param area where we copy arguments.
3793-
if (icall_sig != MINT_ICALLSIG_MAX) {
3803+
if (icall_sig != MINT_ICALLSIG_MAX && default_cconv) {
37943804
interp_add_ins (td, MINT_CALLI_NAT_FAST);
37953805
interp_ins_set_dreg (td->last_ins, dreg);
37963806
interp_ins_set_sregs2 (td->last_ins, fp_sreg, MINT_CALL_ARGS_SREG);
@@ -3804,10 +3814,6 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
38043814
td->last_ins->data [0] = get_data_item_index (td, (void *)csignature);
38053815
} else if (native) {
38063816
interp_add_ins (td, MINT_CALLI_NAT);
3807-
#ifdef TARGET_X86
3808-
/* Windows not tested/supported yet */
3809-
g_assertf (csignature->call_convention == MONO_CALL_DEFAULT || csignature->call_convention == MONO_CALL_C, "Interpreter supports only cdecl pinvoke on x86");
3810-
#endif
38113817

38123818
InterpMethod *imethod = NULL;
38133819
/*

0 commit comments

Comments
 (0)