Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
cf_system.cpp
Go to the documentation of this file.
3
4namespace sysio { namespace chain { namespace webassembly {
5 inline static constexpr size_t max_assert_message = 1024;
6 void interface::abort() const {
7 SYS_ASSERT( false, abort_called, "abort() called" );
8 }
9
10 void interface::sysio_assert( bool condition, null_terminated_ptr msg ) const {
11 if( BOOST_UNLIKELY( !condition ) ) {
12 const size_t sz = strnlen( msg.data(), max_assert_message );
13 std::string message( msg.data(), sz );
14 SYS_THROW( sysio_assert_message_exception, "assertion failure with message: ${s}", ("s",message) );
15 }
16 }
17
18 void interface::sysio_assert_message( bool condition, legacy_span<const char> msg ) const {
19 if( BOOST_UNLIKELY( !condition ) ) {
20 const size_t sz = msg.size() > max_assert_message ? max_assert_message : msg.size();
21 std::string message( msg.data(), sz );
22 SYS_THROW( sysio_assert_message_exception, "assertion failure with message: ${s}", ("s",message) );
23 }
24 }
25
26 void interface::sysio_assert_code( bool condition, uint64_t error_code ) const {
27 if( BOOST_UNLIKELY( !condition ) ) {
28 if( error_code >= static_cast<uint64_t>(system_error_code::generic_system_error) ) {
29 restricted_error_code_exception e( FC_LOG_MESSAGE(
30 error,
31 "sysio_assert_code called with reserved error code: ${error_code}",
32 ("error_code", error_code)
33 ) );
35 throw e;
36 } else {
37 sysio_assert_code_exception e( FC_LOG_MESSAGE(
38 error,
39 "assertion failure with error code: ${error_code}",
40 ("error_code", error_code)
41 ) );
42 e.error_code = error_code;
43 throw e;
44 }
45 }
46 }
47
48 void interface::sysio_exit( int32_t code ) const {
49 context.control.get_wasm_interface().exit();
50 }
51}}} // ns sysio::chain::webassembly
#define SYS_THROW(exc_type, FORMAT,...)
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
void sysio_exit(int32_t code) const
Definition cf_system.cpp:48
void sysio_assert_message(bool condition, legacy_span< const char > msg) const
Definition cf_system.cpp:18
void sysio_assert_code(bool condition, uint64_t error_code) const
Definition cf_system.cpp:26
void sysio_assert(bool condition, null_terminated_ptr msg) const
Definition cf_system.cpp:10
#define FC_LOG_MESSAGE(LOG_LEVEL, FORMAT,...)
A helper method for generating log messages.
signed int int32_t
Definition stdint.h:123
unsigned __int64 uint64_t
Definition stdint.h:136
const char * data() const
Definition common.hpp:36