|
20 | 20 | #include <mono/utils/mono-threads-wasm.h>
|
21 | 21 |
|
22 | 22 | #include <emscripten.h>
|
23 |
| -#include <emscripten/stack.h> |
24 | 23 | #ifndef DISABLE_THREADS
|
25 | 24 | #include <emscripten/threading.h>
|
26 | 25 | #include <mono/metadata/threads-types.h>
|
27 | 26 | #endif
|
28 | 27 |
|
29 |
| - |
30 |
| -#define round_down(addr, val) ((void*)((addr) & ~((val) - 1))) |
31 |
| - |
32 |
| -EMSCRIPTEN_KEEPALIVE |
33 |
| -static int |
34 |
| -wasm_get_stack_base (void) |
35 |
| -{ |
36 |
| - // wasm-mt: add MONO_ENTER_GC_UNSAFE / MONO_EXIT_GC_UNSAFE if this function becomes more complex |
37 |
| - return emscripten_stack_get_end (); |
38 |
| -} |
39 |
| - |
40 |
| -EMSCRIPTEN_KEEPALIVE |
41 |
| -static int |
42 |
| -wasm_get_stack_size (void) |
43 |
| -{ |
44 |
| - // wasm-mt: add MONO_ENTER_GC_UNSAFE / MONO_EXIT_GC_UNSAFE if this function becomes more complex |
45 |
| - return (guint8*)emscripten_stack_get_base () - (guint8*)emscripten_stack_get_end (); |
46 |
| -} |
47 |
| - |
48 |
| -#else /* HOST_BROWSER -> WASI */ |
| 28 | +#endif |
49 | 29 |
|
50 | 30 | uintptr_t get_wasm_stack_high(void);
|
51 | 31 | uintptr_t get_wasm_stack_low(void);
|
52 | 32 |
|
53 | 33 | static int
|
54 | 34 | wasm_get_stack_size (void)
|
55 | 35 | {
|
| 36 | + // this will need further change for multithreading as the stack will allocated be per thread at different addresses |
| 37 | + |
56 | 38 | /*
|
57 | 39 | * | -- increasing address ---> |
|
58 |
| - * | data (data_end)| stack |(heap_base) heap | |
| 40 | + * | data |(stack low) stack (stack high)| heap | |
59 | 41 | */
|
60 |
| - size_t heap_base = get_wasm_stack_high(); |
61 |
| - size_t data_end = get_wasm_stack_low(); |
62 |
| - size_t max_stack_size = heap_base - data_end; |
| 42 | + size_t stack_high = get_wasm_stack_high(); |
| 43 | + size_t stack_low = get_wasm_stack_low(); |
| 44 | + size_t max_stack_size = stack_high - stack_low; |
63 | 45 |
|
64 |
| - g_assert (data_end > 0); |
65 |
| - g_assert (heap_base > data_end); |
| 46 | + g_assert (stack_low > 0); |
| 47 | + g_assert (stack_high > stack_low); |
66 | 48 |
|
67 |
| - // this is the max available stack size size, |
68 |
| - // return a 16-byte aligned smaller size |
69 |
| - return max_stack_size & ~0xF; |
| 49 | + // this is the max available stack size size |
| 50 | + return max_stack_size; |
70 | 51 | }
|
71 | 52 |
|
72 |
| -static int |
73 |
| -wasm_get_stack_base (void) |
74 |
| -{ |
75 |
| - return get_wasm_stack_high(); |
76 |
| - // this will need further change for multithreading as the stack will allocated be per thread at different addresses |
77 |
| -} |
78 |
| - |
79 |
| -#endif /* HOST_BROWSER */ |
80 |
| - |
81 | 53 | int
|
82 | 54 | mono_thread_info_get_system_max_stack_size (void)
|
83 | 55 | {
|
84 | 56 | return wasm_get_stack_size ();
|
85 | 57 | }
|
86 | 58 |
|
87 |
| - |
88 | 59 | void
|
89 | 60 | mono_threads_suspend_init_signals (void)
|
90 | 61 | {
|
@@ -224,11 +195,11 @@ mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
|
224 | 195 | g_error ("%s: pthread_attr_destroy failed with \"%s\" (%d)", __func__, g_strerror (res), res);
|
225 | 196 |
|
226 | 197 | if (*staddr == NULL) {
|
227 |
| - *staddr = (guint8*)wasm_get_stack_base (); |
| 198 | + *staddr = (guint8*)get_wasm_stack_low (); |
228 | 199 | *stsize = wasm_get_stack_size ();
|
229 | 200 | }
|
230 | 201 | #else
|
231 |
| - *staddr = (guint8*)wasm_get_stack_base (); |
| 202 | + *staddr = (guint8*)get_wasm_stack_low (); |
232 | 203 | *stsize = wasm_get_stack_size ();
|
233 | 204 | #endif
|
234 | 205 |
|
|
0 commit comments