Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/wasm-rt.h
1 /* 2 * Copyright 2018 WebAssembly Community Group participants 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef WASM_RT_H_ 18 #define WASM_RT_H_ 19 20 #include <setjmp.h> 21 #include <stdbool.h> 22 #include <stdint.h> 23 #include <stdlib.h> 24 #include <string.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #ifndef __has_builtin 31 #define __has_builtin(x) 0 /** Compatibility with non-clang compilers. */ 32 #endif 33 34 #if __has_builtin(__builtin_expect) 35 #define UNLIKELY(x) __builtin_expect(!!(x), 0) 36 #define LIKELY(x) __builtin_expect(!!(x), 1) 37 #else 38 #define UNLIKELY(x) (x) 39 #define LIKELY(x) (x) 40 #endif 41 42 #if __has_builtin(__builtin_memcpy) 43 #define wasm_rt_memcpy __builtin_memcpy 44 #else 45 #define wasm_rt_memcpy memcpy 46 #endif 47 48 #if __has_builtin(__builtin_unreachable) 49 #define wasm_rt_unreachable __builtin_unreachable 50 #else 51 #define wasm_rt_unreachable abort 52 #endif 53 54 #ifdef __STDC_VERSION__ 55 #if __STDC_VERSION__ >= 201112L 56 #define WASM_RT_C11_AVAILABLE 57 #endif 58 #endif 59 60 /** 61 * Many devices don't implement the C11 threads.h. We use CriticalSection APIs 62 * for Windows and pthreads on other platforms where threads are not available. 63 */ 64 #ifdef WASM_RT_C11_AVAILABLE 65 66 #if defined(_WIN32) 67 #include <windows.h> 68 #define WASM_RT_MUTEX CRITICAL_SECTION 69 #define WASM_RT_USE_CRITICALSECTION 1 70 #elif defined(__APPLE__) || defined(__STDC_NO_THREADS__) 71 #include <pthread.h> 72 #define WASM_RT_MUTEX pthread_mutex_t 73 #define WASM_RT_USE_PTHREADS 1 74 #else 75 #include <threads.h> 76 #define WASM_RT_MUTEX mtx_t 77 #define WASM_RT_USE_C11THREADS 1 78 #endif 79 80 #endif 81 82 #ifdef _MSC_VER 83 #define WASM_RT_THREAD_LOCAL __declspec(thread) 84 #elif defined(WASM_RT_C11_AVAILABLE) 85 #define WASM_RT_THREAD_LOCAL _Thread_local 86 #else 87 #define WASM_RT_THREAD_LOCAL 88 #endif 89 90 /** 91 * If enabled, perform additional sanity checks in the generated wasm2c code and 92 * wasm2c runtime. This is useful to enable on debug builds. 93 */ 94 #ifndef WASM_RT_SANITY_CHECKS 95 #define WASM_RT_SANITY_CHECKS 0 96 #endif 97 98 /** 99 * Backward compatibility: Convert the previously exposed 100 * WASM_RT_MEMCHECK_SIGNAL_HANDLER macro to the ALLOCATION and CHECK macros that 101 * are now used. 102 */ 103 #if defined(WASM_RT_MEMCHECK_SIGNAL_HANDLER) 104 105 #if WASM_RT_MEMCHECK_SIGNAL_HANDLER 106 #define WASM_RT_USE_MMAP 1 107 #define WASM_RT_MEMCHECK_GUARD_PAGES 1 108 #else 109 #define WASM_RT_USE_MMAP 0 110 #define WASM_RT_MEMCHECK_BOUNDS_CHECK 1 111 #endif 112 113 #warning \ 114 "WASM_RT_MEMCHECK_SIGNAL_HANDLER has been deprecated in favor of WASM_RT_USE_MMAP and WASM_RT_MEMORY_CHECK_* macros" 115 #endif 116 117 /** 118 * Specify if we use OR mmap/mprotect (+ Windows equivalents) OR malloc/realloc 119 * for the Wasm memory allocation and growth. mmap/mprotect guarantees memory 120 * will grow without being moved, while malloc ensures the virtual memory is 121 * consumed only as needed, but may relocate the memory to handle memory 122 * fragmentation. 123 * 124 * This defaults to malloc on 32-bit platforms or if memory64 support is needed. 125 * It defaults to mmap on 64-bit platforms assuming memory64 support is not 126 * needed (so we can use the guard based range checks below). 127 */ 128 #ifndef WASM_RT_USE_MMAP 129 #if UINTPTR_MAX > 0xffffffff && !SUPPORT_MEMORY64 130 #define WASM_RT_USE_MMAP 1 131 #else 132 #define WASM_RT_USE_MMAP 0 133 #endif 134 #endif 135 136 /** 137 * Set the range checking strategy for Wasm memories. 138 * 139 * GUARD_PAGES: memory accesses rely on unmapped pages/guard pages to trap 140 * out-of-bound accesses. 141 * 142 * BOUNDS_CHECK: memory accesses are checked with explicit bounds checks. 143 * 144 * This defaults to GUARD_PAGES as this is the fasest option, iff the 145 * requirements of GUARD_PAGES --- 64-bit platforms, MMAP allocation strategy, 146 * no 64-bit memories, no big-endian --- are met. This falls back to BOUNDS 147 * otherwise. 148 */ 149 150 /** Check if Guard checks are supported */ 151 #if UINTPTR_MAX > 0xffffffff && WASM_RT_USE_MMAP && !SUPPORT_MEMORY64 && \ 152 !WABT_BIG_ENDIAN 153 #define WASM_RT_GUARD_PAGES_SUPPORTED 1 154 #else 155 #define WASM_RT_GUARD_PAGES_SUPPORTED 0 156 #endif 157 158 /** Specify defaults for memory checks if unspecified */ 159 #if !defined(WASM_RT_MEMCHECK_GUARD_PAGES) && \ 160 !defined(WASM_RT_MEMCHECK_BOUNDS_CHECK) 161 #if WASM_RT_GUARD_PAGES_SUPPORTED 162 #define WASM_RT_MEMCHECK_GUARD_PAGES 1 163 #else 164 #define WASM_RT_MEMCHECK_BOUNDS_CHECK 1 165 #endif 166 #endif 167 168 /** Ensure the macros are defined */ 169 #ifndef WASM_RT_MEMCHECK_GUARD_PAGES 170 #define WASM_RT_MEMCHECK_GUARD_PAGES 0 171 #endif 172 #ifndef WASM_RT_MEMCHECK_BOUNDS_CHECK 173 #define WASM_RT_MEMCHECK_BOUNDS_CHECK 0 174 #endif 175 176 /** Sanity check the use of guard pages */ 177 #if WASM_RT_MEMCHECK_GUARD_PAGES && !WASM_RT_GUARD_PAGES_SUPPORTED 178 #error \ 179 "WASM_RT_MEMCHECK_GUARD_PAGES not supported on this platform/configuration" 180 #endif 181 182 #if WASM_RT_MEMCHECK_GUARD_PAGES && WASM_RT_MEMCHECK_BOUNDS_CHECK 183 #error \ 184 "Cannot use both WASM_RT_MEMCHECK_GUARD_PAGES and WASM_RT_MEMCHECK_BOUNDS_CHECK" 185 186 #elif !WASM_RT_MEMCHECK_GUARD_PAGES && !WASM_RT_MEMCHECK_BOUNDS_CHECK 187 #error \ 188 "Must choose at least one from WASM_RT_MEMCHECK_GUARD_PAGES and WASM_RT_MEMCHECK_BOUNDS_CHECK" 189 #endif 190 191 /** 192 * Some configurations above require the Wasm runtime to install a signal 193 * handler. However, this can be explicitly disallowed by the host using 194 * WASM_RT_SKIP_SIGNAL_RECOVERY. In this case, when the wasm code encounters an 195 * OOB access, it may either trap or abort. 196 */ 197 #ifndef WASM_RT_SKIP_SIGNAL_RECOVERY 198 #define WASM_RT_SKIP_SIGNAL_RECOVERY 0 199 #endif 200 201 #if WASM_RT_MEMCHECK_GUARD_PAGES && !WASM_RT_SKIP_SIGNAL_RECOVERY 202 #define WASM_RT_INSTALL_SIGNAL_HANDLER 1 203 #else 204 #define WASM_RT_INSTALL_SIGNAL_HANDLER 0 205 #endif 206 207 /** 208 * This macro, if defined to 1 (i.e., allows the "segue" optimization), allows 209 * Wasm2c to use segment registers to speedup access to the linear heap. Note 210 * that even if allowed in this way, the segment registers would only be used if 211 * Wasm2c output is compiled for a suitable architecture and OS and the produces 212 * C file is compiled by supported compilers. The extact restrictions are listed 213 * in detail in src/template/wasm2c.declarations.c 214 */ 215 #ifndef WASM_RT_ALLOW_SEGUE 216 #define WASM_RT_ALLOW_SEGUE 0 217 #endif 218 219 /** 220 * This macro, if defined, allows the embedder to disable all stack exhaustion 221 * checks. This a non conformant configuration, i.e., this does not respect 222 * Wasm's specification, and may compromise security. Use with caution. 223 */ 224 #ifndef WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION 225 #define WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION 0 226 #endif 227 228 /** 229 * We need to detect and trap stack overflows. If we use a signal handler on 230 * POSIX systems, this can detect call stack overflows. On windows, or platforms 231 * without a signal handler, we use stack depth counting. 232 */ 233 #if !defined(WASM_RT_STACK_DEPTH_COUNT) && \ 234 !defined(WASM_RT_STACK_EXHAUSTION_HANDLER) && \ 235 !WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION 236 237 #if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32) 238 #define WASM_RT_STACK_EXHAUSTION_HANDLER 1 239 #else 240 #define WASM_RT_STACK_DEPTH_COUNT 1 241 #endif 242 243 #endif 244 245 /** Ensure the stack macros are defined */ 246 #ifndef WASM_RT_STACK_DEPTH_COUNT 247 #define WASM_RT_STACK_DEPTH_COUNT 0 248 #endif 249 #ifndef WASM_RT_STACK_EXHAUSTION_HANDLER 250 #define WASM_RT_STACK_EXHAUSTION_HANDLER 0 251 #endif 252 253 #if WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION 254 255 #if (WASM_RT_STACK_EXHAUSTION_HANDLER + WASM_RT_STACK_DEPTH_COUNT) != 0 256 #error \ 257 "Cannot specify WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION along with WASM_RT_STACK_EXHAUSTION_HANDLER or WASM_RT_STACK_DEPTH_COUNT" 258 #endif 259 260 #else 261 262 #if (WASM_RT_STACK_EXHAUSTION_HANDLER + WASM_RT_STACK_DEPTH_COUNT) > 1 263 #error \ 264 "Cannot specify multiple options from WASM_RT_STACK_EXHAUSTION_HANDLER , WASM_RT_STACK_DEPTH_COUNT" 265 #elif (WASM_RT_STACK_EXHAUSTION_HANDLER + WASM_RT_STACK_DEPTH_COUNT) == 0 266 #error \ 267 "Must specify one of WASM_RT_STACK_EXHAUSTION_HANDLER , WASM_RT_STACK_DEPTH_COUNT" 268 #endif 269 270 #endif 271 272 #if WASM_RT_STACK_EXHAUSTION_HANDLER && !WASM_RT_INSTALL_SIGNAL_HANDLER 273 #error \ 274 "WASM_RT_STACK_EXHAUSTION_HANDLER can only be used if WASM_RT_INSTALL_SIGNAL_HANDLER is enabled" 275 #endif 276 277 #if WASM_RT_STACK_DEPTH_COUNT 278 /** 279 * When the signal handler cannot be used to detect stack overflows, stack depth 280 * is limited explicitly. The maximum stack depth before trapping can be 281 * configured by defining this symbol before including wasm-rt when building the 282 * generated c files, for example: 283 * 284 * ``` 285 * cc -c -DWASM_RT_MAX_CALL_STACK_DEPTH=100 my_module.c -o my_module.o 286 * ``` 287 */ 288 #ifndef WASM_RT_MAX_CALL_STACK_DEPTH 289 #define WASM_RT_MAX_CALL_STACK_DEPTH 500 290 #endif 291 292 /** Current call stack depth. */ 293 extern WASM_RT_THREAD_LOCAL uint32_t wasm_rt_call_stack_depth; 294 295 #endif 296 297 #if defined(_MSC_VER) 298 #define WASM_RT_NO_RETURN __declspec(noreturn) 299 #else 300 #define WASM_RT_NO_RETURN __attribute__((noreturn)) 301 #endif 302 303 #if defined(__APPLE__) && WASM_RT_STACK_EXHAUSTION_HANDLER 304 #define WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS 1 305 #else 306 #define WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS 0 307 #endif 308 309 /** Reason a trap occurred. Provide this to `wasm_rt_trap`. */ 310 typedef enum { 311 WASM_RT_TRAP_NONE, /** No error. */ 312 WASM_RT_TRAP_OOB, /** Out-of-bounds access in linear memory or a table. */ 313 WASM_RT_TRAP_INT_OVERFLOW, /** Integer overflow on divide or truncation. */ 314 WASM_RT_TRAP_DIV_BY_ZERO, /** Integer divide by zero. */ 315 WASM_RT_TRAP_INVALID_CONVERSION, /** Conversion from NaN to integer. */ 316 WASM_RT_TRAP_UNREACHABLE, /** Unreachable instruction executed. */ 317 WASM_RT_TRAP_CALL_INDIRECT, /** Invalid call_indirect, for any reason. */ 318 WASM_RT_TRAP_UNCAUGHT_EXCEPTION, /** Exception thrown and not caught. */ 319 WASM_RT_TRAP_UNALIGNED, /** Unaligned atomic instruction executed. */ 320 #if WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS 321 WASM_RT_TRAP_EXHAUSTION = WASM_RT_TRAP_OOB, 322 #else 323 WASM_RT_TRAP_EXHAUSTION, /** Call stack exhausted. */ 324 #endif 325 } wasm_rt_trap_t; 326 327 /** Value types. Used to define function signatures. */ 328 typedef enum { 329 WASM_RT_I32, 330 WASM_RT_I64, 331 WASM_RT_F32, 332 WASM_RT_F64, 333 WASM_RT_V128, 334 WASM_RT_FUNCREF, 335 WASM_RT_EXTERNREF, 336 } wasm_rt_type_t; 337 338 /** 339 * A generic function pointer type, both for Wasm functions (`code`) 340 * and host functions (`hostcode`). All function pointers are stored 341 * in this canonical form, but must be cast to their proper signature 342 * to call. 343 */ 344 typedef void (*wasm_rt_function_ptr_t)(void); 345 346 /** 347 * A pointer to a "tail-callee" function, called by a tail-call 348 * trampoline or by another tail-callee function. (The definition uses a 349 * single-member struct to allow a recursive definition.) 350 */ 351 typedef struct wasm_rt_tailcallee_t { 352 void (*fn)(void** instance_ptr, 353 void* tail_call_stack, 354 struct wasm_rt_tailcallee_t* next); 355 } wasm_rt_tailcallee_t; 356 357 /** 358 * The type of a function (an arbitrary number of param and result types). 359 * This is represented as an opaque 256-bit ID. 360 */ 361 typedef const char* wasm_rt_func_type_t; 362 363 /** 364 * A function instance (the runtime representation of a function). 365 * These can be stored in tables of type funcref, or used as values. 366 */ 367 typedef struct { 368 /** The function's type. */ 369 wasm_rt_func_type_t func_type; 370 /** 371 * The function. The embedder must know the actual C signature of the function 372 * and cast to it before calling. 373 */ 374 wasm_rt_function_ptr_t func; 375 /** An alternate version of the function to be used when tail-called. */ 376 wasm_rt_tailcallee_t func_tailcallee; 377 /** 378 * A function instance is a closure of the function over an instance 379 * of the originating module. The module_instance element will be passed into 380 * the function at runtime. 381 */ 382 void* module_instance; 383 } wasm_rt_funcref_t; 384 385 /** Default (null) value of a funcref */ 386 #define wasm_rt_funcref_null_value \ 387 ((wasm_rt_funcref_t){NULL, NULL, {NULL}, NULL}) 388 389 /** The type of an external reference (opaque to WebAssembly). */ 390 typedef void* wasm_rt_externref_t; 391 392 /** Default (null) value of an externref */ 393 #define wasm_rt_externref_null_value ((wasm_rt_externref_t){NULL}) 394 395 /** A Memory object. */ 396 typedef struct { 397 /** The linear memory data, with a byte length of `size`. */ 398 uint8_t* data; 399 /** The current page count for this Memory object. */ 400 uint64_t pages; 401 /** 402 * The maximum page count for this Memory object. If there is no maximum, 403 * `max_pages` is 0xffffffffu (i.e. UINT32_MAX). 404 */ 405 uint64_t max_pages; 406 /** The current size of the linear memory, in bytes. */ 407 uint64_t size; 408 /** Is this memory indexed by u64 (as opposed to default u32) */ 409 bool is64; 410 } wasm_rt_memory_t; 411 412 #ifdef WASM_RT_C11_AVAILABLE 413 /** A shared Memory object. */ 414 typedef struct { 415 /** 416 * The linear memory data, with a byte length of `size`. The memory is marked 417 * atomic as it is shared and may have to be accessed with different memory 418 * orders --- sequential when being accessed atomically, relaxed otherwise. 419 * Unfortunately, the C standard does not state what happens if there are 420 * overlaps in two memory accesses which have a memory order, e.g., an 421 * atomic32 being read from the same location an atomic64 is read. One way to 422 * prevent optimizations from assuming non-overlapping behavior as typically 423 * done in C is to mark the memory as volatile. Thus the memory is atomic and 424 * volatile. 425 */ 426 _Atomic volatile uint8_t* data; 427 /** The current page count for this Memory object. */ 428 uint64_t pages; 429 /** 430 * The maximum page count for this Memory object. If there is no maximum, 431 * `max_pages` is 0xffffffffu (i.e. UINT32_MAX). 432 */ 433 uint64_t max_pages; 434 /** The current size of the linear memory, in bytes. */ 435 uint64_t size; 436 /** Is this memory indexed by u64 (as opposed to default u32) */ 437 bool is64; 438 /** Lock used to ensure operations such as memory grow are threadsafe */ 439 WASM_RT_MUTEX mem_lock; 440 } wasm_rt_shared_memory_t; 441 #endif 442 443 /** A Table of type funcref. */ 444 typedef struct { 445 /** The table element data, with an element count of `size`. */ 446 wasm_rt_funcref_t* data; 447 /** 448 * The maximum element count of this Table object. If there is no maximum, 449 * `max_size` is 0xffffffffu (i.e. UINT32_MAX). 450 */ 451 uint32_t max_size; 452 /** The current element count of the table. */ 453 uint32_t size; 454 } wasm_rt_funcref_table_t; 455 456 /** A Table of type externref. */ 457 typedef struct { 458 /** The table element data, with an element count of `size`. */ 459 wasm_rt_externref_t* data; 460 /** 461 * The maximum element count of this Table object. If there is no maximum, 462 * `max_size` is 0xffffffffu (i.e. UINT32_MAX). 463 */ 464 uint32_t max_size; 465 /** The current element count of the table. */ 466 uint32_t size; 467 } wasm_rt_externref_table_t; 468 469 /** Initialize the runtime. */ 470 void wasm_rt_init(void); 471 472 /** Is the runtime initialized? */ 473 bool wasm_rt_is_initialized(void); 474 475 /** Free the runtime's state. */ 476 void wasm_rt_free(void); 477 478 /* 479 * Initialize the multithreaded runtime for a given thread. Must be 480 * called by each thread (other than the one that called wasm_rt_init) 481 * before initializing a Wasm module or calling an exported 482 * function. 483 */ 484 void wasm_rt_init_thread(void); 485 486 /* 487 * Free the individual thread's state. 488 */ 489 void wasm_rt_free_thread(void); 490 491 /** A hardened jmp_buf that allows checking for initialization before use */ 492 typedef struct { 493 /** Is the jmp buf intialized? */ 494 bool initialized; 495 /** jmp_buf contents */ 496 jmp_buf buffer; 497 } wasm_rt_jmp_buf; 498 499 #ifndef _WIN32 500 #define WASM_RT_SETJMP_SETBUF(buf) sigsetjmp(buf, 1) 501 #else 502 #define WASM_RT_SETJMP_SETBUF(buf) setjmp(buf) 503 #endif 504 505 #define WASM_RT_SETJMP(buf) \ 506 ((buf).initialized = true, WASM_RT_SETJMP_SETBUF((buf).buffer)) 507 508 #ifndef _WIN32 509 #define WASM_RT_LONGJMP_UNCHECKED(buf, val) siglongjmp(buf, val) 510 #else 511 #define WASM_RT_LONGJMP_UNCHECKED(buf, val) longjmp(buf, val) 512 #endif 513 514 #define WASM_RT_LONGJMP(buf, val) \ 515 /** Abort on failure as this may be called in the trap handler */ \ 516 if (!((buf).initialized)) \ 517 abort(); \ 518 (buf).initialized = false; \ 519 WASM_RT_LONGJMP_UNCHECKED((buf).buffer, val) 520 521 /** 522 * Stop execution immediately and jump back to the call to `wasm_rt_impl_try`. 523 * The result of `wasm_rt_impl_try` will be the provided trap reason. 524 * 525 * This is typically called by the generated code, and not the embedder. 526 */ 527 WASM_RT_NO_RETURN void wasm_rt_trap(wasm_rt_trap_t); 528 529 /** Return a human readable error string based on a trap type. */ 530 const char* wasm_rt_strerror(wasm_rt_trap_t trap); 531 532 #define wasm_rt_try(target) WASM_RT_SETJMP(target) 533 534 /** 535 * Initialize a Memory object with an initial page size of `initial_pages` and 536 * a maximum page size of `max_pages`, indexed with an i32 or i64. 537 * 538 * ``` 539 * wasm_rt_memory_t my_memory; 540 * // 1 initial page (65536 bytes), and a maximum of 2 pages, 541 * // indexed with an i32 542 * wasm_rt_allocate_memory(&my_memory, 1, 2, false); 543 * ``` 544 */ 545 void wasm_rt_allocate_memory(wasm_rt_memory_t*, 546 uint64_t initial_pages, 547 uint64_t max_pages, 548 bool is64); 549 550 /** 551 * Grow a Memory object by `pages`, and return the previous page count. If 552 * this new page count is greater than the maximum page count, the grow fails 553 * and 0xffffffffu (UINT32_MAX) is returned instead. 554 * 555 * ``` 556 * wasm_rt_memory_t my_memory; 557 * ... 558 * // Grow memory by 10 pages. 559 * uint32_t old_page_size = wasm_rt_grow_memory(&my_memory, 10); 560 * if (old_page_size == UINT32_MAX) { 561 * // Failed to grow memory. 562 * } 563 * ``` 564 */ 565 uint64_t wasm_rt_grow_memory(wasm_rt_memory_t*, uint64_t pages); 566 567 /** Free a Memory object. */ 568 void wasm_rt_free_memory(wasm_rt_memory_t*); 569 570 #ifdef WASM_RT_C11_AVAILABLE 571 /** Shared memory version of wasm_rt_allocate_memory */ 572 void wasm_rt_allocate_memory_shared(wasm_rt_shared_memory_t*, 573 uint64_t initial_pages, 574 uint64_t max_pages, 575 bool is64); 576 577 /** Shared memory version of wasm_rt_grow_memory */ 578 uint64_t wasm_rt_grow_memory_shared(wasm_rt_shared_memory_t*, uint64_t pages); 579 580 /** Shared memory version of wasm_rt_free_memory */ 581 void wasm_rt_free_memory_shared(wasm_rt_shared_memory_t*); 582 #endif 583 584 /** 585 * Initialize a funcref Table object with an element count of `elements` and a 586 * maximum size of `max_elements`. 587 * 588 * ``` 589 * wasm_rt_funcref_table_t my_table; 590 * // 5 elements and a maximum of 10 elements. 591 * wasm_rt_allocate_funcref_table(&my_table, 5, 10); 592 * ``` 593 */ 594 void wasm_rt_allocate_funcref_table(wasm_rt_funcref_table_t*, 595 uint32_t elements, 596 uint32_t max_elements); 597 598 /** Free a funcref Table object. */ 599 void wasm_rt_free_funcref_table(wasm_rt_funcref_table_t*); 600 601 /** 602 * Initialize an externref Table object with an element count 603 * of `elements` and a maximum size of `max_elements`. 604 * Usage as per wasm_rt_allocate_funcref_table. 605 */ 606 void wasm_rt_allocate_externref_table(wasm_rt_externref_table_t*, 607 uint32_t elements, 608 uint32_t max_elements); 609 610 /** Free an externref Table object. */ 611 void wasm_rt_free_externref_table(wasm_rt_externref_table_t*); 612 613 /** 614 * Grow a Table object by `delta` elements (giving the new elements the value 615 * `init`), and return the previous element count. If this new element count is 616 * greater than the maximum element count, the grow fails and 0xffffffffu 617 * (UINT32_MAX) is returned instead. 618 */ 619 uint32_t wasm_rt_grow_funcref_table(wasm_rt_funcref_table_t*, 620 uint32_t delta, 621 wasm_rt_funcref_t init); 622 uint32_t wasm_rt_grow_externref_table(wasm_rt_externref_table_t*, 623 uint32_t delta, 624 wasm_rt_externref_t init); 625 626 #ifdef __cplusplus 627 } 628 #endif 629 630 #endif /* WASM_RT_H_ */