15 static thread_local std::stack<std::shared_ptr<ModuleInstance>>
19 std::shared_ptr<ModuleInstance> borrowed_runtime_instance) {
37 #undef WAVM_DEFINE_INTRINSIC_FUNCTION 39 #define WAVM_DEFINE_INTRINSIC_FUNCTION(Result, cName, ...) \ 40 Result cName(WAVM::Runtime::ContextRuntimeData *contextRuntimeData, \ 43 #define WAVM_DEFINE_INTRINSIC_FUNCTION_STUB(Result, cName, ...) \ 44 Result cName(WAVM::Runtime::ContextRuntimeData *contextRuntimeData, \ 46 logger->warn("Unimplemented Host API function " #cName " was called"); \ 51 ext_allocator_free_version_1,
53 return peekHostApi()->ext_allocator_free_version_1(address);
57 ext_allocator_malloc_version_1,
59 return peekHostApi()->ext_allocator_malloc_version_1(size);
63 ext_crypto_ed25519_generate_version_1,
66 return peekHostApi()->ext_crypto_ed25519_generate_version_1(keytype, seed);
70 ext_crypto_ed25519_public_keys_version_1,
72 return peekHostApi()->ext_crypto_ed25519_public_keys_version_1(key_type);
76 ext_crypto_ed25519_sign_version_1,
80 return peekHostApi()->ext_crypto_ed25519_sign_version_1(
81 key_type, key, msg_data);
85 ext_crypto_ed25519_verify_version_1,
88 WAVM::I32 pubkey_data) {
89 return peekHostApi()->ext_crypto_ed25519_verify_version_1(
90 sig_data, msg, pubkey_data);
94 ext_crypto_finish_batch_verify_version_1) {
95 return peekHostApi()->ext_crypto_finish_batch_verify_version_1();
99 ext_crypto_secp256k1_ecdsa_recover_version_1,
102 return peekHostApi()->ext_crypto_secp256k1_ecdsa_recover_version_1(sig,
107 ext_crypto_secp256k1_ecdsa_recover_version_2,
110 return peekHostApi()->ext_crypto_secp256k1_ecdsa_recover_version_2(sig,
116 ext_crypto_secp256k1_ecdsa_recover_compressed_version_1,
120 ->ext_crypto_secp256k1_ecdsa_recover_compressed_version_1(sig, msg);
125 ext_crypto_secp256k1_ecdsa_recover_compressed_version_2,
129 ->ext_crypto_secp256k1_ecdsa_recover_compressed_version_2(sig, msg);
133 ext_crypto_sr25519_generate_version_1,
136 return peekHostApi()->ext_crypto_sr25519_generate_version_1(key_type, seed);
140 ext_crypto_sr25519_public_keys_version_1,
141 WAVM::I32 key_type) {
142 return peekHostApi()->ext_crypto_sr25519_public_keys_version_1(key_type);
146 ext_crypto_sr25519_sign_version_1,
149 WAVM::I64 msg_data) {
150 return peekHostApi()->ext_crypto_sr25519_sign_version_1(
151 key_type, key, msg_data);
155 ext_crypto_sr25519_verify_version_1,
158 WAVM::I32 pubkey_data) {
159 return peekHostApi()->ext_crypto_sr25519_verify_version_1(
160 sig_data, msg, pubkey_data);
164 ext_crypto_sr25519_verify_version_2,
167 WAVM::I32 pubkey_data) {
168 return peekHostApi()->ext_crypto_sr25519_verify_version_2(
169 sig_data, msg, pubkey_data);
173 ext_crypto_ecdsa_generate_version_1,
176 return peekHostApi()->ext_crypto_ecdsa_generate_version_1(key_type, seed);
180 ext_crypto_ecdsa_public_keys_version_1,
181 WAVM::I32 key_type) {
182 return peekHostApi()->ext_crypto_ecdsa_public_keys_version_1(key_type);
186 ext_crypto_ecdsa_sign_version_1,
189 WAVM::I64 msg_data) {
190 return peekHostApi()->ext_crypto_ecdsa_sign_version_1(
191 key_type, key, msg_data);
195 ext_crypto_ecdsa_sign_prehashed_version_1,
198 WAVM::I64 msg_data) {
199 return peekHostApi()->ext_crypto_ecdsa_sign_prehashed_version_1(
200 key_type, key, msg_data);
204 ext_crypto_ecdsa_verify_version_1,
207 WAVM::I32 pubkey_data) {
208 return peekHostApi()->ext_crypto_ecdsa_verify_version_1(
209 sig_data, msg, pubkey_data);
213 ext_crypto_ecdsa_verify_prehashed_version_1,
216 WAVM::I32 pubkey_data) {
217 return peekHostApi()->ext_crypto_ecdsa_verify_prehashed_version_1(
218 sig_data, msg, pubkey_data);
222 ext_crypto_start_batch_verify_version_1) {
223 return peekHostApi()->ext_crypto_start_batch_verify_version_1();
227 ext_trie_blake2_256_ordered_root_version_1,
228 WAVM::I64 values_data) {
229 return peekHostApi()->ext_trie_blake2_256_ordered_root_version_1(
234 ext_trie_blake2_256_ordered_root_version_2,
235 WAVM::I64 values_data,
236 WAVM::I32 state_version) {
237 return peekHostApi()->ext_trie_blake2_256_ordered_root_version_2(
238 values_data, state_version);
242 ext_misc_print_hex_version_1,
243 WAVM::I64 values_data) {
244 return peekHostApi()->ext_misc_print_hex_version_1(values_data);
248 ext_misc_print_num_version_1,
249 WAVM::I64 values_data) {
250 return peekHostApi()->ext_misc_print_num_version_1(values_data);
254 ext_misc_print_utf8_version_1,
255 WAVM::I64 values_data) {
256 return peekHostApi()->ext_misc_print_utf8_version_1(values_data);
260 ext_misc_runtime_version_version_1,
261 WAVM::I64 values_data) {
262 return peekHostApi()->ext_misc_runtime_version_version_1(values_data);
266 ext_default_child_storage_clear_version_1,
267 WAVM::I64 child_storage_key,
269 return peekHostApi()->ext_default_child_storage_clear_version_1(
270 child_storage_key, key);
274 ext_default_child_storage_read_version_1,
275 WAVM::I64 child_storage_key,
279 return peekHostApi()->ext_default_child_storage_read_version_1(
280 child_storage_key, key, value_out, offset);
284 ext_default_child_storage_exists_version_1,
285 WAVM::I64 child_storage_key,
287 return peekHostApi()->ext_default_child_storage_exists_version_1(
288 child_storage_key, key);
292 ext_default_child_storage_get_version_1,
293 WAVM::I64 child_storage_key,
295 return peekHostApi()->ext_default_child_storage_get_version_1(
296 child_storage_key, key);
300 ext_default_child_storage_next_key_version_1,
301 WAVM::I64 child_storage_key,
303 return peekHostApi()->ext_default_child_storage_next_key_version_1(
304 child_storage_key, key);
309 ext_default_child_storage_clear_prefix_version_1,
310 WAVM::I64 child_storage_key,
312 return peekHostApi()->ext_default_child_storage_clear_prefix_version_1(
313 child_storage_key, prefix);
317 ext_default_child_storage_root_version_1,
318 WAVM::I64 child_storage_key) {
319 return peekHostApi()->ext_default_child_storage_root_version_1(
324 ext_default_child_storage_set_version_1,
325 WAVM::I64 child_storage_key,
328 return peekHostApi()->ext_default_child_storage_set_version_1(
329 child_storage_key, key, value);
334 ext_default_child_storage_storage_kill_version_1,
335 WAVM::I64 child_storage_key) {
336 return peekHostApi()->ext_default_child_storage_storage_kill_version_1(
341 ext_hashing_blake2_128_version_1,
343 return peekHostApi()->ext_hashing_blake2_128_version_1(data);
347 ext_hashing_blake2_256_version_1,
349 return peekHostApi()->ext_hashing_blake2_256_version_1(data);
353 ext_hashing_keccak_256_version_1,
355 return peekHostApi()->ext_hashing_keccak_256_version_1(data);
359 ext_hashing_sha2_256_version_1,
361 return peekHostApi()->ext_hashing_sha2_256_version_1(data);
365 ext_hashing_twox_128_version_1,
367 return peekHostApi()->ext_hashing_twox_128_version_1(data);
371 ext_hashing_twox_64_version_1,
373 return peekHostApi()->ext_hashing_twox_64_version_1(data);
377 ext_hashing_twox_256_version_1,
379 return peekHostApi()->ext_hashing_twox_256_version_1(data);
385 ext_offchain_is_validator_version_1) {
386 return peekHostApi()->ext_offchain_is_validator_version_1();
390 ext_offchain_submit_transaction_version_1,
392 return peekHostApi()->ext_offchain_submit_transaction_version_1(xt);
396 ext_offchain_network_state_version_1) {
397 return peekHostApi()->ext_offchain_network_state_version_1();
401 return peekHostApi()->ext_offchain_timestamp_version_1();
405 ext_offchain_sleep_until_version_1,
406 WAVM::I64 deadline) {
407 return peekHostApi()->ext_offchain_sleep_until_version_1(deadline);
411 ext_offchain_random_seed_version_1) {
412 return peekHostApi()->ext_offchain_random_seed_version_1();
416 ext_offchain_local_storage_set_version_1,
420 return peekHostApi()->ext_offchain_local_storage_set_version_1(
425 ext_offchain_local_storage_clear_version_1,
428 return peekHostApi()->ext_offchain_local_storage_clear_version_1(kind, key);
433 ext_offchain_local_storage_compare_and_set_version_1,
438 return peekHostApi()->ext_offchain_local_storage_compare_and_set_version_1(
439 kind, key, expected, value);
443 ext_offchain_local_storage_get_version_1,
446 return peekHostApi()->ext_offchain_local_storage_get_version_1(kind, key);
450 ext_offchain_http_request_start_version_1,
454 return peekHostApi()->ext_offchain_http_request_start_version_1(
459 ext_offchain_http_request_add_header_version_1,
460 WAVM::I32 request_id,
463 return peekHostApi()->ext_offchain_http_request_add_header_version_1(
464 request_id, name, value);
468 ext_offchain_http_request_write_body_version_1,
469 WAVM::I32 request_id,
471 WAVM::I64 deadline) {
472 return peekHostApi()->ext_offchain_http_request_write_body_version_1(
473 request_id, chunk, deadline);
477 ext_offchain_http_response_wait_version_1,
479 WAVM::I64 deadline) {
480 return peekHostApi()->ext_offchain_http_response_wait_version_1(ids,
485 ext_offchain_http_response_headers_version_1,
486 WAVM::I32 request_id) {
487 return peekHostApi()->ext_offchain_http_response_headers_version_1(
492 ext_offchain_http_response_read_body_version_1,
493 WAVM::I32 request_id,
495 WAVM::I64 deadline) {
496 return peekHostApi()->ext_offchain_http_response_read_body_version_1(
497 request_id, buffer, deadline);
501 ext_offchain_set_authorized_nodes_version_1,
503 WAVM::I32 authorized_only) {
504 return peekHostApi()->ext_offchain_set_authorized_nodes_version_1(
505 nodes, authorized_only);
509 ext_offchain_index_set_version_1,
512 return peekHostApi()->ext_offchain_index_set_version_1(key, value);
516 ext_offchain_index_clear_version_1,
518 return peekHostApi()->ext_offchain_index_clear_version_1(key);
524 ext_storage_append_version_1,
527 return peekHostApi()->ext_storage_append_version_1(key, value);
531 ext_storage_changes_root_version_1,
532 WAVM::I64 parent_hash) {
533 return peekHostApi()->ext_storage_changes_root_version_1(parent_hash);
537 ext_storage_clear_version_1,
538 WAVM::I64 key_data) {
539 return peekHostApi()->ext_storage_clear_version_1(key_data);
543 ext_storage_clear_prefix_version_1,
545 return peekHostApi()->ext_storage_clear_prefix_version_1(prefix);
549 ext_storage_clear_prefix_version_2,
552 return peekHostApi()->ext_storage_clear_prefix_version_2(prefix, limit);
556 ext_storage_commit_transaction_version_1) {
557 return peekHostApi()->ext_storage_commit_transaction_version_1();
561 ext_storage_get_version_1,
563 return peekHostApi()->ext_storage_get_version_1(key);
567 ext_storage_next_key_version_1,
569 return peekHostApi()->ext_storage_next_key_version_1(key);
573 ext_storage_read_version_1,
577 return peekHostApi()->ext_storage_read_version_1(key, value_out, offset);
581 ext_storage_rollback_transaction_version_1) {
582 return peekHostApi()->ext_storage_rollback_transaction_version_1();
586 return peekHostApi()->ext_storage_root_version_1();
590 ext_storage_root_version_2,
591 WAVM::I32 state_version) {
592 return peekHostApi()->ext_storage_root_version_2(state_version);
596 ext_storage_set_version_1,
599 return peekHostApi()->ext_storage_set_version_1(key, value);
603 ext_storage_start_transaction_version_1) {
604 return peekHostApi()->ext_storage_start_transaction_version_1();
608 ext_storage_exists_version_1,
610 return peekHostApi()->ext_storage_exists_version_1(key);
614 ext_logging_log_version_1,
618 return peekHostApi()->ext_logging_log_version_1(level, target, message);
622 return peekHostApi()->ext_logging_max_level_version_1();
626 ext_sandbox_instance_teardown_version_1,
630 ext_sandbox_instantiate_version_1,
637 ext_sandbox_invoke_version_1,
646 ext_sandbox_memory_get_version_1,
653 ext_sandbox_memory_new_version_1,
658 ext_sandbox_memory_set_version_1,
665 ext_sandbox_memory_teardown_version_1,
669 ext_trie_blake2_256_root_version_1,
670 WAVM::I64 values_data) {
671 return peekHostApi()->ext_trie_blake2_256_root_version_1(values_data);
675 if (logger ==
nullptr)
678 #define REGISTER_HOST_INTRINSIC(Ret, name, ...) \ 679 module.addFunction( \ 680 #name, &name, WAVM::IR::FunctionType{{Ret}, {__VA_ARGS__}}); 682 auto I32 = WAVM::IR::ValueType::i32;
683 auto I64 = WAVM::IR::ValueType::i64;
void popBorrowedRuntimeInstance()
WAVM_DEFINE_INTRINSIC_FUNCTION(void, ext_allocator_free_version_1, WAVM::I32 address)
#define REGISTER_HOST_INTRINSIC(Ret, name,...)
static thread_local std::stack< std::shared_ptr< ModuleInstance > > global_instances
std::shared_ptr< ModuleInstance > peekBorrowedRuntimeInstance()
std::shared_ptr< soralog::Logger > Logger
std::shared_ptr< host_api::HostApi > peekHostApi()
WAVM_DEFINE_INTRINSIC_FUNCTION_STUB(void, ext_sandbox_instance_teardown_version_1, WAVM::I32) WAVM_DEFINE_INTRINSIC_FUNCTION_STUB(WAVM
Logger createLogger(const std::string &tag)
void registerHostApiMethods(IntrinsicModule &module)
void pushBorrowedRuntimeInstance(std::shared_ptr< ModuleInstance > borrowed_runtime_instance)