summaryrefslogtreecommitdiff
path: root/test/wasm2c/hello.txt
diff options
context:
space:
mode:
Diffstat (limited to 'test/wasm2c/hello.txt')
-rw-r--r--test/wasm2c/hello.txt40
1 files changed, 28 insertions, 12 deletions
diff --git a/test/wasm2c/hello.txt b/test/wasm2c/hello.txt
index 77608b6c..a9beeede 100644
--- a/test/wasm2c/hello.txt
+++ b/test/wasm2c/hello.txt
@@ -131,11 +131,16 @@ void w2c_test_0x5Fstart(w2c_test*);
// for accessing pointers, and supports memcpy on pointers with custom
// "address namespaces". GCC does not support the memcpy requirement, so
// this leaves only clang for now.
-// (5) The OS doesn't replace the segment register on context switch which
+// (5) The OS provides a way to query if (rd|wr)gsbase is allowed by the kernel
+// or the implementation has to use a syscall for this.
+// (6) The OS doesn't replace the segment register on context switch which
// eliminates windows for now
+//
+// While more OS can be supported in the future, we only support linux for now
#if WASM_RT_ALLOW_SEGUE && !WABT_BIG_ENDIAN && \
(defined(__x86_64__) || defined(_M_X64)) && IS_SINGLE_UNSHARED_MEMORY && \
- __clang__ && __has_builtin(__builtin_ia32_wrgsbase64) && !defined(_WIN32)
+ __clang__ && __has_builtin(__builtin_ia32_wrgsbase64) && \
+ !defined(_WIN32) && defined(__linux__)
#define WASM_RT_USE_SEGUE 1
#else
#define WASM_RT_USE_SEGUE 0
@@ -144,9 +149,20 @@ void w2c_test_0x5Fstart(w2c_test*);
#if WASM_RT_USE_SEGUE
// POSIX uses FS for TLS, GS is free
-#define WASM_RT_SEGUE_READ_BASE() __builtin_ia32_rdgsbase64()
-#define WASM_RT_SEGUE_WRITE_BASE(base) \
- __builtin_ia32_wrgsbase64((uintptr_t)base)
+static inline void* wasm_rt_segue_read_base() {
+ if (wasm_rt_fsgsbase_inst_supported) {
+ return (void*)__builtin_ia32_rdgsbase64();
+ } else {
+ return wasm_rt_syscall_get_segue_base();
+ }
+}
+static inline void wasm_rt_segue_write_base(void* base) {
+ if (wasm_rt_fsgsbase_inst_supported) {
+ __builtin_ia32_wrgsbase64((uintptr_t)base);
+ } else {
+ wasm_rt_syscall_set_segue_base(base);
+ }
+}
#define MEM_ADDR_MEMOP(mem, addr, n) ((uint8_t __seg_gs*)(uintptr_t)addr)
#else
#define MEM_ADDR_MEMOP(mem, addr, n) MEM_ADDR(mem, addr, n)
@@ -202,7 +218,7 @@ static inline bool func_types_eq(const wasm_rt_func_type_t a,
#if WASM_RT_USE_SEGUE && WASM_RT_SANITY_CHECKS
#include <stdio.h>
#define WASM_RT_CHECK_BASE(mem) \
- if (((uintptr_t)((mem)->data)) != ((uintptr_t)WASM_RT_SEGUE_READ_BASE())) { \
+ if (((uintptr_t)((mem)->data)) != ((uintptr_t)wasm_rt_segue_read_base())) { \
puts("Segment register mismatch\n"); \
abort(); \
}
@@ -817,12 +833,12 @@ wasm_rt_memory_t* w2c_test_memory(w2c_test* instance) {
/* export: '_start' */
void w2c_test_0x5Fstart(w2c_test* instance) {
#if WASM_RT_USE_SEGUE
- uintptr_t segue_saved_base = WASM_RT_SEGUE_READ_BASE();
- WASM_RT_SEGUE_WRITE_BASE(instance->w2c_memory.data);
+ void* segue_saved_base = wasm_rt_segue_read_base();
+ wasm_rt_segue_write_base(instance->w2c_memory.data);
#endif
w2c_test_0x5Fstart_0(instance);
#if WASM_RT_USE_SEGUE
- WASM_RT_SEGUE_WRITE_BASE(segue_saved_base);
+ wasm_rt_segue_write_base(segue_saved_base);
#endif
}
@@ -836,13 +852,13 @@ void wasm2c_test_instantiate(w2c_test* instance, struct w2c_wasi__snapshot__prev
init_tables(instance);
init_memories(instance);
#if WASM_RT_USE_SEGUE
- uintptr_t segue_saved_base = WASM_RT_SEGUE_READ_BASE();
- WASM_RT_SEGUE_WRITE_BASE(instance->w2c_memory.data);
+ void* segue_saved_base = wasm_rt_segue_read_base();
+ wasm_rt_segue_write_base(instance->w2c_memory.data);
#endif
init_elem_instances(instance);
init_data_instances(instance);
#if WASM_RT_USE_SEGUE
- WASM_RT_SEGUE_WRITE_BASE(segue_saved_base);
+ wasm_rt_segue_write_base(segue_saved_base);
#endif
}