[wasm] Add threading, dl and hwcap support for wasm.
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 21 Aug 2017 23:26:04 +0000 (16:26 -0700)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 23 Aug 2017 20:56:55 +0000 (13:56 -0700)
mono/utils/Makefile.am
mono/utils/mono-dl-wasm.c [new file with mode: 0644]
mono/utils/mono-hwcap-wasm.c [new file with mode: 0644]
mono/utils/mono-threads-posix.c
mono/utils/mono-threads-wasm.c [new file with mode: 0644]
mono/utils/mono-threads.h

index b277688859176ae54ff3a4d3c5b16ff574eccbb5..118ab953d0e8bcc172995e3e797a268899737113 100644 (file)
@@ -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 (file)
index 0000000..029eb12
--- /dev/null
@@ -0,0 +1,75 @@
+#include <config.h>
+
+#if defined (HOST_WASM)
+
+#include "mono/utils/mono-dl.h"
+#include "mono/utils/mono-embed.h"
+#include "mono/utils/mono-path.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <glib.h>
+
+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 (file)
index 0000000..d7d78b0
--- /dev/null
@@ -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)
+{
+}
index 22fcb674add26a94d235726f21a0a701afb40bc8..6804024e156a0a6a31ff4c9ff3db282344197a02 100644 (file)
@@ -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 <pthread.h>
 
diff --git a/mono/utils/mono-threads-wasm.c b/mono/utils/mono-threads-wasm.c
new file mode 100644 (file)
index 0000000..6ef8a9c
--- /dev/null
@@ -0,0 +1,60 @@
+#include "config.h"
+
+#include <mono/utils/mono-threads.h>
+#include <mono/utils/mono-mmap.h>
+
+#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
index ff3b40ed525e236b1fcafdeea25aaac9f4015620..ffa9de63a66e5468d8cd5fe58989202cb73755b1 100644 (file)
@@ -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