File tree Expand file tree Collapse file tree 3 files changed +33
-34
lines changed Expand file tree Collapse file tree 3 files changed +33
-34
lines changed Original file line number Diff line number Diff line change @@ -1017,40 +1017,7 @@ ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunModuleConstructor (M
1017
1017
ICALL_EXPORT MonoBoolean
1018
1018
ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_SufficientExecutionStack (void )
1019
1019
{
1020
- #if defined(TARGET_WIN32 ) || defined(HOST_WIN32 )
1021
- // It does not work on win32
1022
- #elif defined(TARGET_ANDROID ) || defined(__linux__ )
1023
- // No need for now
1024
- #else
1025
- guint8 * stack_addr ;
1026
- guint8 * current ;
1027
- size_t stack_size ;
1028
- int min_size ;
1029
- MonoInternalThread * thread ;
1030
-
1031
- mono_thread_info_get_stack_bounds (& stack_addr , & stack_size );
1032
- /* if we have no info we are optimistic and assume there is enough room */
1033
- if (!stack_addr )
1034
- return TRUE;
1035
-
1036
- thread = mono_thread_internal_current ();
1037
- // .net seems to check that at least 50% of stack is available
1038
- min_size = thread -> stack_size / 2 ;
1039
-
1040
- // TODO: It's not always set
1041
- if (!min_size )
1042
- return TRUE;
1043
-
1044
- current = (guint8 * )& stack_addr ;
1045
- if (current > stack_addr ) {
1046
- if ((current - stack_addr ) < min_size )
1047
- return FALSE;
1048
- } else {
1049
- if (current - (stack_addr - stack_size ) < min_size )
1050
- return FALSE;
1051
- }
1052
- #endif
1053
- return TRUE;
1020
+ return mono_thread_has_sufficient_execution_stack ();
1054
1021
}
1055
1022
1056
1023
ICALL_EXPORT MonoObject *
Original file line number Diff line number Diff line change @@ -5678,3 +5678,33 @@ MonoException* mono_unity_thread_check_exception()
5678
5678
unlock_thread (thread );
5679
5679
return NULL ;
5680
5680
}
5681
+
5682
+ mono_bool mono_thread_has_sufficient_execution_stack (void )
5683
+ {
5684
+ guint8 * stack_addr ;
5685
+ guint8 * current ;
5686
+ size_t stack_size ;
5687
+ size_t min_size ;
5688
+
5689
+ mono_thread_info_get_stack_bounds (& stack_addr , & stack_size );
5690
+ /* if we have no info we are optimistic and assume there is enough room */
5691
+ if (!stack_addr || !stack_size )
5692
+ return TRUE;
5693
+
5694
+ min_size = stack_size / 2 ;
5695
+
5696
+ // TODO: It's not always set
5697
+ if (!min_size )
5698
+ return TRUE;
5699
+
5700
+ current = (guint8 * )& stack_addr ;
5701
+ if (current > stack_addr ) {
5702
+ if ((current - stack_addr ) < min_size )
5703
+ return FALSE;
5704
+ }
5705
+ else {
5706
+ if (current - (stack_addr - stack_size ) < min_size )
5707
+ return FALSE;
5708
+ }
5709
+ return TRUE;
5710
+ }
Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ MONO_API mono_bool mono_thread_is_foreign (MonoThread *thread);
57
57
58
58
extern MONO_API mono_bool mono_thread_detach_if_exiting (void );
59
59
60
+ MONO_API mono_bool mono_thread_has_sufficient_execution_stack (void );
61
+
60
62
MONO_END_DECLS
61
63
62
64
#endif /* _MONO_METADATA_THREADS_H_ */
You can’t perform that action at this time.
0 commit comments