Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <sysio/vm/utils.hpp>
4
5#include <cstdint>
6#include <exception>
7
8#define SYS_VM_ASSERT( expr, exc_type, msg ) \
9 if (!UNLIKELY(expr)) { \
10 throw exc_type{msg}; \
11 }
12
13namespace sysio { namespace vm {
14 struct exception : public std::exception {
15 virtual const char* what()const throw()=0;
16 virtual const char* detail()const throw()=0;
17 };
18}}
19
20#define DECLARE_EXCEPTION(name, _code, _what) \
21 struct name : public sysio::vm::exception { \
22 name(std::string msg) : msg(msg) {} \
23 virtual const char* what()const throw() { return _what; } \
24 virtual const char* detail()const throw() { return msg.c_str(); } \
25 uint32_t code()const { return _code; } \
26 std::string msg; \
27 };
28
29namespace sysio { namespace vm {
30 DECLARE_EXCEPTION( wasm_interpreter_exception, 4000000, "wasm interpreter exception" )
31 DECLARE_EXCEPTION( wasm_section_length_exception, 4000001, "wasm section length exception" )
32 DECLARE_EXCEPTION( wasm_bad_alloc, 4000002, "wasm allocation failed" )
33 DECLARE_EXCEPTION( wasm_double_free, 4000003, "wasm free failed" )
34 DECLARE_EXCEPTION( wasm_vector_oob_exception, 4000004, "wasm vector out of bounds" )
35 DECLARE_EXCEPTION( wasm_unsupported_import_exception, 4000005, "wasm interpreter only accepts function imports" )
36 DECLARE_EXCEPTION( wasm_parse_exception, 4000006, "wasm parse exception" )
37 DECLARE_EXCEPTION( wasm_memory_exception, 4000007, "wasm memory exception" )
38 DECLARE_EXCEPTION( stack_memory_exception, 4000008, "stack memory exception" )
39 DECLARE_EXCEPTION( wasm_invalid_element, 4000009, "wasm invalid_element" )
40 DECLARE_EXCEPTION( wasm_link_exception, 4000010, "wasm linked function failure" )
41 DECLARE_EXCEPTION( guarded_ptr_exception, 4010000, "pointer out of bounds" )
42 DECLARE_EXCEPTION( timeout_exception, 4010001, "timeout" )
43 DECLARE_EXCEPTION( wasm_exit_exception, 4010002, "exit" )
44 DECLARE_EXCEPTION( span_exception, 4020000, "span exception" )
45 DECLARE_EXCEPTION( profile_exception, 4030000, "profile exception" )
46}} // sysio::vm
47
48#undef DECLARE_EXCEPTION
virtual const char * what() const =0
#define DECLARE_EXCEPTION(name, _code, _what)