From 06fcf41eaedf94e28151954d7aa17a0c0bb3f086 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Thu, 31 Aug 2017 11:18:52 -0700 Subject: [PATCH] [wasm] Disable posix threading backend and fix wasm's. --- mono/utils/mono-threads-coop.c | 3 ++ mono/utils/mono-threads-wasm.c | 83 ++++++++++++++++++++++++++++++++-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/mono/utils/mono-threads-coop.c b/mono/utils/mono-threads-coop.c index 440eff85125..1b9849fe5af 100644 --- a/mono/utils/mono-threads-coop.c +++ b/mono/utils/mono-threads-coop.c @@ -37,6 +37,9 @@ #ifdef _MSC_VER // TODO: Find MSVC replacement for __builtin_unwind_init #define SAVE_REGS_ON_STACK g_assert_not_reached (); +#elif defined (HOST_WASM) +//TODO: figure out wasm stack scanning +#define SAVE_REGS_ON_STACK do {} while (0) #else #define SAVE_REGS_ON_STACK __builtin_unwind_init (); #endif diff --git a/mono/utils/mono-threads-wasm.c b/mono/utils/mono-threads-wasm.c index 6ef8a9c5e84..60816ed8d57 100644 --- a/mono/utils/mono-threads-wasm.c +++ b/mono/utils/mono-threads-wasm.c @@ -7,13 +7,13 @@ #define round_down(addr, val) ((void*)((addr) & ~((val) - 1))) -void -mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize) +int +mono_threads_get_max_stack_size (void) { - *staddr = round_down ((size_t)&staddr, 65536); //WASM pagesize is 64k - *stsize = 65536 * 4; //we say it's 4 pages, there isn't much that uses this beyond the GC + return 65536 * 8; //totally arbitrary, this value is actually useless until WASM supports multiple threads. } + void mono_threads_suspend_init_signals (void) { @@ -57,4 +57,79 @@ mono_threads_suspend_abort_syscall (MonoThreadInfo *info) { } +//---- + +gboolean +mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2) +{ + return id1 == id2; +} + + +MonoNativeThreadId +mono_native_thread_id_get (void) +{ + return (MonoNativeThreadId)1; +} + +MONO_API gboolean +mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg) +{ + g_error ("WASM doesn't support threading"); +} + +static const char *thread_name; + +void +mono_native_thread_set_name (MonoNativeThreadId tid, const char *name) +{ + thread_name = g_strdup (name); +} + +gboolean +mono_native_thread_join (MonoNativeThreadId tid) +{ + g_error ("WASM doesn't support threading"); + return FALSE; +} + +//---- + +gboolean +mono_threads_platform_yield (void) +{ + return TRUE; +} + +void +mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize) +{ + *staddr = round_down ((size_t)&staddr, 65536); //WASM pagesize is 64k + *stsize = 65536 * 4; //we say it's 4 pages, there isn't much that uses this beyond the GC +} + + +gboolean +mono_thread_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_data, gsize* const stack_size, MonoNativeThreadId *tid) +{ + g_error ("WASM doesn't support threading"); + return FALSE; +} + +void mono_threads_platform_init (void) +{ +} + +void +mono_threads_platform_exit (gsize exit_code) +{ + g_error ("WASM doesn't support threading"); +} + +gboolean +mono_threads_platform_in_critical_region (MonoNativeThreadId tid) +{ + return FALSE; +} + #endif -- 2.25.1