Skip to content

Commit

Permalink
[mono] ThisCall with no arguments is invalid (dotnet#72495)
Browse files Browse the repository at this point in the history
* [mono] ThisCall with no arguments is invalid

* Disable test on llvmfullaot
  • Loading branch information
AaronRobinsonMSFT committed Jul 20, 2022
1 parent 9b1f2e2 commit 72da8ac
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -3015,6 +3015,11 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
csignature = mono_method_signature_internal (target_method);
}

if (calli && csignature->param_count == 0 && csignature->call_convention == MONO_CALL_THISCALL) {
mono_error_set_generic_error (error, "System", "InvalidProgramException", "thiscall with 0 arguments");
return FALSE;
}

if (check_visibility && target_method && !mono_method_can_access_method (method, target_method))
interp_generate_mae_throw (td, method, target_method);

Expand Down
3 changes: 3 additions & 0 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -7335,6 +7335,9 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b

//g_assert (!virtual_ || fsig->hasthis);

if (n == 0 && fsig->call_convention == MONO_CALL_THISCALL)
mono_cfg_set_exception_invalid_program(cfg, "thiscall with 0 arguments");

sp -= n;

if (!(cfg->method->wrapper_type && cfg->method->wrapper_type != MONO_WRAPPER_DYNAMIC_METHOD) && check_call_signature (cfg, fsig, sp)) {
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -4044,7 +4044,7 @@ mono_cfg_set_exception (MonoCompile *cfg, MonoExceptionType type)

/* Assumes ownership of the MSG argument */
void
mono_cfg_set_exception_invalid_program (MonoCompile *cfg, char *msg)
mono_cfg_set_exception_invalid_program (MonoCompile *cfg, const char *msg)
{
mono_cfg_set_exception (cfg, MONO_EXCEPTION_MONO_ERROR);
mono_error_set_generic_error (cfg->error, "System", "InvalidProgramException", "%s", msg);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -2780,7 +2780,7 @@ guint mono_type_to_regmove (MonoCompile *cfg, MonoType *type);
void mono_cfg_add_try_hole (MonoCompile *cfg, MonoExceptionClause *clause, guint8 *start, MonoBasicBlock *bb);

void mono_cfg_set_exception (MonoCompile *cfg, MonoExceptionType type);
void mono_cfg_set_exception_invalid_program (MonoCompile *cfg, char *msg);
void mono_cfg_set_exception_invalid_program (MonoCompile *cfg, const char *msg);

#define MONO_TIME_TRACK(a, phase) \
{ \
Expand Down
6 changes: 3 additions & 3 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2214,9 +2214,6 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_68568/Runtime_68568/*">
<Issue>Tests coreclr's handling of switches on natively sized integers</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/callconv/ThisCall/EmptyThisCallTest/*">
<Issue>Tests that 'thiscall' with an empty signature results in InvalidProgramException, which is coreclr-only behavior</Issue>
</ExcludeList>
</ItemGroup>

<!-- Known failures for mono runtime on Windows -->
Expand Down Expand Up @@ -2874,6 +2871,9 @@
<ExcludeList Include = "$(XunitTestBinBase)/Interop/PInvoke/Miscellaneous/HandleRef/HandleRefTest/**">
<Issue>https://github.com/dotnet/runtime/issues/57350</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/callconv/ThisCall/EmptyThisCallTest/*">
<Issue>Tests that 'thiscall' with an empty signature results in InvalidProgramException</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Directed/coverage/importer/badendfinally/**">
<Issue>https://github.com/dotnet/runtime/issues/57350</Issue>
</ExcludeList>
Expand Down

0 comments on commit 72da8ac

Please sign in to comment.