| 1 |
/** |
| 2 |
* \file wasm-tools.h |
| 3 |
* |
| 4 |
* C API for wasm-tools |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef WASM_TOOLS_H |
| 8 |
#define WASM_TOOLS_H |
| 9 |
|
| 10 |
#include <stdint.h> |
| 11 |
|
| 12 |
#ifdef __cplusplus |
| 13 |
extern "C" { |
| 14 |
#endif |
| 15 |
|
| 16 |
/** |
| 17 |
* \struct wasm_tools_byte_vec_t |
| 18 |
* \brief A list of bytes |
| 19 |
* |
| 20 |
* Used to pass data in or pass data out of various functions. The meaning and |
| 21 |
* ownership of the bytes is defined by each API that operates on this |
| 22 |
* datatype. |
| 23 |
* |
| 24 |
* \var wasm_tools_byte_vec_t::size |
| 25 |
* \brief Length of this vector. |
| 26 |
* |
| 27 |
* \var wasm_tools_byte_vec_t::data |
| 28 |
* \brief Pointer to the base of this vector |
| 29 |
* |
| 30 |
* \fn void wasm_tools_byte_vec_delete(wasm_tools_byte_vec_t *); |
| 31 |
* \brief Deletes a byte vector. |
| 32 |
* |
| 33 |
* This function will deallocate the data referenced by the argument provided. |
| 34 |
* This does not deallocate the memory holding the #wasm_tools_byte_vec_t itself, it's |
| 35 |
* expected that memory is owned by the caller. |
| 36 |
*/ |
| 37 |
struct wasm_tools_byte_vec_t { |
| 38 |
uint8_t* data; |
| 39 |
size_t size; |
| 40 |
}; |
| 41 |
|
| 42 |
/** |
| 43 |
* \enum wasm_tools_error |
| 44 |
* \brief Errors return by functions |
| 45 |
*/ |
| 46 |
enum wasm_tools_error { |
| 47 |
WASM_TOOLS_SUCCESS = 0, ///< success |
| 48 |
WASM_TOOLS_ERROR = -1, ///< generic error |
| 49 |
WASM_TOOLS_INSUFFICIENT_ENTROPY = -2, ///< wasm-smith seed too short |
| 50 |
}; |
| 51 |
|
| 52 |
/** |
| 53 |
* \brief Deletes a wasm_tools_byte_vec_t instance. |
| 54 |
* |
| 55 |
* \param bytes this is the input pointer for the wasm_tools_byte_vec_t |
| 56 |
* instance to be deleted |
| 57 |
*/ |
| 58 |
void wasm_tools_byte_vec_delete(struct wasm_tools_byte_vec_t* bytes); |
| 59 |
|
| 60 |
/** |
| 61 |
* \brief Generates a random valid wasm module using default settings. |
| 62 |
* |
| 63 |
* \param seed the input pointer to the binary seed |
| 64 |
* \param seed_len the length of `seed`, in bytes. |
| 65 |
* \param bytes wasm_tools_byte_vec_t instance where generated module is written |
| 66 |
* |
| 67 |
* \return WASM_TOOLS_SUCCESS if generation is successful, |
| 68 |
* WASM_TOOLS_INSUFFICIENT_ENTROPY if seed has too little entropy |
| 69 |
* |
| 70 |
* This function does not take ownership of `seed` |
| 71 |
*/ |
| 72 |
enum wasm_tools_error wasm_smith_create(const char* seed, size_t seed_len, struct wasm_tools_byte_vec_t* bytes); |
| 73 |
|
| 74 |
#ifdef __cplusplus |
| 75 |
} // extern "C" |
| 76 |
#endif |
| 77 |
|
| 78 |
#endif // #ifdef WASM_TOOLS_H |