1 #include <stdbool.h>
2 #include <stdint.h>
3 #include <stdlib.h>
4 
5 #define CONCAT2(a, b) a##b
6 #define CONCAT(a, b) CONCAT2(a, b)
7 #define VERSIONED_SYMBOL(a) CONCAT(a, VERSIONED_SUFFIX)
8 
9 #ifdef FEATURE_DEBUG_BUILTINS
10 #ifdef CFG_TARGET_OS_windows
11 #define DEBUG_BUILTIN_EXPORT __declspec(dllexport)
12 #else
13 #define DEBUG_BUILTIN_EXPORT
14 #endif
15 
16 // This set of symbols is defined here in C because Rust's #[export_name]
17 // functions are not dllexported on Windows when building an executable. These
18 // symbols are directly referenced by name from the native DWARF info.
19 void *VERSIONED_SYMBOL(resolve_vmctx_memory_ptr)(void *);
20 DEBUG_BUILTIN_EXPORT void *
21 VERSIONED_SYMBOL(wasmtime_resolve_vmctx_memory_ptr)(void *p) {
22   return VERSIONED_SYMBOL(resolve_vmctx_memory_ptr)(p);
23 }
24 void VERSIONED_SYMBOL(set_vmctx_memory)(void *);
25 DEBUG_BUILTIN_EXPORT void VERSIONED_SYMBOL(wasmtime_set_vmctx_memory)(void *p) {
26   VERSIONED_SYMBOL(set_vmctx_memory)(p);
27 }
28 
29 // Helper symbol called from Rust to force the above two functions to not get
30 // stripped by the linker.
31 void VERSIONED_SYMBOL(wasmtime_debug_builtins_init)() {
32 #ifndef CFG_TARGET_OS_windows
33   void *volatile p;
34   p = (void *)&VERSIONED_SYMBOL(wasmtime_resolve_vmctx_memory_ptr);
35   p = (void *)&VERSIONED_SYMBOL(wasmtime_set_vmctx_memory);
36   (void)p;
37 #endif
38 }
39 #endif // FEATURE_DEBUG_BUILTINS
40 
41 // For more information about this see `unix/unwind.rs` and the
42 // `using_libunwind` function. The basic idea is that weak symbols aren't stable
43 // in Rust so we use a bit of C to work around that.
44 #ifndef CFG_TARGET_OS_windows
45 __attribute__((weak)) extern void __unw_add_dynamic_fde();
46 
47 bool VERSIONED_SYMBOL(wasmtime_using_libunwind)() {
48   return __unw_add_dynamic_fde != NULL;
49 }
50 #endif
51