@@ -126,7 +126,7 @@ static MonoFtnPtrEHCallback ftnptr_eh_callback;
126
126
*/
127
127
int mono_llvmonly_do_unwind_flag ;
128
128
129
- static void mono_walk_stack_full (MonoJitStackWalk func , MonoContext * start_ctx , MonoJitTlsData * jit_tls , MonoLMF * lmf , MonoUnwindOptions unwind_options , gpointer user_data , gboolean crash_context );
129
+ static void mono_walk_stack_full (MonoJitStackWalk func , MonoContext * start_ctx , MonoJitTlsData * jit_tls , MonoLMF * lmf , MonoUnwindOptions unwind_options , gpointer user_data );
130
130
static void mono_raise_exception_with_ctx (MonoException * exc , MonoContext * ctx );
131
131
static void mono_runtime_walk_stack_with_ctx (MonoJitStackWalk func , MonoContext * start_ctx , MonoUnwindOptions unwind_options , void * user_data );
132
132
static gboolean mono_current_thread_has_handle_block_guard (void );
@@ -1224,7 +1224,7 @@ mono_walk_stack_with_ctx (MonoJitStackWalk func, MonoContext *start_ctx, MonoUnw
1224
1224
start_ctx = & extra_ctx ;
1225
1225
}
1226
1226
1227
- mono_walk_stack_full (func , start_ctx , thread -> jit_data , mono_get_lmf (), unwind_options , user_data , FALSE );
1227
+ mono_walk_stack_full (func , start_ctx , thread -> jit_data , mono_get_lmf (), unwind_options , user_data );
1228
1228
}
1229
1229
1230
1230
/**
@@ -1258,7 +1258,7 @@ mono_walk_stack_with_state (MonoJitStackWalk func, MonoThreadUnwindState *state,
1258
1258
& state -> ctx ,
1259
1259
(MonoJitTlsData * )state -> unwind_data [MONO_UNWIND_DATA_JIT_TLS ],
1260
1260
(MonoLMF * )state -> unwind_data [MONO_UNWIND_DATA_LMF ],
1261
- unwind_options , user_data , FALSE );
1261
+ unwind_options , user_data );
1262
1262
}
1263
1263
1264
1264
void
@@ -1278,14 +1278,13 @@ mono_walk_stack (MonoJitStackWalk func, MonoUnwindOptions options, void *user_da
1278
1278
* \param thread the thread whose stack to walk, can be NULL to use the current thread
1279
1279
* \param lmf the LMF of \p thread, can be NULL to use the LMF of the current thread
1280
1280
* \param user_data data passed to the callback
1281
- * \param crash_context tells us that we're in a context where it's not safe to lock or allocate
1282
1281
* This function walks the stack of a thread, starting from the state
1283
1282
* represented by \p start_ctx. For each frame the callback
1284
1283
* function is called with the relevant info. The walk ends when no more
1285
1284
* managed stack frames are found or when the callback returns a TRUE value.
1286
1285
*/
1287
1286
static void
1288
- mono_walk_stack_full (MonoJitStackWalk func , MonoContext * start_ctx , MonoJitTlsData * jit_tls , MonoLMF * lmf , MonoUnwindOptions unwind_options , gpointer user_data , gboolean crash_context )
1287
+ mono_walk_stack_full (MonoJitStackWalk func , MonoContext * start_ctx , MonoJitTlsData * jit_tls , MonoLMF * lmf , MonoUnwindOptions unwind_options , gpointer user_data )
1289
1288
{
1290
1289
gint il_offset ;
1291
1290
MonoContext ctx , new_ctx ;
@@ -1372,15 +1371,15 @@ mono_walk_stack_full (MonoJitStackWalk func, MonoContext *start_ctx, MonoJitTlsD
1372
1371
MonoDebugSourceLocation * source = NULL ;
1373
1372
1374
1373
// Don't do this when we can be in a signal handler
1375
- if (!crash_context )
1374
+ if (!async )
1376
1375
source = mono_debug_lookup_source_location (jinfo_get_method (frame .ji ), frame .native_offset , NULL );
1377
1376
if (source ) {
1378
1377
il_offset = source -> il_offset ;
1379
1378
} else {
1380
1379
MonoSeqPointInfo * seq_points = NULL ;
1381
1380
1382
1381
// It's more reliable to look into the global cache if possible
1383
- if (crash_context )
1382
+ if (async )
1384
1383
seq_points = (MonoSeqPointInfo * ) frame .ji -> seq_points ;
1385
1384
else
1386
1385
seq_points = mono_get_seq_points (jinfo_get_method (frame .ji ));
@@ -2976,7 +2975,17 @@ mono_handle_native_crash (const char *signal, MonoContext *mctx, MONO_SIG_HANDLE
2976
2975
g_async_safe_printf ("\tManaged Stacktrace:\n" );
2977
2976
g_async_safe_printf ("=================================================================\n" );
2978
2977
2979
- mono_walk_stack_full (print_stack_frame_signal_safe , mctx , jit_tls , mono_get_lmf (), MONO_UNWIND_LOOKUP_IL_OFFSET , NULL , TRUE);
2978
+ gboolean restore_async_context = FALSE;
2979
+ if (!mono_thread_info_is_async_context ()) {
2980
+ mono_thread_info_set_is_async_context (TRUE);
2981
+ restore_async_context = TRUE;
2982
+ }
2983
+
2984
+ mono_walk_stack_full (print_stack_frame_signal_safe , mctx , jit_tls , mono_get_lmf (), MONO_UNWIND_LOOKUP_IL_OFFSET , NULL );
2985
+
2986
+ if (restore_async_context )
2987
+ mono_thread_info_set_is_async_context (FALSE);
2988
+
2980
2989
g_async_safe_printf ("=================================================================\n" );
2981
2990
}
2982
2991
@@ -3146,15 +3155,22 @@ mono_install_handler_block_guard (MonoThreadUnwindState *ctx)
3146
3155
MonoJitTlsData * jit_tls = (MonoJitTlsData * )ctx -> unwind_data [MONO_UNWIND_DATA_JIT_TLS ];
3147
3156
3148
3157
/* Guard against a null MonoJitTlsData. This can happens if the thread receives the
3149
- * interrupt signal before the JIT has time to initialize its TLS data for the given thread.
3158
+ * interrupt signal before the JIT has time to initialize its TLS data for the given thread.
3150
3159
*/
3151
3160
if (!jit_tls || jit_tls -> handler_block )
3152
3161
return FALSE;
3153
3162
3154
3163
/* Do an async safe stack walk */
3155
- mono_thread_info_set_is_async_context (TRUE);
3156
- mono_walk_stack_with_state (find_last_handler_block , ctx , MONO_UNWIND_NONE , & data );
3157
- mono_thread_info_set_is_async_context (FALSE);
3164
+ gboolean restore_async_context = FALSE;
3165
+ if (!mono_thread_info_is_async_context ()) {
3166
+ mono_thread_info_set_is_async_context (TRUE);
3167
+ restore_async_context = TRUE;
3168
+ }
3169
+
3170
+ mono_walk_stack_with_state (find_last_handler_block , ctx , MONO_UNWIND_SIGNAL_SAFE , & data );
3171
+
3172
+ if (restore_async_context )
3173
+ mono_thread_info_set_is_async_context (FALSE);
3158
3174
3159
3175
if (!data .ji )
3160
3176
return FALSE;
0 commit comments