提交 eb3e935b 编写于 作者: J Jonathan Chambers

Implement check for sufficient execution stack.

Enable across platforms and expose to embedding API.
上级 067ea2fc
......@@ -1017,40 +1017,7 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunModuleConstructor (M
ICALL_EXPORT MonoBoolean
ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_SufficientExecutionStack (void)
{
#if defined(TARGET_WIN32) || defined(HOST_WIN32)
// It does not work on win32
#elif defined(TARGET_ANDROID) || defined(__linux__)
// No need for now
#else
guint8 *stack_addr;
guint8 *current;
size_t stack_size;
int min_size;
MonoInternalThread *thread;
mono_thread_info_get_stack_bounds (&stack_addr, &stack_size);
/* if we have no info we are optimistic and assume there is enough room */
if (!stack_addr)
return TRUE;
thread = mono_thread_internal_current ();
// .net seems to check that at least 50% of stack is available
min_size = thread->stack_size / 2;
// TODO: It's not always set
if (!min_size)
return TRUE;
current = (guint8 *)&stack_addr;
if (current > stack_addr) {
if ((current - stack_addr) < min_size)
return FALSE;
} else {
if (current - (stack_addr - stack_size) < min_size)
return FALSE;
}
#endif
return TRUE;
return mono_thread_has_sufficient_execution_stack ();
}
ICALL_EXPORT MonoObject *
......
......@@ -5678,3 +5678,33 @@ MonoException* mono_unity_thread_check_exception()
unlock_thread(thread);
return NULL;
}
mono_bool mono_thread_has_sufficient_execution_stack (void)
{
guint8* stack_addr;
guint8* current;
size_t stack_size;
size_t min_size;
mono_thread_info_get_stack_bounds (&stack_addr, &stack_size);
/* if we have no info we are optimistic and assume there is enough room */
if (!stack_addr || !stack_size)
return TRUE;
min_size = stack_size / 2;
// TODO: It's not always set
if (!min_size)
return TRUE;
current = (guint8*)&stack_addr;
if (current > stack_addr) {
if ((current - stack_addr) < min_size)
return FALSE;
}
else {
if (current - (stack_addr - stack_size) < min_size)
return FALSE;
}
return TRUE;
}
......@@ -57,6 +57,8 @@ MONO_API mono_bool mono_thread_is_foreign (MonoThread *thread);
extern MONO_API mono_bool mono_thread_detach_if_exiting (void);
MONO_API mono_bool mono_thread_has_sufficient_execution_stack (void);
MONO_END_DECLS
#endif /* _MONO_METADATA_THREADS_H_ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册