1 /** 2 * \file wasmtime/memory.h 3 * 4 * Wasmtime API for interacting with wasm memories. 5 */ 6 7 #ifndef WASMTIME_MEMORY_H 8 #define WASMTIME_MEMORY_H 9 10 #include <wasm.h> 11 #include <wasmtime/error.h> 12 #include <wasmtime/extern.h> 13 #include <wasmtime/store.h> 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /** 20 * \brief Creates a new memory type from the specified parameters. 21 * 22 * Note that this function is preferred over #wasm_memorytype_new for 23 * compatibility with the memory64 proposal. 24 */ 25 WASM_API_EXTERN wasm_memorytype_t *wasmtime_memorytype_new(uint64_t min, 26 bool max_present, 27 uint64_t max, 28 bool is_64); 29 30 /** 31 * \brief Returns the minimum size, in pages, of the specified memory type. 32 * 33 * Note that this function is preferred over #wasm_memorytype_limits for 34 * compatibility with the memory64 proposal. 35 */ 36 WASM_API_EXTERN uint64_t 37 wasmtime_memorytype_minimum(const wasm_memorytype_t *ty); 38 39 /** 40 * \brief Returns the maximum size, in pages, of the specified memory type. 41 * 42 * If this memory type doesn't have a maximum size listed then `false` is 43 * returned. Otherwise `true` is returned and the `max` pointer is filled in 44 * with the specified maximum size, in pages. 45 * 46 * Note that this function is preferred over #wasm_memorytype_limits for 47 * compatibility with the memory64 proposal. 48 */ 49 WASM_API_EXTERN bool wasmtime_memorytype_maximum(const wasm_memorytype_t *ty, 50 uint64_t *max); 51 52 /** 53 * \brief Returns whether this type of memory represents a 64-bit memory. 54 */ 55 WASM_API_EXTERN bool wasmtime_memorytype_is64(const wasm_memorytype_t *ty); 56 57 /** 58 * \brief Returns whether this type of memory represents a shared memory. 59 */ 60 WASM_API_EXTERN bool wasmtime_memorytype_isshared(const wasm_memorytype_t *ty); 61 62 /** 63 * \brief Creates a new WebAssembly linear memory 64 * 65 * \param store the store to create the memory within 66 * \param ty the type of the memory to create 67 * \param ret where to store the returned memory 68 * 69 * If an error happens when creating the memory it's returned and owned by the 70 * caller. If an error happens then `ret` is not filled in. 71 */ 72 WASM_API_EXTERN wasmtime_error_t * 73 wasmtime_memory_new(wasmtime_context_t *store, const wasm_memorytype_t *ty, 74 wasmtime_memory_t *ret); 75 76 /** 77 * \brief Returns the type of the memory specified 78 */ 79 WASM_API_EXTERN wasm_memorytype_t * 80 wasmtime_memory_type(const wasmtime_context_t *store, 81 const wasmtime_memory_t *memory); 82 83 /** 84 * \brief Returns the base pointer in memory where the linear memory starts. 85 */ 86 WASM_API_EXTERN uint8_t *wasmtime_memory_data(const wasmtime_context_t *store, 87 const wasmtime_memory_t *memory); 88 89 /** 90 * \brief Returns the byte length of this linear memory. 91 */ 92 WASM_API_EXTERN size_t wasmtime_memory_data_size( 93 const wasmtime_context_t *store, const wasmtime_memory_t *memory); 94 95 /** 96 * \brief Returns the length, in WebAssembly pages, of this linear memory 97 */ 98 WASM_API_EXTERN uint64_t wasmtime_memory_size(const wasmtime_context_t *store, 99 const wasmtime_memory_t *memory); 100 101 /** 102 * \brief Attempts to grow the specified memory by `delta` pages. 103 * 104 * \param store the store that owns `memory` 105 * \param memory the memory to grow 106 * \param delta the number of pages to grow by 107 * \param prev_size where to store the previous size of memory 108 * 109 * If memory cannot be grown then `prev_size` is left unchanged and an error is 110 * returned. Otherwise `prev_size` is set to the previous size of the memory, in 111 * WebAssembly pages, and `NULL` is returned. 112 */ 113 WASM_API_EXTERN wasmtime_error_t * 114 wasmtime_memory_grow(wasmtime_context_t *store, const wasmtime_memory_t *memory, 115 uint64_t delta, uint64_t *prev_size); 116 117 #ifdef __cplusplus 118 } // extern "C" 119 #endif 120 121 #endif // WASMTIME_MEMORY_H 122