Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / utils / mono-threads-wasm.c
1 #include "config.h"
2
3 #include <mono/utils/mono-threads.h>
4 #include <mono/utils/mono-mmap.h>
5
6 #if defined (USE_WASM_BACKEND)
7
8 #define round_down(addr, val) ((void*)((addr) & ~((val) - 1)))
9
10 int
11 mono_threads_get_max_stack_size (void)
12 {
13         return 65536 * 8; //totally arbitrary, this value is actually useless until WASM supports multiple threads.
14 }
15
16
17 void
18 mono_threads_suspend_init_signals (void)
19 {
20 }
21
22 void
23 mono_threads_suspend_init (void)
24 {
25 }
26
27 void
28 mono_threads_suspend_register (MonoThreadInfo *info)
29 {
30 }
31
32 gboolean
33 mono_threads_suspend_begin_async_resume (MonoThreadInfo *info)
34 {
35         return TRUE;
36 }
37
38 void
39 mono_threads_suspend_free (MonoThreadInfo *info)
40 {
41 }
42
43 gboolean
44 mono_threads_suspend_begin_async_suspend (MonoThreadInfo *info, gboolean interrupt_kernel)
45 {
46         return TRUE;
47 }
48
49 gboolean
50 mono_threads_suspend_check_suspend_result (MonoThreadInfo *info)
51 {
52         return TRUE;
53 }
54
55 void
56 mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
57 {
58 }
59
60 //----
61
62 gboolean
63 mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2)
64 {
65         return id1 == id2;
66 }
67
68
69 MonoNativeThreadId
70 mono_native_thread_id_get (void)
71 {
72         return (MonoNativeThreadId)1;
73 }
74
75 MONO_API gboolean
76 mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg)
77 {
78         g_error ("WASM doesn't support threading");
79 }
80
81 static const char *thread_name;
82
83 void
84 mono_native_thread_set_name (MonoNativeThreadId tid, const char *name)
85 {
86         thread_name = g_strdup (name);
87 }
88
89 gboolean
90 mono_native_thread_join (MonoNativeThreadId tid)
91 {
92         g_error ("WASM doesn't support threading");
93         return FALSE;
94 }
95
96 //----
97
98 gboolean
99 mono_threads_platform_yield (void)
100 {
101         return TRUE;
102 }
103
104 void
105 mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
106 {
107         *staddr = round_down ((size_t)&staddr, 65536); //WASM pagesize is 64k
108         *stsize = 65536 * 4; //we say it's 4 pages, there isn't much that uses this beyond the GC
109 }
110
111
112 gboolean
113 mono_thread_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_data, gsize* const stack_size, MonoNativeThreadId *tid)
114 {
115         g_error ("WASM doesn't support threading");
116         return FALSE;
117 }
118
119 void mono_threads_platform_init (void)
120 {
121 }
122
123 void
124 mono_threads_platform_exit (gsize exit_code)
125 {
126         g_error ("WASM doesn't support threading");
127 }
128
129 gboolean
130 mono_threads_platform_in_critical_region (MonoNativeThreadId tid)
131 {
132         return FALSE;
133 }
134
135 #endif