Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mono/metadata/Makefile.am4
-rw-r--r--mono/metadata/boehm-gc.c5
-rw-r--r--mono/metadata/domain.c2
-rw-r--r--mono/metadata/gc-internals.h2
-rw-r--r--mono/metadata/null-gc.c5
-rw-r--r--mono/metadata/sgen-client-mono.h8
-rw-r--r--mono/metadata/sgen-mono.c34
-rw-r--r--mono/metadata/sgen-os-coop.c76
-rw-r--r--mono/metadata/sgen-os-mach.c153
-rw-r--r--mono/metadata/sgen-os-posix.c246
-rw-r--r--mono/metadata/sgen-os-win32.c145
-rw-r--r--mono/metadata/sgen-stw.c165
-rw-r--r--mono/mini/mini-posix.c3
-rw-r--r--mono/utils/Makefile.am5
-rw-r--r--mono/utils/mono-threads-coop.c1
-rw-r--r--mono/utils/mono-threads-debug.h42
-rw-r--r--mono/utils/mono-threads-mach-abort-syscall.c89
-rw-r--r--mono/utils/mono-threads-mach.c86
-rw-r--r--mono/utils/mono-threads-posix-abort-syscall.c44
-rw-r--r--mono/utils/mono-threads-posix-signals.c145
-rw-r--r--mono/utils/mono-threads-posix-signals.h34
-rw-r--r--mono/utils/mono-threads-posix.c24
-rw-r--r--mono/utils/mono-threads-state-machine.c1
-rw-r--r--mono/utils/mono-threads-windows-abort-syscall.c51
-rw-r--r--mono/utils/mono-threads-windows.c59
-rw-r--r--mono/utils/mono-threads.c12
-rw-r--r--mono/utils/mono-threads.h49
-rw-r--r--msvc/libmonoruntime.vcxproj14
-rw-r--r--msvc/libmonoruntime.vcxproj.filters12
-rw-r--r--msvc/libmonoutils.vcxproj14
30 files changed, 289 insertions, 1241 deletions
diff --git a/mono/metadata/Makefile.am b/mono/metadata/Makefile.am
index b3fd6121b2d..a3c116e5134 100644
--- a/mono/metadata/Makefile.am
+++ b/mono/metadata/Makefile.am
@@ -279,10 +279,6 @@ boehm_sources = \
boehm-gc.c
sgen_sources = \
- sgen-os-posix.c \
- sgen-os-mach.c \
- sgen-os-win32.c \
- sgen-os-coop.c \
sgen-bridge.c \
sgen-bridge.h \
sgen-bridge-internals.h \
diff --git a/mono/metadata/boehm-gc.c b/mono/metadata/boehm-gc.c
index d3debe1cd03..2c648c85da6 100644
--- a/mono/metadata/boehm-gc.c
+++ b/mono/metadata/boehm-gc.c
@@ -1352,11 +1352,6 @@ mono_gc_get_nursery (int *shift_bits, size_t *size)
return NULL;
}
-void
-mono_gc_set_current_thread_appdomain (MonoDomain *domain)
-{
-}
-
gboolean
mono_gc_precise_stack_mark_enabled (void)
{
diff --git a/mono/metadata/domain.c b/mono/metadata/domain.c
index 39dd1ca4165..adb8909f460 100644
--- a/mono/metadata/domain.c
+++ b/mono/metadata/domain.c
@@ -66,7 +66,6 @@ MONO_FAST_TLS_DECLARE(tls_appdomain);
MonoThreadInfo *info; \
MONO_FAST_TLS_SET (tls_appdomain,x); \
mono_native_tls_set_value (appdomain_thread_id, x); \
- mono_gc_set_current_thread_appdomain (x); \
info = mono_thread_info_current (); \
if (info) \
mono_thread_info_tls_set (info, TLS_KEY_DOMAIN, (x)); \
@@ -78,7 +77,6 @@ MONO_FAST_TLS_DECLARE(tls_appdomain);
#define SET_APPDOMAIN(x) do { \
MonoThreadInfo *info; \
mono_native_tls_set_value (appdomain_thread_id, x); \
- mono_gc_set_current_thread_appdomain (x); \
info = mono_thread_info_current (); \
if (info) \
mono_thread_info_tls_set (info, TLS_KEY_DOMAIN, (x)); \
diff --git a/mono/metadata/gc-internals.h b/mono/metadata/gc-internals.h
index d3d81f272a8..afb6522d1cb 100644
--- a/mono/metadata/gc-internals.h
+++ b/mono/metadata/gc-internals.h
@@ -297,8 +297,6 @@ gboolean mono_gc_card_table_nursery_check (void);
void* mono_gc_get_nursery (int *shift_bits, size_t *size);
-void mono_gc_set_current_thread_appdomain (MonoDomain *domain);
-
void mono_gc_set_skip_thread (gboolean skip);
#ifndef HOST_WIN32
diff --git a/mono/metadata/null-gc.c b/mono/metadata/null-gc.c
index b3224372dde..0990ff875fd 100644
--- a/mono/metadata/null-gc.c
+++ b/mono/metadata/null-gc.c
@@ -444,11 +444,6 @@ mono_gc_get_nursery (int *shift_bits, size_t *size)
return NULL;
}
-void
-mono_gc_set_current_thread_appdomain (MonoDomain *domain)
-{
-}
-
gboolean
mono_gc_precise_stack_mark_enabled (void)
{
diff --git a/mono/metadata/sgen-client-mono.h b/mono/metadata/sgen-client-mono.h
index eee26b70601..cb60f3b58ec 100644
--- a/mono/metadata/sgen-client-mono.h
+++ b/mono/metadata/sgen-client-mono.h
@@ -39,9 +39,6 @@ struct _SgenClientThreadInfo {
gboolean skip, suspend_done;
volatile int in_critical_region;
- gpointer stopped_ip; /* only valid if the thread is stopped */
- MonoDomain *stopped_domain; /* dsto */
-
/*
This is set the argument of mono_gc_set_skip_thread.
@@ -700,11 +697,6 @@ sgen_client_binary_protocol_pin_stats (int objects_pinned_in_nursery, size_t byt
{
}
-int sgen_thread_handshake (BOOL suspend);
-gboolean sgen_suspend_thread (SgenThreadInfo *info);
-gboolean sgen_resume_thread (SgenThreadInfo *info);
-void sgen_wait_for_suspend_ack (int count);
-
#ifdef HAVE_KW_THREAD
extern __thread SgenThreadInfo *sgen_thread_info;
#define TLAB_ACCESS_INIT
diff --git a/mono/metadata/sgen-mono.c b/mono/metadata/sgen-mono.c
index 725a7eccc63..6372084d21d 100644
--- a/mono/metadata/sgen-mono.c
+++ b/mono/metadata/sgen-mono.c
@@ -29,6 +29,7 @@
#include "utils/mono-logger-internals.h"
#include "utils/mono-threads-coop.h"
#include "sgen/sgen-thread-pool.h"
+#include "utils/mono-threads.h"
#ifdef HEAVY_STATISTICS
static guint64 stat_wbarrier_set_arrayref = 0;
@@ -184,6 +185,18 @@ mono_gc_wbarrier_value_copy_bitmap (gpointer _dest, gpointer _src, int size, uns
sgen_wbarrier_value_copy_bitmap (_dest, _src, size, bitmap);
}
+int
+mono_gc_get_suspend_signal (void)
+{
+ return mono_threads_suspend_get_suspend_signal ();
+}
+
+int
+mono_gc_get_restart_signal (void)
+{
+ return mono_threads_suspend_get_restart_signal ();
+}
+
static MonoMethod *write_barrier_conc_method;
static MonoMethod *write_barrier_noconc_method;
@@ -732,18 +745,6 @@ mono_gc_ephemeron_array_add (MonoObject *obj)
* Appdomain handling
*/
-void
-mono_gc_set_current_thread_appdomain (MonoDomain *domain)
-{
- SgenThreadInfo *info = mono_thread_info_current ();
-
- /* Could be called from sgen_thread_unregister () with a NULL info */
- if (domain) {
- g_assert (info);
- info->client_info.stopped_domain = domain;
- }
-}
-
static gboolean
need_remove_object_for_domain (GCObject *start, MonoDomain *domain)
{
@@ -2214,8 +2215,6 @@ sgen_client_thread_register (SgenThreadInfo* info, void *stack_bottom_fallback)
#endif
info->client_info.skip = 0;
- info->client_info.stopped_ip = NULL;
- info->client_info.stopped_domain = NULL;
info->client_info.stack_start = NULL;
@@ -2876,13 +2875,6 @@ sgen_client_init (void)
}
#endif
- /*
- * This needs to happen before any internal allocations because
- * it inits the small id which is required for hazard pointer
- * operations.
- */
- sgen_os_init ();
-
mono_gc_register_thread (&dummy);
}
diff --git a/mono/metadata/sgen-os-coop.c b/mono/metadata/sgen-os-coop.c
deleted file mode 100644
index aab29b6466c..00000000000
--- a/mono/metadata/sgen-os-coop.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * sgen-os-coop.c: SGen Cooperative backend support.
- *
- * Author:
- * João Matos (joao.matos@xamarin.com)
- * Copyright (C) 2015 Xamarin Inc
- *
- * Licensed under the MIT license. See LICENSE file in the project root for full license information.
- */
-
-#include "config.h"
-
-#ifdef HAVE_SGEN_GC
-
-
-#include <glib.h>
-#include "sgen/sgen-gc.h"
-#include "sgen/sgen-archdep.h"
-#include "sgen/sgen-protocol.h"
-#include "metadata/object-internals.h"
-#include "metadata/gc-internals.h"
-
-
-#if defined(USE_COOP_GC)
-
-gboolean
-sgen_resume_thread (SgenThreadInfo *info)
-{
- g_error ("FIXME");
- return FALSE;
-}
-
-gboolean
-sgen_suspend_thread (SgenThreadInfo *info)
-{
- g_error ("FIXME");
- return FALSE;
-}
-
-void
-sgen_wait_for_suspend_ack (int count)
-{
-}
-
-/* LOCKING: assumes the GC lock is held */
-int
-sgen_thread_handshake (BOOL suspend)
-{
- g_error ("FIXME");
- return 0;
-}
-
-void
-sgen_os_init (void)
-{
-}
-
-int
-mono_gc_get_suspend_signal (void)
-{
- return -1;
-}
-
-int
-mono_gc_get_restart_signal (void)
-{
- return -1;
-}
-#else
-
-#ifdef _MSC_VER
-// Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty.
-void __mono_win32_sgen_os_coop_quiet_lnk4221(void) {}
-#endif
-#endif /* USE_COOP_GC */
-#endif
diff --git a/mono/metadata/sgen-os-mach.c b/mono/metadata/sgen-os-mach.c
deleted file mode 100644
index 1f87eb137f3..00000000000
--- a/mono/metadata/sgen-os-mach.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * sgen-os-mach.c: Mach-OS support.
- *
- * Author:
- * Paolo Molaro (lupus@ximian.com)
- * Mark Probst (mprobst@novell.com)
- * Geoff Norton (gnorton@novell.com)
- *
- * Copyright 2010 Novell, Inc (http://www.novell.com)
- * Copyright (C) 2012 Xamarin Inc
- *
- * Licensed under the MIT license. See LICENSE file in the project root for full license information.
- */
-
-#include "config.h"
-#ifdef HAVE_SGEN_GC
-
-
-#include <glib.h>
-#include "sgen/sgen-gc.h"
-#include "sgen/sgen-archdep.h"
-#include "sgen/sgen-protocol.h"
-#include "sgen/sgen-thread-pool.h"
-#include "metadata/object-internals.h"
-#include "metadata/gc-internals.h"
-
-#if defined(__MACH__)
-#include "utils/mach-support.h"
-#endif
-
-#if defined(__MACH__) && MONO_MACH_ARCH_SUPPORTED
-
-#if !defined(USE_COOP_GC)
-gboolean
-sgen_resume_thread (SgenThreadInfo *info)
-{
- kern_return_t ret;
- do {
- ret = thread_resume (info->client_info.info.native_handle);
- } while (ret == KERN_ABORTED);
- return ret == KERN_SUCCESS;
-}
-
-gboolean
-sgen_suspend_thread (SgenThreadInfo *info)
-{
- mach_msg_type_number_t num_state;
- thread_state_t state;
- kern_return_t ret;
- ucontext_t ctx;
- mcontext_t mctx;
-
- gpointer stack_start;
-
- state = (thread_state_t) alloca (mono_mach_arch_get_thread_state_size ());
- mctx = (mcontext_t) alloca (mono_mach_arch_get_mcontext_size ());
-
- do {
- ret = thread_suspend (info->client_info.info.native_handle);
- } while (ret == KERN_ABORTED);
- if (ret != KERN_SUCCESS)
- return FALSE;
-
- do {
- ret = mono_mach_arch_get_thread_state (info->client_info.info.native_handle, state, &num_state);
- } while (ret == KERN_ABORTED);
- if (ret != KERN_SUCCESS)
- return FALSE;
-
- mono_mach_arch_thread_state_to_mcontext (state, mctx);
- ctx.uc_mcontext = mctx;
-
- info->client_info.stopped_domain = mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
- info->client_info.stopped_ip = (gpointer) mono_mach_arch_get_ip (state);
- info->client_info.stack_start = NULL;
- stack_start = (char*) mono_mach_arch_get_sp (state) - REDZONE_SIZE;
- /* 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;
-
- mono_sigctx_to_monoctx (&ctx, &info->client_info.ctx);
- } 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, &ctx, NULL);
-
- SGEN_LOG (2, "thread %p stopped at %p stack_start=%p", (void*)(gsize)info->client_info.info.native_handle, info->client_info.stopped_ip, info->client_info.stack_start);
- binary_protocol_thread_suspend ((gpointer)mono_thread_info_get_tid (info), info->client_info.stopped_ip);
-
- return TRUE;
-}
-
-void
-sgen_wait_for_suspend_ack (int count)
-{
- /* mach thread_resume is synchronous so we dont need to wait for them */
-}
-
-/* LOCKING: assumes the GC lock is held */
-int
-sgen_thread_handshake (BOOL suspend)
-{
- SgenThreadInfo *cur_thread = mono_thread_info_current ();
- kern_return_t ret;
-
- int count = 0;
-
- cur_thread->client_info.suspend_done = TRUE;
- FOREACH_THREAD (info) {
- if (info == cur_thread || sgen_thread_pool_is_thread_pool_thread (mono_thread_info_get_tid (info)))
- continue;
-
- info->client_info.suspend_done = FALSE;
- if (info->client_info.gc_disabled)
- continue;
-
- if (suspend) {
- if (!sgen_suspend_thread (info))
- continue;
- } else {
- do {
- ret = thread_resume (info->client_info.info.native_handle);
- } while (ret == KERN_ABORTED);
- if (ret != KERN_SUCCESS)
- continue;
- }
- count ++;
- } FOREACH_THREAD_END
- return count;
-}
-
-void
-sgen_os_init (void)
-{
-}
-
-int
-mono_gc_get_suspend_signal (void)
-{
- return -1;
-}
-
-int
-mono_gc_get_restart_signal (void)
-{
- return -1;
-}
-#endif
-#endif
-#endif
diff --git a/mono/metadata/sgen-os-posix.c b/mono/metadata/sgen-os-posix.c
deleted file mode 100644
index 1016841f535..00000000000
--- a/mono/metadata/sgen-os-posix.c
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * sgen-os-posix.c: Posix support.
- *
- * Author:
- * Paolo Molaro (lupus@ximian.com)
- * Mark Probst (mprobst@novell.com)
- * Geoff Norton (gnorton@novell.com)
- *
- * Copyright 2010 Novell, Inc (http://www.novell.com)
- * Copyright (C) 2012 Xamarin Inc
- *
- * Licensed under the MIT license. See LICENSE file in the project root for full license information.
- */
-
-#include "config.h"
-
-#if defined(HAVE_SGEN_GC) && !defined(USE_COOP_GC)
-#if !defined(__MACH__) && !MONO_MACH_ARCH_SUPPORTED && defined(HAVE_PTHREAD_KILL)
-
-#include <errno.h>
-#include <glib.h>
-#include "sgen/sgen-gc.h"
-#include "metadata/gc-internals.h"
-#include "sgen/sgen-archdep.h"
-#include "metadata/object-internals.h"
-#include "utils/mono-signal-handler.h"
-
-#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-const static int suspend_signal_num = SIGXFSZ;
-#else
-const static int suspend_signal_num = SIGPWR;
-#endif
-const static int restart_signal_num = SIGXCPU;
-
-static SgenSemaphore suspend_ack_semaphore;
-static SgenSemaphore *suspend_ack_semaphore_ptr;
-
-static sigset_t suspend_signal_mask;
-static sigset_t suspend_ack_signal_mask;
-
-static void
-suspend_thread (SgenThreadInfo *info, void *context)
-{
- int stop_count;
- MonoContext ctx;
- gpointer stack_start;
-
- info->client_info.stopped_domain = mono_domain_get ();
- info->client_info.stack_start = NULL;
- info->client_info.signal = 0;
- stop_count = sgen_global_stop_count;
- /* duplicate signal */
- if (0 && info->client_info.stop_count == stop_count)
- return;
-
- 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;
- }
-
- /* 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;
-
- if (context) {
- memcpy (&info->client_info.ctx, &ctx, sizeof (MonoContext));
- } else {
- memset (&info->client_info.ctx, 0, sizeof (MonoContext));
- }
- } 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);
-}
-
-/* LOCKING: assumes the GC lock is held (by the stopping thread) */
-MONO_SIG_HANDLER_FUNC (static, suspend_handler)
-{
- /*
- * The suspend signal handler potentially uses syscalls that
- * can set errno, and it calls functions that use the hazard
- * pointer machinery. Since we're interrupting other code we
- * must restore those to the values they had when we
- * interrupted.
- */
- SgenThreadInfo *info;
- int old_errno = errno;
- int hp_save_index = mono_hazard_pointer_save_for_signal_handler ();
- MONO_SIG_HANDLER_GET_CONTEXT;
-
- info = mono_thread_info_current ();
- suspend_thread (info, ctx);
-
- mono_hazard_pointer_restore_for_signal_handler (hp_save_index);
- errno = old_errno;
-}
-
-MONO_SIG_HANDLER_FUNC (static, restart_handler)
-{
- SgenThreadInfo *info;
- int old_errno = errno;
-
- info = mono_thread_info_current ();
- info->client_info.signal = restart_signal_num;
- SGEN_LOG (4, "Restart handler in %p %p", info, (gpointer) (gsize) mono_native_thread_id_get ());
- errno = old_errno;
-}
-
-gboolean
-sgen_resume_thread (SgenThreadInfo *info)
-{
- return mono_threads_pthread_kill (info, restart_signal_num) == 0;
-}
-
-gboolean
-sgen_suspend_thread (SgenThreadInfo *info)
-{
- return mono_threads_pthread_kill (info, suspend_signal_num) == 0;
-}
-
-void
-sgen_wait_for_suspend_ack (int count)
-{
- int i, result;
-
- for (i = 0; i < count; ++i) {
- while ((result = SGEN_SEMAPHORE_WAIT (suspend_ack_semaphore_ptr)) != 0) {
- if (errno != EINTR) {
- g_error ("SGEN_SEMAPHORE_WAIT FAILED with %d errno %d (%s)", result, errno, strerror (errno));
- }
- }
- }
-}
-
-int
-sgen_thread_handshake (BOOL suspend)
-{
- int count, result;
- int signum = suspend ? suspend_signal_num : restart_signal_num;
-
- MonoNativeThreadId me = mono_native_thread_id_get ();
-
- count = 0;
- mono_thread_info_current ()->client_info.suspend_done = TRUE;
- FOREACH_THREAD (info) {
- if (mono_native_thread_id_equals (mono_thread_info_get_tid (info), me)) {
- continue;
- }
- info->client_info.suspend_done = FALSE;
- if (info->client_info.gc_disabled)
- continue;
- /*if (signum == suspend_signal_num && info->stop_count == global_stop_count)
- continue;*/
- result = mono_threads_pthread_kill (info, signum);
- if (result == 0) {
- count++;
- } else {
- info->client_info.skip = 1;
- }
- } FOREACH_THREAD_END
-
- sgen_wait_for_suspend_ack (count);
-
- SGEN_LOG (4, "%s handshake for %d threads\n", suspend ? "suspend" : "resume", count);
-
- return count;
-}
-
-void
-sgen_os_init (void)
-{
- struct sigaction sinfo;
-
- if (mono_thread_info_unified_management_enabled ())
- return;
-
- suspend_ack_semaphore_ptr = &suspend_ack_semaphore;
- SGEN_SEMAPHORE_INIT (&suspend_ack_semaphore, 0);
-
- sigfillset (&sinfo.sa_mask);
- sinfo.sa_flags = SA_RESTART | SA_SIGINFO;
- sinfo.sa_sigaction = suspend_handler;
- if (sigaction (suspend_signal_num, &sinfo, NULL) != 0) {
- g_error ("failed sigaction");
- }
-
- sinfo.sa_handler = (void (*)(int))restart_handler;
- if (sigaction (restart_signal_num, &sinfo, NULL) != 0) {
- g_error ("failed sigaction");
- }
-
- sigfillset (&suspend_signal_mask);
- sigdelset (&suspend_signal_mask, restart_signal_num);
-
- sigemptyset (&suspend_ack_signal_mask);
- sigaddset (&suspend_ack_signal_mask, restart_signal_num);
-
-}
-
-int
-mono_gc_get_suspend_signal (void)
-{
- return suspend_signal_num;
-}
-
-int
-mono_gc_get_restart_signal (void)
-{
- return restart_signal_num;
-}
-#endif
-#endif
diff --git a/mono/metadata/sgen-os-win32.c b/mono/metadata/sgen-os-win32.c
deleted file mode 100644
index d78be35069d..00000000000
--- a/mono/metadata/sgen-os-win32.c
+++ /dev/null
@@ -1,145 +0,0 @@
-#include "config.h"
-
-#if defined(HAVE_SGEN_GC) && !defined(USE_COOP_GC) && defined(HOST_WIN32)
-
-#include "io-layer/io-layer.h"
-
-#include "sgen/sgen-gc.h"
-#include "metadata/gc-internals.h"
-
-gboolean
-sgen_resume_thread (SgenThreadInfo *info)
-{
- DWORD id = mono_thread_info_get_tid (info);
- HANDLE handle = OpenThread (THREAD_ALL_ACCESS, FALSE, id);
- DWORD result;
-
- g_assert (handle);
-
- result = ResumeThread (handle);
- g_assert (result != (DWORD)-1);
-
- CloseHandle (handle);
-
- return result != (DWORD)-1 && result > 0;
-}
-
-gboolean
-sgen_suspend_thread (SgenThreadInfo *info)
-{
- DWORD id = mono_thread_info_get_tid (info);
- HANDLE handle = OpenThread (THREAD_ALL_ACCESS, FALSE, id);
- CONTEXT context;
- DWORD result;
-
- g_assert (id != GetCurrentThreadId ());
-
- g_assert (handle);
-
- result = SuspendThread (handle);
- if (result == (DWORD)-1) {
- fprintf (stderr, "could not suspend thread %x (handle %p): %d\n", id, handle, GetLastError ()); fflush (stderr);
- CloseHandle (handle);
- return FALSE;
- }
-
- context.ContextFlags = CONTEXT_INTEGER | CONTEXT_CONTROL;
-
- if (!GetThreadContext (handle, &context)) {
- g_assert_not_reached ();
- ResumeThread (handle);
- CloseHandle (handle);
- return FALSE;
- }
-
- g_assert (context.ContextFlags & CONTEXT_INTEGER);
- g_assert (context.ContextFlags & CONTEXT_CONTROL);
-
- CloseHandle (handle);
-
-#if !defined(MONO_CROSS_COMPILE)
- memset (&info->client_info.ctx, 0, sizeof (MonoContext));
-#ifdef TARGET_AMD64
- info->client_info.ctx.gregs[AMD64_RIP] = context.Rip;
- info->client_info.ctx.gregs[AMD64_RAX] = context.Rax;
- info->client_info.ctx.gregs[AMD64_RCX] = context.Rcx;
- info->client_info.ctx.gregs[AMD64_RDX] = context.Rdx;
- info->client_info.ctx.gregs[AMD64_RBX] = context.Rbx;
- info->client_info.ctx.gregs[AMD64_RSP] = context.Rsp;
- info->client_info.ctx.gregs[AMD64_RBP] = context.Rbp;
- info->client_info.ctx.gregs[AMD64_RSI] = context.Rsi;
- info->client_info.ctx.gregs[AMD64_RDI] = context.Rdi;
- info->client_info.ctx.gregs[AMD64_R8] = context.R8;
- info->client_info.ctx.gregs[AMD64_R9] = context.R9;
- info->client_info.ctx.gregs[AMD64_R10] = context.R10;
- info->client_info.ctx.gregs[AMD64_R11] = context.R11;
- info->client_info.ctx.gregs[AMD64_R12] = context.R12;
- info->client_info.ctx.gregs[AMD64_R13] = context.R13;
- info->client_info.ctx.gregs[AMD64_R14] = context.R14;
- info->client_info.ctx.gregs[AMD64_R15] = context.R15;
- info->client_info.stopped_ip = info->client_info.ctx.gregs[AMD64_RIP];
- info->client_info.stack_start = (char*)info->client_info.ctx.gregs[AMD64_RSP] - REDZONE_SIZE;
-#else
- info->client_info.ctx.edi = context.Edi;
- info->client_info.ctx.esi = context.Esi;
- info->client_info.ctx.ebx = context.Ebx;
- info->client_info.ctx.edx = context.Edx;
- info->client_info.ctx.ecx = context.Ecx;
- info->client_info.ctx.eax = context.Eax;
- info->client_info.ctx.ebp = context.Ebp;
- info->client_info.ctx.esp = context.Esp;
- info->client_info.stopped_ip = (gpointer)context.Eip;
- info->client_info.stack_start = (char*)context.Esp - REDZONE_SIZE;
-#endif
-#endif
-
- /* 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, NULL, NULL);
-
- return TRUE;
-}
-
-void
-sgen_wait_for_suspend_ack (int count)
-{
- /* Win32 suspend/resume is synchronous, so we don't need to wait for anything */
-}
-
-int
-sgen_thread_handshake (BOOL suspend)
-{
- SgenThreadInfo *current = mono_thread_info_current ();
- int count = 0;
-
- current->client_info.suspend_done = TRUE;
- FOREACH_THREAD (info) {
- if (info == current)
- continue;
- info->client_info.suspend_done = FALSE;
- if (info->client_info.gc_disabled)
- continue;
- if (suspend) {
- if (!sgen_suspend_thread (info))
- continue;
- } else {
- if (!sgen_resume_thread (info))
- continue;
- }
- ++count;
- } FOREACH_THREAD_END
- return count;
-}
-
-void
-sgen_os_init (void)
-{
-}
-
-int
-mono_gc_get_suspend_signal (void)
-{
- return -1;
-}
-
-#endif
diff --git a/mono/metadata/sgen-stw.c b/mono/metadata/sgen-stw.c
index 60e5933450f..9b9de7180ed 100644
--- a/mono/metadata/sgen-stw.c
+++ b/mono/metadata/sgen-stw.c
@@ -25,6 +25,7 @@
#include "metadata/sgen-bridge-internals.h"
#include "metadata/gc-internals.h"
#include "utils/mono-threads.h"
+#include "utils/mono-threads-debug.h"
#define TV_DECLARE SGEN_TV_DECLARE
#define TV_GETTIME SGEN_TV_GETTIME
@@ -76,106 +77,6 @@ update_current_thread_stack (void *start)
mono_gc_get_gc_callbacks ()->thread_suspend_func (info->client_info.runtime_data, NULL, &info->client_info.ctx);
}
-static gboolean
-is_ip_in_managed_allocator (MonoDomain *domain, gpointer ip)
-{
- MonoJitInfo *ji;
-
- if (!mono_thread_internal_current ())
- /* Happens during thread attach */
- return FALSE;
-
- if (!ip || !domain)
- return FALSE;
- if (!sgen_has_critical_method ())
- return FALSE;
-
- /*
- * mono_jit_info_table_find is not async safe since it calls into the AOT runtime to load information for
- * missing methods (#13951). To work around this, we disable the AOT fallback. For this to work, the JIT needs
- * to register the jit info for all GC critical methods after they are JITted/loaded.
- */
- ji = mono_jit_info_table_find_internal (domain, (char *)ip, FALSE, FALSE);
- if (!ji)
- return FALSE;
-
- return sgen_is_critical_method (mono_jit_info_get_method (ji));
-}
-
-static int
-restart_threads_until_none_in_managed_allocator (void)
-{
- int num_threads_died = 0;
- int sleep_duration = -1;
-
- for (;;) {
- int restart_count = 0, restarted_count = 0;
- /* restart all threads that stopped in the
- allocator */
- FOREACH_THREAD (info) {
- gboolean result;
- if (info->client_info.skip || info->client_info.gc_disabled || info->client_info.suspend_done)
- continue;
- if (mono_thread_info_is_live (info) &&
- (!info->client_info.stack_start || info->client_info.in_critical_region || info->client_info.info.inside_critical_region ||
- is_ip_in_managed_allocator (info->client_info.stopped_domain, info->client_info.stopped_ip))) {
- binary_protocol_thread_restart ((gpointer)mono_thread_info_get_tid (info));
- SGEN_LOG (3, "thread %p resumed.", (void*) (size_t) info->client_info.info.native_handle);
- result = sgen_resume_thread (info);
- if (result) {
- ++restart_count;
- } else {
- info->client_info.skip = 1;
- }
- } else {
- /* we set the stopped_ip to
- NULL for threads which
- we're not restarting so
- that we can easily identify
- the others */
- info->client_info.stopped_ip = NULL;
- info->client_info.stopped_domain = NULL;
- info->client_info.suspend_done = TRUE;
- }
- } FOREACH_THREAD_END
- /* if no threads were restarted, we're done */
- if (restart_count == 0)
- break;
-
- /* wait for the threads to signal their restart */
- sgen_wait_for_suspend_ack (restart_count);
-
- if (sleep_duration < 0) {
- mono_thread_info_yield ();
- sleep_duration = 0;
- } else {
- g_usleep (sleep_duration);
- sleep_duration += 10;
- }
-
- /* stop them again */
- FOREACH_THREAD (info) {
- gboolean result;
- if (info->client_info.skip || info->client_info.stopped_ip == NULL)
- continue;
- result = sgen_suspend_thread (info);
-
- if (result) {
- ++restarted_count;
- } else {
- info->client_info.skip = 1;
- }
- } FOREACH_THREAD_END
- /* some threads might have died */
- num_threads_died += restart_count - restarted_count;
- /* wait for the threads to signal their suspension
- again */
- sgen_wait_for_suspend_ack (restarted_count);
- }
-
- return num_threads_died;
-}
-
static void
acquire_gc_locks (void)
{
@@ -220,15 +121,7 @@ sgen_client_stop_world (int generation)
SGEN_LOG (3, "stopping world n %d from %p %p", sgen_global_stop_count, mono_thread_info_current (), (gpointer) (gsize) mono_native_thread_id_get ());
TV_GETTIME (stop_world_time);
- if (mono_thread_info_unified_management_enabled ()) {
- sgen_unified_suspend_stop_world ();
- } else {
- int count, dead;
- count = sgen_thread_handshake (TRUE);
- dead = restart_threads_until_none_in_managed_allocator ();
- if (count < dead)
- g_error ("More threads have died (%d) that been initialy suspended %d", dead, count);
- }
+ sgen_unified_suspend_stop_world ();
SGEN_LOG (3, "world stopped");
@@ -260,10 +153,7 @@ sgen_client_restart_world (int generation, gint64 *stw_time)
TV_GETTIME (start_handshake);
- if (mono_thread_info_unified_management_enabled ())
- sgen_unified_suspend_restart_world ();
- else
- sgen_thread_handshake (FALSE);
+ sgen_unified_suspend_restart_world ();
TV_GETTIME (end_sw);
time_restart_world += TV_ELAPSED (start_handshake, end_sw);
@@ -362,7 +252,7 @@ sgen_unified_suspend_stop_world (void)
int sleep_duration = -1;
mono_threads_begin_global_suspend ();
- THREADS_STW_DEBUG ("[GC-STW-BEGIN] *** BEGIN SUSPEND *** \n");
+ THREADS_STW_DEBUG ("[GC-STW-BEGIN][%p] *** BEGIN SUSPEND *** \n", mono_thread_info_get_tid (mono_thread_info_current ()));
FOREACH_THREAD (info) {
int reason;
@@ -370,9 +260,9 @@ sgen_unified_suspend_stop_world (void)
info->client_info.suspend_done = FALSE;
if (sgen_is_thread_in_current_stw (info, &reason)) {
info->client_info.skip = !mono_thread_info_begin_suspend (info);
- THREADS_STW_DEBUG ("[GC-STW-BEGIN-SUSPEND] SUSPEND thread %p skip %d\n", mono_thread_info_get_tid (info), info->client_info.skip);
+ THREADS_STW_DEBUG ("[GC-STW-BEGIN-SUSPEND] SUSPEND thread %p skip %s\n", mono_thread_info_get_tid (info), info->client_info.skip ? "true" : "false");
} else {
- THREADS_STW_DEBUG ("[GC-STW-BEGIN-SUSPEND] IGNORE thread %p skip %d reason %d\n", mono_thread_info_get_tid (info), info->client_info.skip, reason);
+ THREADS_STW_DEBUG ("[GC-STW-BEGIN-SUSPEND] IGNORE thread %p skip %s reason %d\n", mono_thread_info_get_tid (info), info->client_info.skip ? "true" : "false", reason);
}
} FOREACH_THREAD_END
@@ -400,11 +290,11 @@ sgen_unified_suspend_stop_world (void)
if (!(suspend_count == 1))
g_error ("[%p] suspend_count = %d, but should be 1", mono_thread_info_get_tid (info), suspend_count);
res = mono_thread_info_begin_resume (info);
- THREADS_STW_DEBUG ("[GC-STW-RESTART] RESTART thread %p skip %d\n", mono_thread_info_get_tid (info), res);
if (res)
++restart_counter;
else
info->client_info.skip = TRUE;
+ THREADS_STW_DEBUG ("[GC-STW-RESTART] RESTART thread %p skip %s\n", mono_thread_info_get_tid (info), info->client_info.skip ? "true" : "false");
} else {
THREADS_STW_DEBUG ("[GC-STW-RESTART] DONE thread %p deemed fully suspended\n", mono_thread_info_get_tid (info));
g_assert (!info->client_info.in_critical_region);
@@ -433,9 +323,9 @@ sgen_unified_suspend_stop_world (void)
if (mono_thread_info_is_running (info)) {
gboolean res = mono_thread_info_begin_suspend (info);
- THREADS_STW_DEBUG ("[GC-STW-RESTART] SUSPEND thread %p skip %d\n", mono_thread_info_get_tid (info), res);
if (!res)
info->client_info.skip = TRUE;
+ THREADS_STW_DEBUG ("[GC-STW-RESTART] SUSPEND thread %p skip %s\n", mono_thread_info_get_tid (info), info->client_info.skip ? "true" : "false");
}
} FOREACH_THREAD_END
@@ -445,36 +335,29 @@ sgen_unified_suspend_stop_world (void)
FOREACH_THREAD (info) {
int reason = 0;
if (sgen_is_thread_in_current_stw (info, &reason)) {
- MonoThreadUnwindState *state;
+ gpointer stopped_ip;
- THREADS_STW_DEBUG ("[GC-STW-SUSPEND-END] thread %p is suspended\n", mono_thread_info_get_tid (info));
g_assert (info->client_info.suspend_done);
- state = mono_thread_info_get_suspend_state (info);
+ info->client_info.ctx = mono_thread_info_get_suspend_state (info)->ctx;
- info->client_info.ctx = state->ctx;
+ /* Once we remove the old suspend code, we should move sgen to directly access the state in MonoThread */
+ info->client_info.stack_start = (gpointer) ((char*)MONO_CONTEXT_GET_SP (&info->client_info.ctx) - REDZONE_SIZE);
- if (!state->unwind_data [MONO_UNWIND_DATA_DOMAIN] || !state->unwind_data [MONO_UNWIND_DATA_LMF]) {
- /* thread is starting or detaching, nothing to scan here */
- info->client_info.stopped_domain = NULL;
- info->client_info.stopped_ip = NULL;
- info->client_info.stack_start = NULL;
- } else {
- /* Once we remove the old suspend code, we should move sgen to directly access the state in MonoThread */
- info->client_info.stopped_domain = (MonoDomain*) mono_thread_info_tls_get (info, TLS_KEY_DOMAIN);
- info->client_info.stopped_ip = (gpointer) (MONO_CONTEXT_GET_IP (&info->client_info.ctx));
- info->client_info.stack_start = (gpointer) ((char*)MONO_CONTEXT_GET_SP (&info->client_info.ctx) - REDZONE_SIZE);
-
- /* altstack signal handler, sgen can't handle them, mono-threads should have handled this. */
- if (!info->client_info.stack_start
- || info->client_info.stack_start < info->client_info.stack_start_limit
- || info->client_info.stack_start >= info->client_info.stack_end) {
- g_error ("BAD STACK: stack_start = %p, stack_start_limit = %p, stack_end = %p",
- info->client_info.stack_start, info->client_info.stack_start_limit, info->client_info.stack_end);
- }
+ /* altstack signal handler, sgen can't handle them, mono-threads should have handled this. */
+ if (!info->client_info.stack_start
+ || info->client_info.stack_start < info->client_info.stack_start_limit
+ || info->client_info.stack_start >= info->client_info.stack_end) {
+ g_error ("BAD STACK: stack_start = %p, stack_start_limit = %p, stack_end = %p",
+ info->client_info.stack_start, info->client_info.stack_start_limit, info->client_info.stack_end);
}
- binary_protocol_thread_suspend ((gpointer) mono_thread_info_get_tid (info), info->client_info.stopped_ip);
+ stopped_ip = (gpointer) (MONO_CONTEXT_GET_IP (&info->client_info.ctx));
+
+ THREADS_STW_DEBUG ("[GC-STW-SUSPEND-END] thread %p is suspended, stopped_ip = %p, stack = %p -> %p\n",
+ mono_thread_info_get_tid (info), stopped_ip, info->client_info.stack_start, info->client_info.stack_start ? info->client_info.stack_end : NULL);
+
+ binary_protocol_thread_suspend ((gpointer) mono_thread_info_get_tid (info), stopped_ip);
} else {
THREADS_STW_DEBUG ("[GC-STW-SUSPEND-END] thread %p is NOT suspended, reason %d\n", mono_thread_info_get_tid (info), reason);
g_assert (!info->client_info.suspend_done || info == mono_thread_info_current ());
diff --git a/mono/mini/mini-posix.c b/mono/mini/mini-posix.c
index bdd3149c25b..14c13a4c683 100644
--- a/mono/mini/mini-posix.c
+++ b/mono/mini/mini-posix.c
@@ -59,7 +59,6 @@
#include <mono/utils/dtrace.h>
#include <mono/utils/mono-signal-handler.h>
#include <mono/utils/mono-threads.h>
-#include <mono/utils/mono-threads-posix-signals.h>
#include "mini.h"
#include <string.h>
@@ -813,7 +812,7 @@ mono_runtime_setup_stat_profiler (void)
*/
#if defined (USE_POSIX_BACKEND) && defined (SIGRTMIN) && !defined (PLATFORM_ANDROID)
/* Just take the first real-time signal we can get. */
- profiler_signal = mono_threads_posix_signal_search_alternative (-1);
+ profiler_signal = mono_threads_suspend_search_alternative_signal ();
#else
profiler_signal = SIGPROF;
#endif
diff --git a/mono/utils/Makefile.am b/mono/utils/Makefile.am
index b569936d406..add4c6a85fe 100644
--- a/mono/utils/Makefile.am
+++ b/mono/utils/Makefile.am
@@ -126,7 +126,6 @@ monoutils_sources = \
mono-threads-state-machine.c \
mono-threads-posix.c \
mono-threads-posix-signals.c \
- mono-threads-posix-signals.h \
mono-threads-mach.c \
mono-threads-mach-helper.c \
mono-threads-windows.c \
@@ -136,12 +135,10 @@ monoutils_sources = \
mono-threads-openbsd.c \
mono-threads-android.c \
mono-threads.h \
+ mono-threads-debug.h \
mono-threads-api.h \
mono-threads-coop.c \
mono-threads-coop.h \
- mono-threads-mach-abort-syscall.c \
- mono-threads-posix-abort-syscall.c \
- mono-threads-windows-abort-syscall.c \
mono-tls.h \
mono-tls.c \
linux_magic.h \
diff --git a/mono/utils/mono-threads-coop.c b/mono/utils/mono-threads-coop.c
index 3416fe68207..22b232ad4d5 100644
--- a/mono/utils/mono-threads-coop.c
+++ b/mono/utils/mono-threads-coop.c
@@ -27,6 +27,7 @@
#include <mono/utils/mono-threads-coop.h>
#include <mono/utils/mono-threads-api.h>
#include <mono/utils/checked-build.h>
+#include <mono/utils/mono-threads-debug.h>
#ifdef TARGET_OSX
#include <mono/utils/mach-support.h>
diff --git a/mono/utils/mono-threads-debug.h b/mono/utils/mono-threads-debug.h
new file mode 100644
index 00000000000..750d53d5cd8
--- /dev/null
+++ b/mono/utils/mono-threads-debug.h
@@ -0,0 +1,42 @@
+
+#ifndef __MONO_UTILS_MONO_THREADS_DEBUG_H__
+#define __MONO_UTILS_MONO_THREADS_DEBUG_H__
+
+/* Logging - enable them below if you need specific logging for the category you need */
+#define MOSTLY_ASYNC_SAFE_PRINTF(...) do { \
+ char __buff[1024]; __buff [0] = '\0'; \
+ g_snprintf (__buff, sizeof (__buff), __VA_ARGS__); \
+ write (1, __buff, strlen (__buff)); \
+} while (0)
+
+#if 1
+#define THREADS_DEBUG(...)
+#else
+#define THREADS_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
+#endif
+
+#if 1
+#define THREADS_STW_DEBUG(...)
+#else
+#define THREADS_STW_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
+#endif
+
+#if 1
+#define THREADS_SUSPEND_DEBUG(...)
+#else
+#define THREADS_SUSPEND_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
+#endif
+
+#if 1
+#define THREADS_STATE_MACHINE_DEBUG(...)
+#else
+#define THREADS_STATE_MACHINE_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
+#endif
+
+#if 1
+#define THREADS_INTERRUPT_DEBUG(...)
+#else
+#define THREADS_INTERRUPT_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
+#endif
+
+#endif /* __MONO_UTILS_MONO_THREADS_DEBUG_H__ */
diff --git a/mono/utils/mono-threads-mach-abort-syscall.c b/mono/utils/mono-threads-mach-abort-syscall.c
deleted file mode 100644
index eb43625f479..00000000000
--- a/mono/utils/mono-threads-mach-abort-syscall.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * mono-threads-mach-abort-syscall.c: Low-level syscall aborting
- *
- * Author:
- * Ludovic Henry (ludovic@xamarin.com)
- *
- * (C) 2015 Xamarin, Inc
- */
-
-#include "config.h"
-#include <glib.h>
-
-#if defined (__MACH__)
-#define _DARWIN_C_SOURCE 1
-#endif
-
-#include <mono/utils/mono-threads.h>
-
-#if defined(USE_MACH_BACKEND)
-
-#if defined(HOST_WATCHOS) || defined(HOST_TVOS)
-
-void
-mono_threads_abort_syscall_init (void)
-{
-}
-
-void
-mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
-{
-
-}
-
-gboolean
-mono_threads_suspend_needs_abort_syscall (void)
-{
- return FALSE;
-}
-
-#else
-
-void
-mono_threads_abort_syscall_init (void)
-{
-}
-
-void
-mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
-{
- kern_return_t ret;
-
- do {
- ret = thread_suspend (info->native_handle);
- } while (ret == KERN_ABORTED);
-
- if (ret != KERN_SUCCESS)
- return;
-
- do {
- ret = thread_abort_safely (info->native_handle);
- } while (ret == KERN_ABORTED);
-
- /*
- * We are doing thread_abort when thread_abort_safely returns KERN_SUCCESS because
- * for some reason accept is not interrupted by thread_abort_safely.
- * The risk of aborting non-atomic operations while calling thread_abort should not
- * exist because by the time thread_abort_safely returns KERN_SUCCESS the target
- * thread should have return from the kernel and should be waiting for thread_resume
- * to resume the user code.
- */
- if (ret == KERN_SUCCESS)
- ret = thread_abort (info->native_handle);
-
- do {
- ret = thread_resume (info->native_handle);
- } while (ret == KERN_ABORTED);
-
- g_assert (ret == KERN_SUCCESS);
-}
-
-gboolean
-mono_threads_suspend_needs_abort_syscall (void)
-{
- return TRUE;
-}
-
-#endif
-
-#endif
diff --git a/mono/utils/mono-threads-mach.c b/mono/utils/mono-threads-mach.c
index 948804243cc..b696064decd 100644
--- a/mono/utils/mono-threads-mach.c
+++ b/mono/utils/mono-threads-mach.c
@@ -23,6 +23,7 @@
#include <mono/utils/mono-compiler.h>
#include <mono/utils/mono-threads.h>
#include <mono/utils/hazard-pointer.h>
+#include <mono/utils/mono-threads-debug.h>
void
mono_threads_suspend_init (void)
@@ -50,6 +51,18 @@ mono_threads_suspend_begin_async_resume (MonoThreadInfo *info)
g_assert_not_reached ();
}
+void
+mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
+{
+ g_assert_not_reached ();
+}
+
+gboolean
+mono_threads_suspend_needs_abort_syscall (void)
+{
+ return FALSE;
+}
+
#else /* defined(HOST_WATCHOS) || defined(HOST_TVOS) */
gboolean
@@ -81,14 +94,14 @@ mono_threads_suspend_begin_async_suspend (MonoThreadInfo *info, gboolean interru
}
info->suspend_can_continue = mono_threads_get_runtime_callbacks ()->
thread_state_init_from_handle (&info->thread_saved_state [ASYNC_SUSPEND_STATE_INDEX], info);
- THREADS_SUSPEND_DEBUG ("thread state %p -> %d\n", (gpointer)(gsize)info->native_handle, res);
+ THREADS_SUSPEND_DEBUG ("thread state %p -> %d\n", (gpointer)(gsize)info->native_handle, ret);
if (info->suspend_can_continue) {
if (interrupt_kernel)
thread_abort (info->native_handle);
} else {
THREADS_SUSPEND_DEBUG ("FAILSAFE RESUME/2 %p -> %d\n", (gpointer)(gsize)info->native_handle, 0);
}
- return info->suspend_can_continue;
+ return TRUE;
}
gboolean
@@ -145,6 +158,46 @@ mono_threads_suspend_begin_async_resume (MonoThreadInfo *info)
return ret == KERN_SUCCESS;
}
+void
+mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
+{
+ kern_return_t ret;
+
+ do {
+ ret = thread_suspend (info->native_handle);
+ } while (ret == KERN_ABORTED);
+
+ if (ret != KERN_SUCCESS)
+ return;
+
+ do {
+ ret = thread_abort_safely (info->native_handle);
+ } while (ret == KERN_ABORTED);
+
+ /*
+ * We are doing thread_abort when thread_abort_safely returns KERN_SUCCESS because
+ * for some reason accept is not interrupted by thread_abort_safely.
+ * The risk of aborting non-atomic operations while calling thread_abort should not
+ * exist because by the time thread_abort_safely returns KERN_SUCCESS the target
+ * thread should have return from the kernel and should be waiting for thread_resume
+ * to resume the user code.
+ */
+ if (ret == KERN_SUCCESS)
+ ret = thread_abort (info->native_handle);
+
+ do {
+ ret = thread_resume (info->native_handle);
+ } while (ret == KERN_ABORTED);
+
+ g_assert (ret == KERN_SUCCESS);
+}
+
+gboolean
+mono_threads_suspend_needs_abort_syscall (void)
+{
+ return TRUE;
+}
+
#endif /* defined(HOST_WATCHOS) || defined(HOST_TVOS) */
void
@@ -166,6 +219,35 @@ mono_threads_suspend_free (MonoThreadInfo *info)
mach_port_deallocate (current_task (), info->native_handle);
}
+void
+mono_threads_suspend_init_signals (void)
+{
+}
+
+gint
+mono_threads_suspend_search_alternative_signal (void)
+{
+ g_assert_not_reached ();
+}
+
+gint
+mono_threads_suspend_get_suspend_signal (void)
+{
+ return -1;
+}
+
+gint
+mono_threads_suspend_get_restart_signal (void)
+{
+ return -1;
+}
+
+gint
+mono_threads_suspend_get_abort_signal (void)
+{
+ return -1;
+}
+
#endif /* USE_MACH_BACKEND */
#ifdef __MACH__
diff --git a/mono/utils/mono-threads-posix-abort-syscall.c b/mono/utils/mono-threads-posix-abort-syscall.c
deleted file mode 100644
index 232161c273a..00000000000
--- a/mono/utils/mono-threads-posix-abort-syscall.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * mono-threads-posix-abort-syscall.c: Low-level syscall aborting
- *
- * Author:
- * Ludovic Henry (ludovic@xamarin.com)
- *
- * (C) 2015 Xamarin, Inc
- */
-
-#include "config.h"
-#include <glib.h>
-
-#if defined (__MACH__)
-#define _DARWIN_C_SOURCE 1
-#endif
-
-#include "mono-threads.h"
-#include "mono-threads-posix-signals.h"
-
-#if defined(USE_POSIX_BACKEND)
-
-void
-mono_threads_abort_syscall_init (void)
-{
- mono_threads_posix_init_signals (MONO_THREADS_POSIX_INIT_SIGNALS_ABORT);
-}
-
-void
-mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
-{
- /* We signal a thread to break it from the current syscall.
- * This signal should not be interpreted as a suspend request. */
- info->syscall_break_signal = TRUE;
- if (!mono_threads_pthread_kill (info, mono_threads_posix_get_abort_signal ()))
- mono_threads_add_to_pending_operation_set (info);
-}
-
-gboolean
-mono_threads_suspend_needs_abort_syscall (void)
-{
- return TRUE;
-}
-
-#endif
diff --git a/mono/utils/mono-threads-posix-signals.c b/mono/utils/mono-threads-posix-signals.c
index c1b67330fb5..0c8e6b462b1 100644
--- a/mono/utils/mono-threads-posix-signals.c
+++ b/mono/utils/mono-threads-posix-signals.c
@@ -17,7 +17,7 @@
#include <errno.h>
#include <signal.h>
-#include "mono-threads-posix-signals.h"
+#include "mono-threads-debug.h"
#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#define DEFAULT_SUSPEND_SIGNAL SIGXFSZ
@@ -26,25 +26,20 @@
#endif
#define DEFAULT_RESTART_SIGNAL SIGXCPU
-static int suspend_signal_num;
-static int restart_signal_num;
static int abort_signal_num;
static sigset_t suspend_signal_mask;
static sigset_t suspend_ack_signal_mask;
-//Can't avoid the circular dep on this. Will be gone pretty soon
-extern int mono_gc_get_suspend_signal (void);
-
-int
-mono_threads_posix_signal_search_alternative (int min_signal)
+gint
+mono_threads_suspend_search_alternative_signal (void)
{
#if !defined (SIGRTMIN)
g_error ("signal search only works with RTMIN");
#else
int i;
/* we try to avoid SIGRTMIN and any one that might have been set already, see bug #75387 */
- for (i = MAX (min_signal, SIGRTMIN) + 1; i < SIGRTMAX; ++i) {
+ for (i = SIGRTMIN + 1; i < SIGRTMAX; ++i) {
struct sigaction sinfo;
sigaction (i, NULL, &sinfo);
if (sinfo.sa_handler == SIG_DFL && (void*)sinfo.sa_sigaction == (void*)SIG_DFL) {
@@ -58,7 +53,9 @@ mono_threads_posix_signal_search_alternative (int min_signal)
static void
signal_add_handler (int signo, gpointer handler, int flags)
{
-#if !defined(__native_client__)
+#if defined(__native_client__)
+ g_assert_not_reached ();
+#else
/*FIXME, move the code from mini to utils and do the right thing!*/
struct sigaction sa;
struct sigaction previous_sa;
@@ -75,61 +72,20 @@ signal_add_handler (int signo, gpointer handler, int flags)
}
static int
-suspend_signal_get (void)
-{
-#if defined(PLATFORM_ANDROID)
- return SIGUNUSED;
-#elif !defined (SIGRTMIN)
-#ifdef SIGUSR1
- return SIGUSR1;
-#else
- return -1;
-#endif /* SIGUSR1 */
-#else
- static int suspend_signum = -1;
- if (suspend_signum == -1)
- suspend_signum = mono_threads_posix_signal_search_alternative (-1);
- return suspend_signum;
-#endif /* SIGRTMIN */
-}
-
-static int
-restart_signal_get (void)
-{
-#if defined(PLATFORM_ANDROID)
- return SIGTTOU;
-#elif !defined (SIGRTMIN)
-#ifdef SIGUSR2
- return SIGUSR2;
-#else
- return -1;
-#endif /* SIGUSR1 */
-#else
- static int resume_signum = -1;
- if (resume_signum == -1)
- resume_signum = mono_threads_posix_signal_search_alternative (suspend_signal_get () + 1);
- return resume_signum;
-#endif /* SIGRTMIN */
-}
-
-
-static int
abort_signal_get (void)
{
#if defined(PLATFORM_ANDROID)
return SIGTTIN;
-#elif !defined (SIGRTMIN)
-#ifdef SIGTTIN
- return SIGTTIN;
-#else
- return -1;
-#endif /* SIGRTMIN */
-#else
+#elif defined (SIGRTMIN)
static int abort_signum = -1;
if (abort_signum == -1)
- abort_signum = mono_threads_posix_signal_search_alternative (restart_signal_get () + 1);
+ abort_signum = mono_threads_suspend_search_alternative_signal ();
return abort_signum;
-#endif /* SIGRTMIN */
+#elif defined (SIGTTIN)
+ return SIGTTIN;
+#else
+ return -1;
+#endif
}
static void
@@ -142,7 +98,7 @@ restart_signal_handler (int _dummy, siginfo_t *_info, void *context)
int old_errno = errno;
info = mono_thread_info_current ();
- info->signal = restart_signal_num;
+ info->signal = DEFAULT_RESTART_SIGNAL;
errno = old_errno;
#endif
}
@@ -206,7 +162,7 @@ suspend_signal_handler (int _dummy, siginfo_t *info, void *context)
do {
current->signal = 0;
sigsuspend (&suspend_signal_mask);
- } while (current->signal != restart_signal_num);
+ } while (current->signal != DEFAULT_RESTART_SIGNAL);
/* Unblock the restart signal. */
pthread_sigmask (SIG_UNBLOCK, &suspend_ack_signal_mask, NULL);
@@ -232,81 +188,52 @@ done:
#endif
}
-static void
-abort_signal_handler (int _dummy, siginfo_t *info, void *context)
-{
-#if defined(__native_client__)
- g_assert_not_reached ();
-#else
- suspend_signal_handler (_dummy, info, context);
-#endif
-}
-
void
-mono_threads_posix_init_signals (MonoThreadPosixInitSignals signals)
+mono_threads_suspend_init_signals (void)
{
sigset_t signal_set;
- g_assert ((signals == MONO_THREADS_POSIX_INIT_SIGNALS_SUSPEND_RESTART) ^ (signals == MONO_THREADS_POSIX_INIT_SIGNALS_ABORT));
-
sigemptyset (&signal_set);
- switch (signals) {
- case MONO_THREADS_POSIX_INIT_SIGNALS_SUSPEND_RESTART: {
- if (mono_thread_info_unified_management_enabled ()) {
- suspend_signal_num = DEFAULT_SUSPEND_SIGNAL;
- restart_signal_num = DEFAULT_RESTART_SIGNAL;
- } else {
- suspend_signal_num = suspend_signal_get ();
- restart_signal_num = restart_signal_get ();
- }
+ sigfillset (&suspend_signal_mask);
+ sigdelset (&suspend_signal_mask, DEFAULT_RESTART_SIGNAL);
- sigfillset (&suspend_signal_mask);
- sigdelset (&suspend_signal_mask, restart_signal_num);
- if (!mono_thread_info_unified_management_enabled ())
- sigdelset (&suspend_signal_mask, mono_gc_get_suspend_signal ());
+ sigemptyset (&suspend_ack_signal_mask);
+ sigaddset (&suspend_ack_signal_mask, DEFAULT_RESTART_SIGNAL);
- sigemptyset (&suspend_ack_signal_mask);
- sigaddset (&suspend_ack_signal_mask, restart_signal_num);
+ signal_add_handler (DEFAULT_SUSPEND_SIGNAL, suspend_signal_handler, SA_RESTART);
+ signal_add_handler (DEFAULT_RESTART_SIGNAL, restart_signal_handler, SA_RESTART);
- signal_add_handler (suspend_signal_num, suspend_signal_handler, SA_RESTART);
- signal_add_handler (restart_signal_num, restart_signal_handler, SA_RESTART);
+ sigaddset (&signal_set, DEFAULT_SUSPEND_SIGNAL);
+ sigaddset (&signal_set, DEFAULT_RESTART_SIGNAL);
- sigaddset (&signal_set, suspend_signal_num);
- sigaddset (&signal_set, restart_signal_num);
+ abort_signal_num = abort_signal_get ();
- break;
- }
- case MONO_THREADS_POSIX_INIT_SIGNALS_ABORT: {
- abort_signal_num = abort_signal_get ();
-
- signal_add_handler (abort_signal_num, abort_signal_handler, 0);
-
- sigaddset (&signal_set, abort_signal_num);
+ /* the difference between abort and suspend here is made by not
+ * passing SA_RESTART, meaning we won't restart the syscall when
+ * receiving a signal */
+ signal_add_handler (abort_signal_num, suspend_signal_handler, 0);
- break;
- }
- default: g_assert_not_reached ();
- }
+ sigaddset (&signal_set, abort_signal_num);
/* ensure all the new signals are unblocked */
sigprocmask (SIG_UNBLOCK, &signal_set, NULL);
}
gint
-mono_threads_posix_get_suspend_signal (void)
+mono_threads_suspend_get_suspend_signal (void)
{
- return suspend_signal_num;
+ return DEFAULT_SUSPEND_SIGNAL;
}
gint
-mono_threads_posix_get_restart_signal (void)
+mono_threads_suspend_get_restart_signal (void)
{
- return restart_signal_num;
+ return DEFAULT_RESTART_SIGNAL;
}
gint
-mono_threads_posix_get_abort_signal (void)
+mono_threads_suspend_get_abort_signal (void)
{
return abort_signal_num;
}
diff --git a/mono/utils/mono-threads-posix-signals.h b/mono/utils/mono-threads-posix-signals.h
deleted file mode 100644
index 59a38c1ceb2..00000000000
--- a/mono/utils/mono-threads-posix-signals.h
+++ /dev/null
@@ -1,34 +0,0 @@
-
-#ifndef __MONO_THREADS_POSIX_SIGNALS_H__
-#define __MONO_THREADS_POSIX_SIGNALS_H__
-
-#include <config.h>
-#include <glib.h>
-
-#include "mono-threads.h"
-
-#if defined(USE_POSIX_BACKEND) || defined(USE_POSIX_SYSCALL_ABORT)
-
-typedef enum {
- MONO_THREADS_POSIX_INIT_SIGNALS_SUSPEND_RESTART,
- MONO_THREADS_POSIX_INIT_SIGNALS_ABORT,
-} MonoThreadPosixInitSignals;
-
-int
-mono_threads_posix_signal_search_alternative (int min_signal);
-
-void
-mono_threads_posix_init_signals (MonoThreadPosixInitSignals signals);
-
-gint
-mono_threads_posix_get_suspend_signal (void);
-
-gint
-mono_threads_posix_get_restart_signal (void);
-
-gint
-mono_threads_posix_get_abort_signal (void);
-
-#endif /* defined(USE_POSIX_BACKEND) || defined(USE_POSIX_SYSCALL_ABORT) */
-
-#endif /* __MONO_THREADS_POSIX_SIGNALS_H__ */
diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c
index 29486bac076..be440711fb3 100644
--- a/mono/utils/mono-threads-posix.c
+++ b/mono/utils/mono-threads-posix.c
@@ -15,10 +15,10 @@
#endif
#include <mono/utils/mono-threads.h>
-#include <mono/utils/mono-threads-posix-signals.h>
#include <mono/utils/mono-coop-semaphore.h>
#include <mono/metadata/gc-internals.h>
#include <mono/utils/w32handle.h>
+#include <mono/utils/mono-threads-debug.h>
#include <errno.h>
@@ -368,7 +368,7 @@ mono_threads_platform_init (void)
gboolean
mono_threads_suspend_begin_async_suspend (MonoThreadInfo *info, gboolean interrupt_kernel)
{
- int sig = interrupt_kernel ? mono_threads_posix_get_abort_signal () : mono_threads_posix_get_suspend_signal ();
+ int sig = interrupt_kernel ? mono_threads_suspend_get_abort_signal () : mono_threads_suspend_get_suspend_signal ();
if (!mono_threads_pthread_kill (info, sig)) {
mono_threads_add_to_pending_operation_set (info);
@@ -393,7 +393,24 @@ gboolean
mono_threads_suspend_begin_async_resume (MonoThreadInfo *info)
{
mono_threads_add_to_pending_operation_set (info);
- return mono_threads_pthread_kill (info, mono_threads_posix_get_restart_signal ()) == 0;
+ return mono_threads_pthread_kill (info, mono_threads_suspend_get_restart_signal ()) == 0;
+}
+
+void
+mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
+{
+ /* We signal a thread to break it from the current syscall.
+ * This signal should not be interpreted as a suspend request. */
+ info->syscall_break_signal = TRUE;
+ if (mono_threads_pthread_kill (info, mono_threads_suspend_get_abort_signal ()) == 0) {
+ mono_threads_add_to_pending_operation_set (info);
+ }
+}
+
+gboolean
+mono_threads_suspend_needs_abort_syscall (void)
+{
+ return TRUE;
}
void
@@ -412,7 +429,6 @@ mono_threads_suspend_free (MonoThreadInfo *info)
void
mono_threads_suspend_init (void)
{
- mono_threads_posix_init_signals (MONO_THREADS_POSIX_INIT_SIGNALS_SUSPEND_RESTART);
}
#endif /* defined(USE_POSIX_BACKEND) */
diff --git a/mono/utils/mono-threads-state-machine.c b/mono/utils/mono-threads-state-machine.c
index 9792d5dbe21..76963632297 100644
--- a/mono/utils/mono-threads-state-machine.c
+++ b/mono/utils/mono-threads-state-machine.c
@@ -6,6 +6,7 @@
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/atomic.h>
#include <mono/utils/checked-build.h>
+#include <mono/utils/mono-threads-debug.h>
#include <errno.h>
diff --git a/mono/utils/mono-threads-windows-abort-syscall.c b/mono/utils/mono-threads-windows-abort-syscall.c
deleted file mode 100644
index 02d25b76e1c..00000000000
--- a/mono/utils/mono-threads-windows-abort-syscall.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * mono-threads-windows-abort-syscall.c: Low-level syscall aborting
- *
- * Author:
- * Ludovic Henry (ludovic@xamarin.com)
- *
- * (C) 2015 Xamarin, Inc
- */
-
-#include "config.h"
-#include <glib.h>
-
-#include <mono/utils/mono-threads.h>
-
-#if defined(USE_WINDOWS_BACKEND)
-
-#include <limits.h>
-
-void
-mono_threads_abort_syscall_init (void)
-{
-}
-
-static void CALLBACK
-abort_apc (ULONG_PTR param)
-{
- THREADS_INTERRUPT_DEBUG ("%06d - abort_apc () called", GetCurrentThreadId ());
-}
-
-void
-mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
-{
- DWORD id = mono_thread_info_get_tid (info);
- HANDLE handle;
-
- handle = OpenThread (THREAD_ALL_ACCESS, FALSE, id);
- g_assert (handle);
-
- THREADS_INTERRUPT_DEBUG ("%06d - Aborting syscall in thread %06d", GetCurrentThreadId (), id);
- QueueUserAPC ((PAPCFUNC)abort_apc, handle, (ULONG_PTR)NULL);
-
- CloseHandle (handle);
-}
-
-gboolean
-mono_threads_suspend_needs_abort_syscall (void)
-{
- return TRUE;
-}
-
-#endif
diff --git a/mono/utils/mono-threads-windows.c b/mono/utils/mono-threads-windows.c
index 791b898005a..9a8a93b9694 100644
--- a/mono/utils/mono-threads-windows.c
+++ b/mono/utils/mono-threads-windows.c
@@ -12,6 +12,7 @@
#if defined(USE_WINDOWS_BACKEND)
#include <mono/utils/mono-compiler.h>
+#include <mono/utils/mono-threads-debug.h>
#include <limits.h>
@@ -63,7 +64,7 @@ mono_threads_suspend_begin_async_suspend (MonoThreadInfo *info, gboolean interru
}
CloseHandle (handle);
- return info->suspend_can_continue;
+ return TRUE;
}
gboolean
@@ -72,6 +73,33 @@ mono_threads_suspend_check_suspend_result (MonoThreadInfo *info)
return info->suspend_can_continue;
}
+static void CALLBACK
+abort_apc (ULONG_PTR param)
+{
+ THREADS_INTERRUPT_DEBUG ("%06d - abort_apc () called", GetCurrentThreadId ());
+}
+
+void
+mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
+{
+ DWORD id = mono_thread_info_get_tid (info);
+ HANDLE handle;
+
+ handle = OpenThread (THREAD_ALL_ACCESS, FALSE, id);
+ g_assert (handle);
+
+ THREADS_INTERRUPT_DEBUG ("%06d - Aborting syscall in thread %06d", GetCurrentThreadId (), id);
+ QueueUserAPC ((PAPCFUNC)abort_apc, handle, (ULONG_PTR)NULL);
+
+ CloseHandle (handle);
+}
+
+gboolean
+mono_threads_suspend_needs_abort_syscall (void)
+{
+ return TRUE;
+}
+
gboolean
mono_threads_suspend_begin_async_resume (MonoThreadInfo *info)
{
@@ -128,6 +156,35 @@ mono_threads_suspend_free (MonoThreadInfo *info)
{
}
+void
+mono_threads_suspend_init_signals (void)
+{
+}
+
+gint
+mono_threads_suspend_search_alternative_signal (void)
+{
+ g_assert_not_reached ();
+}
+
+gint
+mono_threads_suspend_get_suspend_signal (void)
+{
+ return -1;
+}
+
+gint
+mono_threads_suspend_get_restart_signal (void)
+{
+ return -1;
+}
+
+gint
+mono_threads_suspend_get_abort_signal (void)
+{
+ return -1;
+}
+
#endif
#if defined (HOST_WIN32)
diff --git a/mono/utils/mono-threads.c b/mono/utils/mono-threads.c
index 6ead6cfc23d..49031c860e5 100644
--- a/mono/utils/mono-threads.c
+++ b/mono/utils/mono-threads.c
@@ -29,6 +29,7 @@
#include <mono/utils/mono-coop-mutex.h>
#include <mono/utils/mono-coop-semaphore.h>
#include <mono/utils/mono-threads-coop.h>
+#include <mono/utils/mono-threads-debug.h>
#include <errno.h>
@@ -71,7 +72,6 @@ static gboolean mono_threads_inited = FALSE;
static MonoSemType suspend_semaphore;
static size_t pending_suspends;
-static gboolean unified_suspend_enabled;
#define mono_thread_info_run_state(info) (((MonoThreadInfo*)info)->thread_state & THREAD_STATE_MASK)
@@ -674,8 +674,6 @@ mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t info_size)
#endif
g_assert (res);
- unified_suspend_enabled = g_getenv ("MONO_ENABLE_UNIFIED_SUSPEND") != NULL || mono_threads_is_coop_enabled ();
-
if ((sleepLimit = g_getenv ("MONO_SLEEP_ABORT_LIMIT")) != NULL) {
errno = 0;
long threshold = strtol(sleepLimit, NULL, 10);
@@ -693,8 +691,8 @@ mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t info_size)
mono_thread_smr_init ();
mono_threads_platform_init ();
mono_threads_suspend_init ();
+ mono_threads_suspend_init_signals ();
mono_threads_coop_init ();
- mono_threads_abort_syscall_init ();
#if defined(__MACH__)
mono_mach_init (thread_info_key);
@@ -1098,12 +1096,6 @@ mono_thread_info_abort_socket_syscall_for_close (MonoNativeThreadId tid)
mono_thread_info_suspend_unlock ();
}
-gboolean
-mono_thread_info_unified_management_enabled (void)
-{
- return unified_suspend_enabled;
-}
-
/*
* mono_thread_info_set_is_async_context:
*
diff --git a/mono/utils/mono-threads.h b/mono/utils/mono-threads.h
index aebfaca9952..90c44c8b74d 100644
--- a/mono/utils/mono-threads.h
+++ b/mono/utils/mono-threads.h
@@ -90,44 +90,6 @@ and reduce the number of casts drastically.
/* Mono Threads internal configuration knows*/
-/* Logging - enable them below if you need specific logging for the category you need */
-#define MOSTLY_ASYNC_SAFE_PRINTF(...) do { \
- char __buff[1024]; __buff [0] = '\0'; \
- g_snprintf (__buff, sizeof (__buff), __VA_ARGS__); \
- write (1, __buff, strlen (__buff)); \
-} while (0)
-
-
-#if 1
-#define THREADS_DEBUG(...)
-#else
-#define THREADS_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
-#endif
-
-#if 1
-#define THREADS_STW_DEBUG(...)
-#else
-#define THREADS_STW_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
-#endif
-
-#if 1
-#define THREADS_SUSPEND_DEBUG(...)
-#else
-#define THREADS_SUSPEND_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
-#endif
-
-#if 1
-#define THREADS_STATE_MACHINE_DEBUG(...)
-#else
-#define THREADS_STATE_MACHINE_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
-#endif
-
-#if 1
-#define THREADS_INTERRUPT_DEBUG(...)
-#else
-#define THREADS_INTERRUPT_DEBUG MOSTLY_ASYNC_SAFE_PRINTF
-#endif
-
/* If this is defined, use the signals backed on Mach. Debug only as signals can't be made usable on OSX. */
// #define USE_SIGNALS_ON_MACH
@@ -370,9 +332,6 @@ mono_thread_info_end_self_suspend (void);
//END of new API
-gboolean
-mono_thread_info_unified_management_enabled (void);
-
void
mono_thread_info_setup_async_call (THREAD_INFO_TYPE *info, void (*target_func)(void*), void *user_data);
@@ -475,12 +434,12 @@ This is called very early in the runtime, it cannot access any runtime facilitie
*/
void mono_threads_suspend_init (void); //ok
+void mono_threads_suspend_init_signals (void);
+
void mono_threads_platform_init (void);
void mono_threads_coop_init (void);
-void mono_threads_abort_syscall_init (void);
-
/*
This begins async suspend. This function must do the following:
@@ -513,6 +472,10 @@ void mono_threads_suspend_register (THREAD_INFO_TYPE *info); //ok
void mono_threads_suspend_free (THREAD_INFO_TYPE *info);
void mono_threads_suspend_abort_syscall (THREAD_INFO_TYPE *info);
gboolean mono_threads_suspend_needs_abort_syscall (void);
+gint mono_threads_suspend_search_alternative_signal (void);
+gint mono_threads_suspend_get_suspend_signal (void);
+gint mono_threads_suspend_get_restart_signal (void);
+gint mono_threads_suspend_get_abort_signal (void);
void mono_threads_platform_register (THREAD_INFO_TYPE *info);
void mono_threads_platform_unregister (THREAD_INFO_TYPE *info);
diff --git a/msvc/libmonoruntime.vcxproj b/msvc/libmonoruntime.vcxproj
index 06836b9b0f8..c51ed6b6c19 100644
--- a/msvc/libmonoruntime.vcxproj
+++ b/msvc/libmonoruntime.vcxproj
@@ -89,25 +89,11 @@
<ClCompile Include="..\mono\metadata\mono-security.c" />
<ClCompile Include="..\mono\metadata\seq-points-data.c" />
<ClCompile Include="..\mono\metadata\sgen-mono.c" />
- <ClCompile Include="..\mono\metadata\sgen-os-coop.c" />
<ClCompile Include="..\mono\metadata\threadpool-ms-io.c" />
<ClCompile Include="..\mono\metadata\threadpool-ms.c" />
<ClCompile Include="..\mono\metadata\sgen-bridge.c" />
<ClCompile Include="..\mono\metadata\sgen-new-bridge.c" />
<ClCompile Include="..\mono\metadata\sgen-old-bridge.c" />
- <ClCompile Include="..\mono\metadata\sgen-os-mach.c">
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
- </ClCompile>
- <ClCompile Include="..\mono\metadata\sgen-os-posix.c">
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
- </ClCompile>
- <ClCompile Include="..\mono\metadata\sgen-os-win32.c" />
<ClCompile Include="..\mono\metadata\sgen-tarjan-bridge.c" />
<ClCompile Include="..\mono\metadata\sgen-toggleref.c" />
<ClCompile Include="..\mono\metadata\sgen-stw.c" />
diff --git a/msvc/libmonoruntime.vcxproj.filters b/msvc/libmonoruntime.vcxproj.filters
index 10ea5f5b356..e0257f56ee4 100644
--- a/msvc/libmonoruntime.vcxproj.filters
+++ b/msvc/libmonoruntime.vcxproj.filters
@@ -175,15 +175,6 @@
<ClCompile Include="..\mono\metadata\boehm-gc.c">
<Filter>Source Files\boehm</Filter>
</ClCompile>
- <ClCompile Include="..\mono\metadata\sgen-os-mach.c">
- <Filter>Source Files\sgen</Filter>
- </ClCompile>
- <ClCompile Include="..\mono\metadata\sgen-os-posix.c">
- <Filter>Source Files\sgen</Filter>
- </ClCompile>
- <ClCompile Include="..\mono\metadata\sgen-os-win32.c">
- <Filter>Source Files\sgen</Filter>
- </ClCompile>
<ClCompile Include="..\mono\metadata\appdomain.c">
<Filter>Source Files\gc</Filter>
</ClCompile>
@@ -250,9 +241,6 @@
<ClCompile Include="..\mono\metadata\sre-save.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\mono\metadata\sgen-os-coop.c">
- <Filter>Source Files\sgen</Filter>
- </ClCompile>
<ClCompile Include="..\mono\metadata\socket-io-windows.c">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/msvc/libmonoutils.vcxproj b/msvc/libmonoutils.vcxproj
index f43c59b7894..ae6dadbcc61 100644
--- a/msvc/libmonoutils.vcxproj
+++ b/msvc/libmonoutils.vcxproj
@@ -104,19 +104,6 @@
<ClCompile Include="..\mono\utils\mono-threads-windows.c" />
<ClCompile Include="..\mono\utils\mono-threads.c" />
<ClCompile Include="..\mono\utils\mono-threads-coop.c" />
- <ClCompile Include="..\mono\utils\mono-threads-posix-abort-syscall.c">
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
- </ClCompile>
- <ClCompile Include="..\mono\utils\mono-threads-mach-abort-syscall.c">
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
- </ClCompile>
- <ClCompile Include="..\mono\utils\mono-threads-windows-abort-syscall.c" />
<ClCompile Include="..\mono\utils\mono-time.c" />
<ClCompile Include="..\mono\utils\mono-tls.c" />
<ClCompile Include="..\mono\utils\mono-uri.c" />
@@ -191,7 +178,6 @@
<ClInclude Include="..\mono\utils\mono-threads.h" />
<ClInclude Include="..\mono\utils\mono-threads-api.h" />
<ClInclude Include="..\mono\utils\mono-threads-coop.h" />
- <ClInclude Include="..\mono\utils\mono-threads-posix-signals.h" />
<ClInclude Include="..\mono\utils\mono-time.h" />
<ClInclude Include="..\mono\utils\mono-tls.h" />
<ClInclude Include="..\mono\utils\mono-uri.h" />