static void suspend_thread (SgenThreadInfo *info, void *context) { int stop_count; #ifndef USE_MONO_CTX gpointer regs [ARCH_NUM_REGS]; #endif MonoContext ctx; gpointer stack_start; info->client_info.stopped_domain = mono_domain_get (); info->client_info.signal = 0; stop_count = sgen_global_stop_count; /* duplicate signal */ if (0 && info->client_info.stop_count == stop_count) return; #ifdef USE_MONO_CTX if (context) { mono_sigctx_to_monoctx (context, &ctx); info->client_info.stopped_ip = MONO_CONTEXT_GET_IP (&ctx); stack_start = (((guint8 *) MONO_CONTEXT_GET_SP (&ctx)) - REDZONE_SIZE); } else { info->client_info.stopped_ip = NULL; stack_start = NULL; } #else info->client_info.stopped_ip = context ? (gpointer) ARCH_SIGCTX_IP (context) : NULL; stack_start = context ? (char*) ARCH_SIGCTX_SP (context) - REDZONE_SIZE : NULL; #endif /* If stack_start is not within the limits, then don't set it in info and we will be restarted. */ if (stack_start >= info->client_info.stack_start_limit && stack_start <= info->client_info.stack_end) { info->client_info.stack_start = stack_start; #ifdef USE_MONO_CTX if (context) { memcpy (&info->client_info.ctx, &ctx, sizeof (MonoContext)); } else { memset (&info->client_info.ctx, 0, sizeof (MonoContext)); } #else if (context) { ARCH_COPY_SIGCTX_REGS (regs, context); memcpy (&info->client_info.regs, regs, sizeof (info->client_info.regs)); } else { memset (&info->client_info.regs, 0, sizeof (info->client_info.regs)); } #endif } else { g_assert (!info->client_info.stack_start); } /* Notify the JIT */ if (mono_gc_get_gc_callbacks ()->thread_suspend_func) mono_gc_get_gc_callbacks ()->thread_suspend_func (info->client_info.runtime_data, context, NULL); SGEN_LOG (4, "Posting suspend_ack_semaphore for suspend from %p %p", info, (gpointer) (gsize) mono_native_thread_id_get ()); /* Block the restart signal. We need to block the restart signal while posting to the suspend_ack semaphore or we race to sigsuspend, which might miss the signal and get stuck. */ pthread_sigmask (SIG_BLOCK, &suspend_ack_signal_mask, NULL); /* notify the waiting thread */ SGEN_SEMAPHORE_POST (suspend_ack_semaphore_ptr); info->client_info.stop_count = stop_count; /* wait until we receive the restart signal */ do { info->client_info.signal = 0; sigsuspend (&suspend_signal_mask); } while (info->client_info.signal != restart_signal_num); /* Unblock the restart signal. */ pthread_sigmask (SIG_UNBLOCK, &suspend_ack_signal_mask, NULL); SGEN_LOG (4, "Posting suspend_ack_semaphore for resume from %p %p\n", info, (gpointer) (gsize) mono_native_thread_id_get ()); /* notify the waiting thread */ SGEN_SEMAPHORE_POST (suspend_ack_semaphore_ptr); }
static void suspend_thread (SgenThreadInfo *info, void *context) { int stop_count; #ifdef USE_MONO_CTX MonoContext monoctx; #else gpointer regs [ARCH_NUM_REGS]; #endif gpointer stack_start; g_assert (info->doing_handshake); info->stopped_domain = mono_domain_get (); info->stopped_ip = context ? (gpointer) ARCH_SIGCTX_IP (context) : NULL; stop_count = sgen_global_stop_count; /* duplicate signal */ if (0 && info->stop_count == stop_count) return; sgen_fill_thread_info_for_suspend (info); stack_start = context ? (char*) ARCH_SIGCTX_SP (context) - REDZONE_SIZE : NULL; /* If stack_start is not within the limits, then don't set it in info and we will be restarted. */ if (stack_start >= info->stack_start_limit && info->stack_start <= info->stack_end) { info->stack_start = stack_start; #ifdef USE_MONO_CTX if (context) { mono_sigctx_to_monoctx (context, &monoctx); info->monoctx = &monoctx; } else { info->monoctx = NULL; } #else if (context) { ARCH_COPY_SIGCTX_REGS (regs, context); info->stopped_regs = regs; } else { info->stopped_regs = NULL; } #endif } else { g_assert (!info->stack_start); } /* Notify the JIT */ if (mono_gc_get_gc_callbacks ()->thread_suspend_func) mono_gc_get_gc_callbacks ()->thread_suspend_func (info->runtime_data, context); DEBUG (4, fprintf (gc_debug_file, "Posting suspend_ack_semaphore for suspend from %p %p\n", info, (gpointer)mono_native_thread_id_get ())); /* Block the restart signal. We need to block the restart signal while posting to the suspend_ack semaphore or we race to sigsuspend, which might miss the signal and get stuck. */ pthread_sigmask (SIG_BLOCK, &suspend_ack_signal_mask, NULL); /* notify the waiting thread */ MONO_SEM_POST (suspend_ack_semaphore_ptr); info->stop_count = stop_count; /* wait until we receive the restart signal */ do { info->signal = 0; sigsuspend (&suspend_signal_mask); } while (info->signal != restart_signal_num && info->doing_handshake); /* Unblock the restart signal. */ pthread_sigmask (SIG_UNBLOCK, &suspend_ack_signal_mask, NULL); DEBUG (4, fprintf (gc_debug_file, "Posting suspend_ack_semaphore for resume from %p %p\n", info, (gpointer)mono_native_thread_id_get ())); /* notify the waiting thread */ MONO_SEM_POST (suspend_ack_semaphore_ptr); }