/** Ensure the macros are defined */ #ifndef WASM_RT_MEMCHECK_GUARD_PAGES #define WASM_RT_MEMCHECK_GUARD_PAGES 0 #endif #ifndef WASM_RT_MEMCHECK_BOUNDS_CHECK #define WASM_RT_MEMCHECK_BOUNDS_CHECK 0 #endif
/** Sanity check the use of guard pages */ #if WASM_RT_MEMCHECK_GUARD_PAGES && !WASM_RT_GUARD_PAGES_SUPPORTED #error \ "WASM_RT_MEMCHECK_GUARD_PAGES not supported on this platform/configuration" #endif
#if WASM_RT_MEMCHECK_GUARD_PAGES && WASM_RT_MEMCHECK_BOUNDS_CHECK #error \ "Cannot use both WASM_RT_MEMCHECK_GUARD_PAGES and WASM_RT_MEMCHECK_BOUNDS_CHECK"
#elif !WASM_RT_MEMCHECK_GUARD_PAGES && !WASM_RT_MEMCHECK_BOUNDS_CHECK #error \ "Must choose at least one from WASM_RT_MEMCHECK_GUARD_PAGES and WASM_RT_MEMCHECK_BOUNDS_CHECK" #endif
#ifndef WASM_RT_USE_SEGUE // Memory functions can use the segue optimization if allowed. The segue // optimization uses x86 segments to point to a linear memory. We use this // optimization when: // // (1) Segue is allowed using WASM_RT_ALLOW_SEGUE // (2) on x86_64 without WABT_BIG_ENDIAN enabled // (3) the compiler supports: intrinsics for (rd|wr)gsbase, "address namespaces" // for accessing pointers, and supports memcpy on pointers with custom // "address namespaces". GCC does not support the memcpy requirement, so // this leaves only clang (version 9 or later) for now. // (4) 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. // (5) 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)) && __clang__ && \
(__clang_major__ >= 9) && __has_builtin(__builtin_ia32_wrgsbase64) && \
!defined(_WIN32) && defined(__linux__) #define WASM_RT_USE_SEGUE 1 #else #define WASM_RT_USE_SEGUE 0 #endif #endif
#if WASM_RT_STACK_EXHAUSTION_HANDLER && !WASM_RT_INSTALL_SIGNAL_HANDLER #error \ "WASM_RT_STACK_EXHAUSTION_HANDLER can only be used if WASM_RT_INSTALL_SIGNAL_HANDLER is enabled" #endif
/** Reason a trap occurred. Provide this to `wasm_rt_trap`. */ typedefenum {
WASM_RT_TRAP_NONE, /** No error. */
WASM_RT_TRAP_OOB, /** Out-of-bounds access in linear memory or a table. */
WASM_RT_TRAP_INT_OVERFLOW, /** Integer overflow on divide or truncation. */
WASM_RT_TRAP_DIV_BY_ZERO, /** Integer divide by zero. */
WASM_RT_TRAP_INVALID_CONVERSION, /** Conversion from NaN to integer. */
WASM_RT_TRAP_UNREACHABLE, /** Unreachable instruction executed. */
WASM_RT_TRAP_CALL_INDIRECT, /** Invalid call_indirect, for any reason. */
WASM_RT_TRAP_UNCAUGHT_EXCEPTION, /** Exception thrown and not caught. */
WASM_RT_TRAP_UNALIGNED, /** Unaligned atomic instruction executed. */ #if WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS
WASM_RT_TRAP_EXHAUSTION = WASM_RT_TRAP_OOB, #else
WASM_RT_TRAP_EXHAUSTION, /** Call stack exhausted. */ #endif
} wasm_rt_trap_t;
/** Value types. Used to define function signatures. */ typedefenum {
WASM_RT_I32,
WASM_RT_I64,
WASM_RT_F32,
WASM_RT_F64,
WASM_RT_V128,
WASM_RT_FUNCREF,
WASM_RT_EXTERNREF,
} wasm_rt_type_t;
/** *Afunctioninstance(theruntimerepresentationofafunction). *Thesecanbestoredintablesoftypefuncref,orusedasvalues.
*/ typedefstruct { /** The function's type. */
wasm_rt_func_type_t func_type; /** *Thefunction.TheembeddermustknowtheactualCsignatureofthefunction *andcasttoitbeforecalling.
*/
wasm_rt_function_ptr_t func; /** An alternate version of the function to be used when tail-called. */
wasm_rt_tailcallee_t func_tailcallee; /** *Afunctioninstanceisaclosureofthefunctionoveraninstance *oftheoriginatingmodule.Themodule_instanceelementwillbepassedinto *thefunctionatruntime.
*/ void* module_instance;
} wasm_rt_funcref_t;
/** Default (null) value of a funcref */ #define wasm_rt_funcref_null_value \
((wasm_rt_funcref_t){NULL, NULL, {NULL}, NULL})
/** The type of an external reference (opaque to WebAssembly). */ typedefvoid* wasm_rt_externref_t;
/** Default (null) value of an externref */ #define wasm_rt_externref_null_value ((wasm_rt_externref_t){NULL})
/** A Memory object. */ typedefstruct { /** The linear memory data, with a byte length of `size`. */
uint8_t* data; /** The current page count for this Memory object. */
uint64_t pages; /** *ThemaximumpagecountforthisMemoryobject.Ifthereisnomaximum, *`max_pages`is0xffffffffu(i.e.UINT32_MAX).
*/
uint64_t max_pages; /** The current size of the linear memory, in bytes. */
uint64_t size; /** Is this memory indexed by u64 (as opposed to default u32) */ bool is64;
} wasm_rt_memory_t;
#ifdef WASM_RT_C11_AVAILABLE /** A shared Memory object. */ typedefstruct { /** *Thelinearmemorydata,withabytelengthof`size`.Thememoryismarked *atomicasitissharedandmayhavetobeaccessedwithdifferentmemory *orders---sequentialwhenbeingaccessedatomically,relaxedotherwise. *Unfortunately,theCstandarddoesnotstatewhathappensifthereare *overlapsintwomemoryaccesseswhichhaveamemoryorder,e.g.,an *atomic32beingreadfromthesamelocationanatomic64isread.Onewayto *preventoptimizationsfromassumingnon-overlappingbehaviorastypically *doneinCistomarkthememoryasvolatile.Thusthememoryisatomicand *volatile.
*/
_Atomic volatile uint8_t* data; /** The current page count for this Memory object. */
uint64_t pages; /** *ThemaximumpagecountforthisMemoryobject.Ifthereisnomaximum, *`max_pages`is0xffffffffu(i.e.UINT32_MAX).
*/
uint64_t max_pages; /** The current size of the linear memory, in bytes. */
uint64_t size; /** Is this memory indexed by u64 (as opposed to default u32) */ bool is64; /** Lock used to ensure operations such as memory grow are threadsafe */
WASM_RT_MUTEX mem_lock;
} wasm_rt_shared_memory_t; #endif
/** A Table of type funcref. */ typedefstruct { /** The table element data, with an element count of `size`. */
wasm_rt_funcref_t* data; /** *ThemaximumelementcountofthisTableobject.Ifthereisnomaximum, *`max_size`is0xffffffffu(i.e.UINT32_MAX).
*/
uint32_t max_size; /** The current element count of the table. */
uint32_t size;
} wasm_rt_funcref_table_t;
/** A Table of type externref. */ typedefstruct { /** The table element data, with an element count of `size`. */
wasm_rt_externref_t* data; /** *ThemaximumelementcountofthisTableobject.Ifthereisnomaximum, *`max_size`is0xffffffffu(i.e.UINT32_MAX).
*/
uint32_t max_size; /** The current element count of the table. */
uint32_t size;
} wasm_rt_externref_table_t;
/** Initialize the runtime. */ void wasm_rt_init(void);
/** Is the runtime initialized? */ bool wasm_rt_is_initialized(void);
/** Free the runtime's state. */ void wasm_rt_free(void);
/** A hardened jmp_buf that allows checking for initialization before use */ typedefstruct { /** Is the jmp buf intialized? */ bool initialized; /** jmp_buf contents */
jmp_buf buffer;
} wasm_rt_jmp_buf;
#define WASM_RT_LONGJMP(buf, val) \ /** Abort on failure as this may be called in the trap handler */ \ if (!((buf).initialized)) \
abort(); \
(buf).initialized = false; \
WASM_RT_LONGJMP_UNCHECKED((buf).buffer, val)
/** Free a Memory object. */ void wasm_rt_free_memory(wasm_rt_memory_t*);
#ifdef WASM_RT_C11_AVAILABLE /** Shared memory version of wasm_rt_allocate_memory */ void wasm_rt_allocate_memory_shared(wasm_rt_shared_memory_t*,
uint64_t initial_pages,
uint64_t max_pages, bool is64);
/** Shared memory version of wasm_rt_grow_memory */
uint64_t wasm_rt_grow_memory_shared(wasm_rt_shared_memory_t*, uint64_t pages);
/** Shared memory version of wasm_rt_free_memory */ void wasm_rt_free_memory_shared(wasm_rt_shared_memory_t*); #endif
/** *InitializeafuncrefTableobjectwithanelementcountof`elements`anda *maximumsizeof`max_elements`. * *``` *wasm_rt_funcref_table_tmy_table; *// 5 elements and a maximum of 10 elements. *wasm_rt_allocate_funcref_table(&my_table,5,10); *```
*/ void wasm_rt_allocate_funcref_table(wasm_rt_funcref_table_t*,
uint32_t elements,
uint32_t max_elements);
/** Free a funcref Table object. */ void wasm_rt_free_funcref_table(wasm_rt_funcref_table_t*);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.