From: Rodrigo Kumpera Date: Mon, 21 Aug 2017 23:26:04 +0000 (-0700) Subject: [wasm] Add threading, dl and hwcap support for wasm. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=1a621cfcf108d2e9da43ee04a8b43d3a99cb846f [wasm] Add threading, dl and hwcap support for wasm. --- diff --git a/mono/utils/Makefile.am b/mono/utils/Makefile.am index b2776888591..118ab953d0e 100644 --- a/mono/utils/Makefile.am +++ b/mono/utils/Makefile.am @@ -39,6 +39,7 @@ monoutils_sources = \ mono-dl-windows.c \ mono-dl-darwin.c \ mono-dl-posix.c \ + mono-dl-wasm.c \ mono-dl.h \ mono-dl-windows-internals.h \ mono-log-windows.c \ @@ -136,6 +137,7 @@ monoutils_sources = \ mono-threads-openbsd.c \ mono-threads-android.c \ mono-threads-haiku.c \ + mono-threads-wasm.c \ mono-threads.h \ mono-threads-debug.h \ mono-threads-api.h \ @@ -246,6 +248,10 @@ if S390X arch_sources += mono-hwcap-s390x.c endif +if HOST_WASM +arch_sources += mono-hwcap-wasm.c +endif + else arch_sources += mono-hwcap-cross.c diff --git a/mono/utils/mono-dl-wasm.c b/mono/utils/mono-dl-wasm.c new file mode 100644 index 00000000000..029eb125bcb --- /dev/null +++ b/mono/utils/mono-dl-wasm.c @@ -0,0 +1,75 @@ +#include + +#if defined (HOST_WASM) + +#include "mono/utils/mono-dl.h" +#include "mono/utils/mono-embed.h" +#include "mono/utils/mono-path.h" + +#include +#include +#include +#include +#include + +const char * +mono_dl_get_so_prefix (void) +{ + return ""; +} +const char ** +mono_dl_get_so_suffixes (void) +{ + static const char *suffixes[] = { + ".wasm", + "", + }; + return suffixes; +} + +int +mono_dl_get_executable_path (char *buf, int buflen) +{ + strncpy (buf, "/managed", buflen); + return 0; +} + +const char* +mono_dl_get_system_dir (void) +{ + return NULL; +} + + +void* +mono_dl_lookup_symbol (MonoDl *module, const char *name) +{ + return NULL; +} + +char* +mono_dl_current_error_string (void) +{ + return g_strdup (""); +} + + +int +mono_dl_convert_flags (int flags) +{ + return flags; +} + +void * +mono_dl_open_file (const char *file, int flags) +{ + return NULL; +} + +void +mono_dl_close_handle (MonoDl *module) +{ + //nothing to do +} + +#endif diff --git a/mono/utils/mono-hwcap-wasm.c b/mono/utils/mono-hwcap-wasm.c new file mode 100644 index 00000000000..d7d78b082b5 --- /dev/null +++ b/mono/utils/mono-hwcap-wasm.c @@ -0,0 +1,15 @@ +/** + * \file + * wasm feature detection + * + * Authors: + * Rodrigo Kumpera (kumpera@gmail.com) + * Licensed under the MIT license. See LICENSE file in the project root for full license information. + */ + +#include "mono/utils/mono-hwcap.h" + +void +mono_hwcap_arch_init (void) +{ +} diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c index 22fcb674add..6804024e156 100644 --- a/mono/utils/mono-threads-posix.c +++ b/mono/utils/mono-threads-posix.c @@ -30,7 +30,7 @@ extern int tkill (pid_t tid, int signal); #endif -#if defined(_POSIX_VERSION) +#if defined(_POSIX_VERSION) && !defined (TARGET_WASM) #include diff --git a/mono/utils/mono-threads-wasm.c b/mono/utils/mono-threads-wasm.c new file mode 100644 index 00000000000..6ef8a9c5e84 --- /dev/null +++ b/mono/utils/mono-threads-wasm.c @@ -0,0 +1,60 @@ +#include "config.h" + +#include +#include + +#if defined (USE_WASM_BACKEND) + +#define round_down(addr, val) ((void*)((addr) & ~((val) - 1))) + +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 +} + +void +mono_threads_suspend_init_signals (void) +{ +} + +void +mono_threads_suspend_init (void) +{ +} + +void +mono_threads_suspend_register (MonoThreadInfo *info) +{ +} + +gboolean +mono_threads_suspend_begin_async_resume (MonoThreadInfo *info) +{ + return TRUE; +} + +void +mono_threads_suspend_free (MonoThreadInfo *info) +{ +} + +gboolean +mono_threads_suspend_begin_async_suspend (MonoThreadInfo *info, gboolean interrupt_kernel) +{ + return TRUE; +} + +gboolean +mono_threads_suspend_check_suspend_result (MonoThreadInfo *info) +{ + return TRUE; +} + +void +mono_threads_suspend_abort_syscall (MonoThreadInfo *info) +{ +} + +#endif diff --git a/mono/utils/mono-threads.h b/mono/utils/mono-threads.h index ff3b40ed525..ffa9de63a66 100644 --- a/mono/utils/mono-threads.h +++ b/mono/utils/mono-threads.h @@ -109,7 +109,9 @@ and reduce the number of casts drastically. /* 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 -#if defined (_POSIX_VERSION) +#ifdef HOST_WASM +#define USE_WASM_BACKEND +#elif defined (_POSIX_VERSION) #if defined (__MACH__) && !defined (USE_SIGNALS_ON_MACH) #define USE_MACH_BACKEND #else