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 Creates a new WebAssembly linear memory 59 * 60 * \param store the store to create the memory within 61 * \param ty the type of the memory to create 62 * \param ret where to store the returned memory 63 * 64 * If an error happens when creating the memory it's returned and owned by the 65 * caller. If an error happens then `ret` is not filled in. 66 */ 67 WASM_API_EXTERN wasmtime_error_t * 68 wasmtime_memory_new(wasmtime_context_t *store, const wasm_memorytype_t *ty, 69 wasmtime_memory_t *ret); 70 71 /** 72 * \brief Returns the type of the memory specified 73 */ 74 WASM_API_EXTERN wasm_memorytype_t * 75 wasmtime_memory_type(const wasmtime_context_t *store, 76 const wasmtime_memory_t *memory); 77 78 /** 79 * \brief Returns the base pointer in memory where the linear memory starts. 80 */ 81 WASM_API_EXTERN uint8_t *wasmtime_memory_data(const wasmtime_context_t *store, 82 const wasmtime_memory_t *memory); 83 84 /** 85 * \brief Returns the byte length of this linear memory. 86 */ 87 WASM_API_EXTERN size_t wasmtime_memory_data_size( 88 const wasmtime_context_t *store, const wasmtime_memory_t *memory); 89 90 /** 91 * \brief Returns the length, in WebAssembly pages, of this linear memory 92 */ 93 WASM_API_EXTERN uint64_t wasmtime_memory_size(const wasmtime_context_t *store, 94 const wasmtime_memory_t *memory); 95 96 /** 97 * \brief Attempts to grow the specified memory by `delta` pages. 98 * 99 * \param store the store that owns `memory` 100 * \param memory the memory to grow 101 * \param delta the number of pages to grow by 102 * \param prev_size where to store the previous size of memory 103 * 104 * If memory cannot be grown then `prev_size` is left unchanged and an error is 105 * returned. Otherwise `prev_size` is set to the previous size of the memory, in 106 * WebAssembly pages, and `NULL` is returned. 107 */ 108 WASM_API_EXTERN wasmtime_error_t * 109 wasmtime_memory_grow(wasmtime_context_t *store, const wasmtime_memory_t *memory, 110 uint64_t delta, uint64_t *prev_size); 111 112 #ifdef __cplusplus 113 } // extern "C" 114 #endif 115 116 #endif // WASMTIME_MEMORY_H 117