Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][interp] Fix sufficient stack check when using interpreter #60514

Merged
merged 1 commit into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,6 @@ public async Task TestReceiveAsync_ManyInOrder()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38817", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoInterpreter))]
[SkipOnPlatform(TestPlatforms.Browser, "uses a lot of stack")]
public async Task TestReceiveAsync_LongChain()
{
Expand Down Expand Up @@ -1924,7 +1923,6 @@ public async Task TestOutputAvailableAsync_DataAfterCompletion()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/38817", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoInterpreter))]
[SkipOnPlatform(TestPlatforms.Browser, "uses a lot of stack")]
public async Task TestOutputAvailableAsync_LongSequence()
{
Expand Down
4 changes: 4 additions & 0 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_SufficientExecutionStac
if (current < limit)
return FALSE;

if (mono_get_runtime_callbacks ()->is_interpreter_enabled () &&
!mono_get_runtime_callbacks ()->interp_sufficient_stack (MONO_MIN_EXECUTION_STACK_SIZE))
return FALSE;

return TRUE;
}

Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/metadata/object-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ typedef struct {
// Same as compile_method, but returns a MonoFtnDesc in llvmonly mode
gpointer (*get_ftnptr)(MonoMethod *method, MonoError *error);
void (*interp_jit_info_foreach)(InterpJitInfoFunc func, gpointer user_data);
gboolean (*interp_sufficient_stack)(gsize size);
} MonoRuntimeCallbacks;

typedef gboolean (*MonoInternalStackWalk) (MonoStackFrameInfo *frame, MonoContext *ctx, gpointer data);
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/mini/ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef gpointer MonoInterpFrameHandle;
MONO_EE_CALLBACK (void, cleanup, (void)) \
MONO_EE_CALLBACK (void, mark_stack, (gpointer thread_info, GcScanFunc func, gpointer gc_data, gboolean precise)) \
MONO_EE_CALLBACK (void, jit_info_foreach, (InterpJitInfoFunc func, gpointer user_data)) \
MONO_EE_CALLBACK (gboolean, sufficient_stack, (gsize size)) \

typedef struct _MonoEECallbacks {

Expand Down
6 changes: 6 additions & 0 deletions src/mono/mono/mini/interp-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ stub_jit_info_foreach (InterpJitInfoFunc func, gpointer user_data)
{
}

static gboolean
stub_sufficient_stack (gsize size)
{
g_assert_not_reached ();
}

#undef MONO_EE_CALLBACK
#define MONO_EE_CALLBACK(ret, name, sig) stub_ ## name,

Expand Down
8 changes: 8 additions & 0 deletions src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7520,6 +7520,14 @@ interp_jit_info_foreach (InterpJitInfoFunc func, gpointer user_data)
}
}

static gboolean
interp_sufficient_stack (gsize size)
{
ThreadContext *context = get_context ();

return (context->stack_pointer + size) < (context->stack_start + INTERP_STACK_SIZE);
}

static void
interp_cleanup (void)
{
Expand Down
8 changes: 8 additions & 0 deletions src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ static void register_icalls (void);
static void runtime_cleanup (MonoDomain *domain, gpointer user_data);
static void mini_invalidate_transformed_interp_methods (MonoAssemblyLoadContext *alc, uint32_t generation);
static void mini_interp_jit_info_foreach(InterpJitInfoFunc func, gpointer user_data);
static gboolean mini_interp_sufficient_stack (gsize size);

gboolean
mono_running_on_valgrind (void)
Expand Down Expand Up @@ -4445,6 +4446,7 @@ mini_init (const char *filename, const char *runtime_version)

callbacks.metadata_update_published = mini_invalidate_transformed_interp_methods;
callbacks.interp_jit_info_foreach = mini_interp_jit_info_foreach;
callbacks.interp_sufficient_stack = mini_interp_sufficient_stack;
callbacks.init_mem_manager = init_jit_mem_manager;
callbacks.free_mem_manager = free_jit_mem_manager;

Expand Down Expand Up @@ -5215,6 +5217,12 @@ mini_interp_jit_info_foreach(InterpJitInfoFunc func, gpointer user_data)
mini_get_interp_callbacks ()->jit_info_foreach (func, user_data);
}

static gboolean
mini_interp_sufficient_stack (gsize size)
{
return mini_get_interp_callbacks ()->sufficient_stack (size);
}

/*
* mini_get_default_mem_manager:
*
Expand Down