mirror of
https://github.com/Xahau/xahaud.git
synced 2026-07-26 16:40:09 +00:00
Update new tests
This commit is contained in:
@@ -2605,81 +2605,245 @@ public:
|
||||
|
||||
// Test 1: Valid helper function without loops - should pass
|
||||
{
|
||||
TestHook hook = wasm[R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
/*
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t
|
||||
error_code);
|
||||
extern int64_t hook_pos(void);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t simple_helper(int64_t x) {
|
||||
return x + 1;
|
||||
}
|
||||
int64_t helper(int64_t n) { return n + hook_pos(); }
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = simple_helper(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
int64_t cbak(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = helper(34);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = helper(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
*/
|
||||
TestHook hook_wasm = wasm[R"[test.hook](
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (result i64)))
|
||||
(type (;2;) (func (param i32 i32) (result i32)))
|
||||
(type (;3;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;4;) (func (param i64) (result i64)))
|
||||
(import "env" "hook_pos" (func (;0;) (type 1)))
|
||||
(import "env" "_g" (func (;1;) (type 2)))
|
||||
(import "env" "accept" (func (;2;) (type 3)))
|
||||
(func (;3;) (type 4) (param i64) (result i64)
|
||||
call 0
|
||||
local.get 0
|
||||
i64.add)
|
||||
(func (;4;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 1
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 34
|
||||
call 3
|
||||
call 2)
|
||||
(func (;5;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 1
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 5
|
||||
call 3
|
||||
call 2)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "cbak" (func 4))
|
||||
(export "hook" (func 5)))
|
||||
)[test.hook]"];
|
||||
HASH_WASM(hook);
|
||||
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
|
||||
env(ripple::test::jtx::hook(
|
||||
alice, {{hso(hook_wasm, overrideFlag)}}, 0),
|
||||
M("Valid helper function without loops"),
|
||||
HSFEE,
|
||||
ter(tesSUCCESS));
|
||||
env.close();
|
||||
EXPECT_HOOK_FEE(hook, 14);
|
||||
}
|
||||
|
||||
// Test 2: Helper function with guarded loop - should pass
|
||||
{
|
||||
TestHook hook = wasm[R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t error_code);
|
||||
/*
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t
|
||||
error_code); extern int64_t hook_pos(void);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t helper_with_loop(int64_t n) {
|
||||
int64_t sum = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
_g(2, 11);
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
int64_t helper(int64_t n) {
|
||||
int64_t sum = 0;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
_g(2, 4);
|
||||
sum += i * n;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = helper_with_loop(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
int64_t cbak(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = helper(2);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = helper(3);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
*/
|
||||
TestHook hook_wasm = wasm[R"[test.hook](
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (param i32 i32) (result i32)))
|
||||
(type (;2;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;3;) (func (param i64) (result i64)))
|
||||
(import "env" "_g" (func (;0;) (type 1)))
|
||||
(import "env" "accept" (func (;1;) (type 2)))
|
||||
(func (;2;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 3
|
||||
call 3
|
||||
call 1)
|
||||
(func (;3;) (type 3) (param i64) (result i64)
|
||||
i32.const 2
|
||||
i32.const 4
|
||||
call 0
|
||||
drop
|
||||
i32.const 2
|
||||
i32.const 4
|
||||
call 0
|
||||
drop
|
||||
i32.const 2
|
||||
i32.const 4
|
||||
call 0
|
||||
drop
|
||||
local.get 0
|
||||
i64.const 3
|
||||
i64.mul)
|
||||
(func (;4;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 2
|
||||
call 3
|
||||
call 1)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "hook" (func 2))
|
||||
(export "cbak" (func 4)))
|
||||
)[test.hook]"];
|
||||
HASH_WASM(hook);
|
||||
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
|
||||
env(ripple::test::jtx::hook(
|
||||
alice, {{hso(hook_wasm, overrideFlag)}}, 0),
|
||||
M("Helper function with guarded loop"),
|
||||
HSFEE,
|
||||
ter(tesSUCCESS));
|
||||
env.close();
|
||||
EXPECT_HOOK_FEE(hook, 26);
|
||||
}
|
||||
|
||||
// Test 3: Direct recursion - should fail
|
||||
{
|
||||
/*
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t
|
||||
error_code);
|
||||
extern int64_t hook_pos(void);
|
||||
|
||||
int64_t recursive_func(int64_t n) {
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
return n + recursive_func(n - hook_pos());
|
||||
}
|
||||
int64_t cbak(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = recursive_func(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = recursive_func(10);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
*/
|
||||
TestHook hook = wasm[R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t recursive_func(int64_t n) {
|
||||
if (n <= 0) return 0;
|
||||
return n + recursive_func(n - 1);
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = recursive_func(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (param i32 i32) (result i32)))
|
||||
(type (;2;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;3;) (func (result i64)))
|
||||
(type (;4;) (func (param i64) (result i64)))
|
||||
(import "env" "_g" (func $g (type 1)))
|
||||
(import "env" "accept" (func $accept (type 2)))
|
||||
(import "env" "hook_pos" (func $hook_pos (type 3)))
|
||||
(func $recursive_func (type 4) (param $n i64) (result i64)
|
||||
(if (result i64)
|
||||
(i64.le_s (local.get $n) (i64.const 0))
|
||||
(then
|
||||
(i64.const 0)
|
||||
)
|
||||
(else
|
||||
(i64.add
|
||||
(local.get $n)
|
||||
(call $recursive_func
|
||||
(i64.sub (local.get $n) (call $hook_pos))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (;3;) (type 0) (param i32) (result i64) ;; cbak
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call $g
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 5
|
||||
call $recursive_func
|
||||
call $accept
|
||||
)
|
||||
(func (;5;) (type 0) (param i32) (result i64) ;; hook
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call $g
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 10
|
||||
call $recursive_func
|
||||
call $accept
|
||||
)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "cbak" (func 3))
|
||||
(export "hook" (func 5)))
|
||||
)[test.hook]"];
|
||||
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook)}}, 0),
|
||||
@@ -2691,32 +2855,90 @@ public:
|
||||
|
||||
// Test 4: Indirect recursion (A -> B -> A) - should fail
|
||||
{
|
||||
/*
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t
|
||||
error_code);
|
||||
|
||||
int64_t func_b(int64_t n);
|
||||
|
||||
int64_t func_a(int64_t n) {
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
return n + func_b(n - 1);
|
||||
}
|
||||
|
||||
int64_t func_b(int64_t n) {
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
return n + func_a(n - 1);
|
||||
}
|
||||
|
||||
int64_t cbak(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = func_a(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = func_a(10);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
*/
|
||||
TestHook hook = wasm[R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_b(int64_t n);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_a(int64_t n) {
|
||||
if (n <= 0) return 0;
|
||||
return n + func_b(n - 1);
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int64_t func_b(int64_t n) {
|
||||
if (n <= 0) return 0;
|
||||
return n + func_a(n - 1);
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = func_a(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(import "env" "_g" (func $_g (param i32 i32) (result i32)))
|
||||
(import "env" "accept" (func $accept (param i32 i32 i64) (result i64)))
|
||||
(type $func_type (func (param i64) (result i64)))
|
||||
(func $func_b (param $n i64) (result i64)
|
||||
(if (result i64)
|
||||
(i64.le_s (local.get $n) (i64.const 0))
|
||||
(then
|
||||
(i64.const 0)
|
||||
)
|
||||
(else
|
||||
(i64.add
|
||||
(local.get $n)
|
||||
(call $func_a
|
||||
(i64.sub (local.get $n) (i64.const 1))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $func_a (param $n i64) (result i64)
|
||||
(if (result i64)
|
||||
(i64.le_s (local.get $n) (i64.const 0))
|
||||
(then
|
||||
(i64.const 0)
|
||||
)
|
||||
(else
|
||||
(i64.add
|
||||
(local.get $n)
|
||||
(call $func_b
|
||||
(i64.sub (local.get $n) (i64.const 1))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $cbak (param $reserved i32) (result i64)
|
||||
(local $result i64)
|
||||
(drop (call $_g (i32.const 1) (i32.const 1)))
|
||||
(local.set $result (call $func_a (i64.const 5)))
|
||||
(call $accept (i32.const 0) (i32.const 0) (local.get $result))
|
||||
)
|
||||
(func $hook (param $reserved i32) (result i64)
|
||||
(local $result i64)
|
||||
(drop (call $_g (i32.const 1) (i32.const 1)))
|
||||
(local.set $result (call $func_a (i64.const 10)))
|
||||
(call $accept (i32.const 0) (i32.const 0) (local.get $result))
|
||||
)
|
||||
(export "cbak" (func $cbak))
|
||||
(export "hook" (func $hook)))
|
||||
)[test.hook]"];
|
||||
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook)}}, 0),
|
||||
@@ -2728,72 +2950,146 @@ public:
|
||||
|
||||
// Test 5: Deep call chain (A -> B -> C -> D) - should pass if WCE is OK
|
||||
{
|
||||
TestHook hook = wasm[R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
/*
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t
|
||||
error_code);
|
||||
extern int64_t hook_pos(void);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_d(int64_t n) {
|
||||
return n * 2;
|
||||
}
|
||||
int64_t helper(int64_t n) { return n + hook_pos(); }
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_c(int64_t n) {
|
||||
return func_d(n) + 1;
|
||||
}
|
||||
int64_t cbak(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = helper(34);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_b(int64_t n) {
|
||||
return func_c(n) + 1;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_a(int64_t n) {
|
||||
return func_b(n) + 1;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = func_a(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = helper(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
*/
|
||||
TestHook hook_wasm = wasm[R"[test.hook](
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (result i64)))
|
||||
(type (;2;) (func (param i32 i32) (result i32)))
|
||||
(type (;3;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;4;) (func (param i64) (result i64)))
|
||||
(import "env" "hook_pos" (func (;0;) (type 1)))
|
||||
(import "env" "_g" (func (;1;) (type 2)))
|
||||
(import "env" "accept" (func (;2;) (type 3)))
|
||||
(func (;3;) (type 4) (param i64) (result i64)
|
||||
call 0
|
||||
local.get 0
|
||||
i64.add)
|
||||
(func (;4;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 1
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 34
|
||||
call 3
|
||||
call 2)
|
||||
(func (;5;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 1
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 5
|
||||
call 3
|
||||
call 2)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "cbak" (func 4))
|
||||
(export "hook" (func 5)))
|
||||
)[test.hook]"];
|
||||
HASH_WASM(hook);
|
||||
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
|
||||
env(ripple::test::jtx::hook(
|
||||
alice, {{hso(hook_wasm, overrideFlag)}}, 0),
|
||||
M("Deep call chain without recursion"),
|
||||
HSFEE,
|
||||
ter(tesSUCCESS));
|
||||
env.close();
|
||||
EXPECT_HOOK_FEE(hook, 14);
|
||||
}
|
||||
|
||||
// Test 6: Helper called multiple times - WCE should accumulate
|
||||
{
|
||||
/*
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t
|
||||
error_code);
|
||||
|
||||
int64_t expensive_helper() {
|
||||
int64_t sum = 0;
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
_g(2, 101);
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = 0;
|
||||
result += expensive_helper();
|
||||
result += expensive_helper();
|
||||
result += expensive_helper();
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
*/
|
||||
TestHook hook = wasm[R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t expensive_helper() {
|
||||
int64_t sum = 0;
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
_g(2, 101);
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = 0;
|
||||
result += expensive_helper();
|
||||
result += expensive_helper();
|
||||
result += expensive_helper();
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(type (;0;) (func (param i32 i32) (result i32)))
|
||||
(type (;1;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;2;) (func (param i32) (result i64)))
|
||||
(type (;3;) (func (result i64)))
|
||||
(import "env" "_g" (func (;0;) (type 0)))
|
||||
(import "env" "accept" (func (;1;) (type 1)))
|
||||
(func (;2;) (type 2) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
call 3
|
||||
call 3
|
||||
i64.add
|
||||
call 3
|
||||
i64.add
|
||||
call 1)
|
||||
(func (;3;) (type 3) (result i64)
|
||||
(local i64)
|
||||
i64.const 100
|
||||
local.set 0
|
||||
loop ;; label = @1
|
||||
i32.const 2
|
||||
i32.const 101
|
||||
call 0
|
||||
drop
|
||||
local.get 0
|
||||
i64.const 1
|
||||
i64.sub
|
||||
local.tee 0
|
||||
i64.eqz
|
||||
i32.eqz
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i64.const 4950)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "hook" (func 2)))
|
||||
)[test.hook]"];
|
||||
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
|
||||
@@ -2805,31 +3101,132 @@ public:
|
||||
|
||||
// Test 7: WCE overflow through many helpers - should fail
|
||||
{
|
||||
/*
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t
|
||||
error_code);
|
||||
|
||||
int64_t large_helper(int64_t n) {
|
||||
int64_t sum = n;
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
_g(2, 10001);
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int64_t cbak(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = 10;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
_g(3, 11);
|
||||
result += large_helper(10);
|
||||
}
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1, 1);
|
||||
int64_t result = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
_g(3, 11);
|
||||
result += large_helper(0);
|
||||
}
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
|
||||
*/
|
||||
TestHook hook = wasm[R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t large_helper() {
|
||||
int64_t sum = 0;
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
_g(2, 10001);
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
_g(3, 11);
|
||||
result += large_helper();
|
||||
}
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (param i32 i32) (result i32)))
|
||||
(type (;2;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;3;) (func (param i64) (result i64)))
|
||||
(import "env" "_g" (func (;0;) (type 1)))
|
||||
(import "env" "accept" (func (;1;) (type 2)))
|
||||
(func (;2;) (type 0) (param i32) (result i64)
|
||||
(local i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 10
|
||||
local.set 0
|
||||
i64.const 10
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
i32.const 3
|
||||
i32.const 11
|
||||
call 0
|
||||
drop
|
||||
i64.const 10
|
||||
call 3
|
||||
local.get 1
|
||||
i64.add
|
||||
local.set 1
|
||||
local.get 0
|
||||
i32.const 1
|
||||
i32.sub
|
||||
local.tee 0
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
local.get 1
|
||||
call 1)
|
||||
(func (;3;) (type 3) (param i64) (result i64)
|
||||
(local i64)
|
||||
i64.const 10000
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
i32.const 2
|
||||
i32.const 10001
|
||||
call 0
|
||||
drop
|
||||
local.get 1
|
||||
i64.const 1
|
||||
i64.sub
|
||||
local.tee 1
|
||||
i64.eqz
|
||||
i32.eqz
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
local.get 0
|
||||
i64.const 49995000
|
||||
i64.add)
|
||||
(func (;4;) (type 0) (param i32) (result i64)
|
||||
(local i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 10
|
||||
local.set 0
|
||||
loop ;; label = @1
|
||||
i32.const 3
|
||||
i32.const 11
|
||||
call 0
|
||||
drop
|
||||
i64.const 0
|
||||
call 3
|
||||
local.get 1
|
||||
i64.add
|
||||
local.set 1
|
||||
local.get 0
|
||||
i32.const 1
|
||||
i32.sub
|
||||
local.tee 0
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
local.get 1
|
||||
call 1)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "cbak" (func 2))
|
||||
(export "hook" (func 4)))
|
||||
)[test.hook]"];
|
||||
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook)}}, 0),
|
||||
|
||||
@@ -544,272 +544,388 @@ std::map<std::string, std::vector<uint8_t>> wasm = {
|
||||
|
||||
/* ==== WASM: 6 ==== */
|
||||
{R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t simple_helper(int64_t x) {
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = simple_helper(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (result i64)))
|
||||
(type (;2;) (func (param i32 i32) (result i32)))
|
||||
(type (;3;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;4;) (func (param i64) (result i64)))
|
||||
(import "env" "hook_pos" (func (;0;) (type 1)))
|
||||
(import "env" "_g" (func (;1;) (type 2)))
|
||||
(import "env" "accept" (func (;2;) (type 3)))
|
||||
(func (;3;) (type 4) (param i64) (result i64)
|
||||
call 0
|
||||
local.get 0
|
||||
i64.add)
|
||||
(func (;4;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 1
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 34
|
||||
call 3
|
||||
call 2)
|
||||
(func (;5;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 1
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 5
|
||||
call 3
|
||||
call 2)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "cbak" (func 4))
|
||||
(export "hook" (func 5)))
|
||||
)[test.hook]",
|
||||
{
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x13U,
|
||||
0x03U, 0x60U, 0x02U, 0x7FU, 0x7FU, 0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU,
|
||||
0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x02U,
|
||||
0x17U, 0x02U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x02U, 0x5FU, 0x67U, 0x00U,
|
||||
0x00U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x06U, 0x61U, 0x63U, 0x63U, 0x65U,
|
||||
0x70U, 0x74U, 0x00U, 0x01U, 0x03U, 0x02U, 0x01U, 0x02U, 0x05U, 0x03U,
|
||||
0x01U, 0x00U, 0x02U, 0x06U, 0x21U, 0x05U, 0x7FU, 0x01U, 0x41U, 0x80U,
|
||||
0x88U, 0x04U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU,
|
||||
0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x88U,
|
||||
0x04U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x07U, 0x08U,
|
||||
0x01U, 0x04U, 0x68U, 0x6FU, 0x6FU, 0x6BU, 0x00U, 0x02U, 0x0AU, 0x9DU,
|
||||
0x80U, 0x00U, 0x01U, 0x99U, 0x80U, 0x00U, 0x00U, 0x41U, 0x01U, 0x41U,
|
||||
0x01U, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x00U,
|
||||
0x41U, 0x00U, 0x42U, 0x06U, 0x10U, 0x81U, 0x80U, 0x80U, 0x80U, 0x00U,
|
||||
0x0BU,
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x1CU,
|
||||
0x05U, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x60U, 0x00U, 0x01U, 0x7EU,
|
||||
0x60U, 0x02U, 0x7FU, 0x7FU, 0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU, 0x7FU,
|
||||
0x7EU, 0x01U, 0x7EU, 0x60U, 0x01U, 0x7EU, 0x01U, 0x7EU, 0x02U, 0x26U,
|
||||
0x03U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x08U, 0x68U, 0x6FU, 0x6FU, 0x6BU,
|
||||
0x5FU, 0x70U, 0x6FU, 0x73U, 0x00U, 0x01U, 0x03U, 0x65U, 0x6EU, 0x76U,
|
||||
0x02U, 0x5FU, 0x67U, 0x00U, 0x02U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x06U,
|
||||
0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x03U, 0x03U, 0x04U,
|
||||
0x03U, 0x04U, 0x00U, 0x00U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U, 0x07U,
|
||||
0x18U, 0x03U, 0x06U, 0x6DU, 0x65U, 0x6DU, 0x6FU, 0x72U, 0x79U, 0x02U,
|
||||
0x00U, 0x04U, 0x63U, 0x62U, 0x61U, 0x6BU, 0x00U, 0x04U, 0x04U, 0x68U,
|
||||
0x6FU, 0x6FU, 0x6BU, 0x00U, 0x05U, 0x0AU, 0x31U, 0x03U, 0x07U, 0x00U,
|
||||
0x10U, 0x00U, 0x20U, 0x00U, 0x7CU, 0x0BU, 0x13U, 0x00U, 0x41U, 0x01U,
|
||||
0x41U, 0x01U, 0x10U, 0x01U, 0x1AU, 0x41U, 0x00U, 0x41U, 0x00U, 0x42U,
|
||||
0x22U, 0x10U, 0x03U, 0x10U, 0x02U, 0x0BU, 0x13U, 0x00U, 0x41U, 0x01U,
|
||||
0x41U, 0x01U, 0x10U, 0x01U, 0x1AU, 0x41U, 0x00U, 0x41U, 0x00U, 0x42U,
|
||||
0x05U, 0x10U, 0x03U, 0x10U, 0x02U, 0x0BU,
|
||||
}},
|
||||
|
||||
/* ==== WASM: 7 ==== */
|
||||
{R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len, int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t helper_with_loop(int64_t n) {
|
||||
int64_t sum = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
_g(2, 11);
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = helper_with_loop(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (param i32 i32) (result i32)))
|
||||
(type (;2;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;3;) (func (param i64) (result i64)))
|
||||
(import "env" "_g" (func (;0;) (type 1)))
|
||||
(import "env" "accept" (func (;1;) (type 2)))
|
||||
(func (;2;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 3
|
||||
call 3
|
||||
call 1)
|
||||
(func (;3;) (type 3) (param i64) (result i64)
|
||||
i32.const 2
|
||||
i32.const 4
|
||||
call 0
|
||||
drop
|
||||
i32.const 2
|
||||
i32.const 4
|
||||
call 0
|
||||
drop
|
||||
i32.const 2
|
||||
i32.const 4
|
||||
call 0
|
||||
drop
|
||||
local.get 0
|
||||
i64.const 3
|
||||
i64.mul)
|
||||
(func (;4;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 2
|
||||
call 3
|
||||
call 1)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "hook" (func 2))
|
||||
(export "cbak" (func 4)))
|
||||
)[test.hook]",
|
||||
{
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x17U,
|
||||
0x04U, 0x60U, 0x02U, 0x7FU, 0x7FU, 0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU,
|
||||
0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x60U,
|
||||
0x00U, 0x01U, 0x7EU, 0x02U, 0x17U, 0x02U, 0x03U, 0x65U, 0x6EU, 0x76U,
|
||||
0x02U, 0x5FU, 0x67U, 0x00U, 0x00U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x06U,
|
||||
0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x01U, 0x03U, 0x03U,
|
||||
0x02U, 0x02U, 0x03U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U, 0x06U, 0x21U,
|
||||
0x05U, 0x7FU, 0x01U, 0x41U, 0x80U, 0x88U, 0x04U, 0x0BU, 0x7FU, 0x00U,
|
||||
0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU,
|
||||
0x7FU, 0x00U, 0x41U, 0x80U, 0x88U, 0x04U, 0x0BU, 0x7FU, 0x00U, 0x41U,
|
||||
0x80U, 0x08U, 0x0BU, 0x07U, 0x08U, 0x01U, 0x04U, 0x68U, 0x6FU, 0x6FU,
|
||||
0x6BU, 0x00U, 0x02U, 0x0AU, 0x96U, 0x81U, 0x00U, 0x02U, 0x9DU, 0x80U,
|
||||
0x00U, 0x00U, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x80U, 0x80U, 0x80U,
|
||||
0x80U, 0x00U, 0x1AU, 0x41U, 0x00U, 0x41U, 0x00U, 0x10U, 0x83U, 0x80U,
|
||||
0x80U, 0x80U, 0x00U, 0x10U, 0x81U, 0x80U, 0x80U, 0x80U, 0x00U, 0x0BU,
|
||||
0xF2U, 0x80U, 0x00U, 0x00U, 0x41U, 0x02U, 0x41U, 0x0BU, 0x10U, 0x80U,
|
||||
0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x02U, 0x41U, 0x0BU, 0x10U,
|
||||
0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x02U, 0x41U, 0x0BU,
|
||||
0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x02U, 0x41U,
|
||||
0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x02U,
|
||||
0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U,
|
||||
0x02U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU,
|
||||
0x41U, 0x02U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U,
|
||||
0x1AU, 0x41U, 0x02U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U,
|
||||
0x00U, 0x1AU, 0x41U, 0x02U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U,
|
||||
0x80U, 0x00U, 0x1AU, 0x41U, 0x02U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U,
|
||||
0x80U, 0x80U, 0x00U, 0x1AU, 0x42U, 0x2DU, 0x0BU,
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x18U,
|
||||
0x04U, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x60U, 0x02U, 0x7FU, 0x7FU,
|
||||
0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU, 0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U,
|
||||
0x01U, 0x7EU, 0x01U, 0x7EU, 0x02U, 0x17U, 0x02U, 0x03U, 0x65U, 0x6EU,
|
||||
0x76U, 0x02U, 0x5FU, 0x67U, 0x00U, 0x01U, 0x03U, 0x65U, 0x6EU, 0x76U,
|
||||
0x06U, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x02U, 0x03U,
|
||||
0x04U, 0x03U, 0x00U, 0x03U, 0x00U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U,
|
||||
0x07U, 0x18U, 0x03U, 0x06U, 0x6DU, 0x65U, 0x6DU, 0x6FU, 0x72U, 0x79U,
|
||||
0x02U, 0x00U, 0x04U, 0x68U, 0x6FU, 0x6FU, 0x6BU, 0x00U, 0x02U, 0x04U,
|
||||
0x63U, 0x62U, 0x61U, 0x6BU, 0x00U, 0x04U, 0x0AU, 0x46U, 0x03U, 0x13U,
|
||||
0x00U, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x00U, 0x1AU, 0x41U, 0x00U,
|
||||
0x41U, 0x00U, 0x42U, 0x03U, 0x10U, 0x03U, 0x10U, 0x01U, 0x0BU, 0x1CU,
|
||||
0x00U, 0x41U, 0x02U, 0x41U, 0x04U, 0x10U, 0x00U, 0x1AU, 0x41U, 0x02U,
|
||||
0x41U, 0x04U, 0x10U, 0x00U, 0x1AU, 0x41U, 0x02U, 0x41U, 0x04U, 0x10U,
|
||||
0x00U, 0x1AU, 0x20U, 0x00U, 0x42U, 0x03U, 0x7EU, 0x0BU, 0x13U, 0x00U,
|
||||
0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x00U, 0x1AU, 0x41U, 0x00U, 0x41U,
|
||||
0x00U, 0x42U, 0x02U, 0x10U, 0x03U, 0x10U, 0x01U, 0x0BU,
|
||||
}},
|
||||
|
||||
/* ==== WASM: 8 ==== */
|
||||
{R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t recursive_func(int64_t n) {
|
||||
if (n <= 0) return 0;
|
||||
return n + recursive_func(n - 1);
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = recursive_func(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (param i32 i32) (result i32)))
|
||||
(type (;2;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;3;) (func (result i64)))
|
||||
(type (;4;) (func (param i64) (result i64)))
|
||||
(import "env" "_g" (func $g (type 1)))
|
||||
(import "env" "accept" (func $accept (type 2)))
|
||||
(import "env" "hook_pos" (func $hook_pos (type 3)))
|
||||
(func $recursive_func (type 4) (param $n i64) (result i64)
|
||||
(if (result i64)
|
||||
(i64.le_s (local.get $n) (i64.const 0))
|
||||
(then
|
||||
(i64.const 0)
|
||||
)
|
||||
(else
|
||||
(i64.add
|
||||
(local.get $n)
|
||||
(call $recursive_func
|
||||
(i64.sub (local.get $n) (call $hook_pos))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func (;3;) (type 0) (param i32) (result i64) ;; cbak
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call $g
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 5
|
||||
call $recursive_func
|
||||
call $accept
|
||||
)
|
||||
(func (;5;) (type 0) (param i32) (result i64) ;; hook
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call $g
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 10
|
||||
call $recursive_func
|
||||
call $accept
|
||||
)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "cbak" (func 3))
|
||||
(export "hook" (func 5)))
|
||||
)[test.hook]",
|
||||
{
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x20U,
|
||||
0x05U, 0x60U, 0x02U, 0x7FU, 0x7FU, 0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU,
|
||||
0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U, 0x05U, 0x7FU, 0x7EU, 0x7EU, 0x7EU,
|
||||
0x7EU, 0x00U, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x60U, 0x01U, 0x7EU,
|
||||
0x01U, 0x7EU, 0x02U, 0x26U, 0x03U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x02U,
|
||||
0x5FU, 0x67U, 0x00U, 0x00U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x06U, 0x61U,
|
||||
0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x01U, 0x03U, 0x65U, 0x6EU,
|
||||
0x76U, 0x08U, 0x5FU, 0x5FU, 0x6DU, 0x75U, 0x6CU, 0x74U, 0x69U, 0x33U,
|
||||
0x00U, 0x02U, 0x03U, 0x03U, 0x02U, 0x03U, 0x04U, 0x05U, 0x03U, 0x01U,
|
||||
0x00U, 0x02U, 0x06U, 0x21U, 0x05U, 0x7FU, 0x01U, 0x41U, 0x80U, 0x88U,
|
||||
0x04U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU, 0x00U,
|
||||
0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x88U, 0x04U,
|
||||
0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x07U, 0x08U, 0x01U,
|
||||
0x04U, 0x68U, 0x6FU, 0x6FU, 0x6BU, 0x00U, 0x03U, 0x0AU, 0x94U, 0x81U,
|
||||
0x00U, 0x02U, 0x9FU, 0x80U, 0x00U, 0x00U, 0x41U, 0x01U, 0x41U, 0x01U,
|
||||
0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x00U, 0x41U,
|
||||
0x00U, 0x42U, 0x05U, 0x10U, 0x84U, 0x80U, 0x80U, 0x80U, 0x00U, 0x10U,
|
||||
0x81U, 0x80U, 0x80U, 0x80U, 0x00U, 0x0BU, 0xEEU, 0x80U, 0x00U, 0x02U,
|
||||
0x01U, 0x7FU, 0x01U, 0x7EU, 0x23U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U,
|
||||
0x41U, 0x10U, 0x6BU, 0x22U, 0x01U, 0x24U, 0x80U, 0x80U, 0x80U, 0x80U,
|
||||
0x00U, 0x02U, 0x40U, 0x02U, 0x40U, 0x20U, 0x00U, 0x42U, 0x01U, 0x59U,
|
||||
0x0DU, 0x00U, 0x42U, 0x00U, 0x21U, 0x00U, 0x0CU, 0x01U, 0x0BU, 0x20U,
|
||||
0x01U, 0x20U, 0x00U, 0x42U, 0x7EU, 0x7CU, 0x42U, 0x00U, 0x20U, 0x00U,
|
||||
0x42U, 0x7FU, 0x7CU, 0x22U, 0x02U, 0x42U, 0x00U, 0x10U, 0x82U, 0x80U,
|
||||
0x80U, 0x80U, 0x00U, 0x20U, 0x02U, 0x20U, 0x02U, 0x7EU, 0x20U, 0x00U,
|
||||
0x7CU, 0x20U, 0x01U, 0x29U, 0x03U, 0x00U, 0x42U, 0x01U, 0x88U, 0x20U,
|
||||
0x01U, 0x41U, 0x08U, 0x6AU, 0x29U, 0x03U, 0x00U, 0x42U, 0x3FU, 0x86U,
|
||||
0x84U, 0x7DU, 0x21U, 0x00U, 0x0BU, 0x20U, 0x01U, 0x41U, 0x10U, 0x6AU,
|
||||
0x24U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x20U, 0x00U, 0x0BU,
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x1CU,
|
||||
0x05U, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x60U, 0x02U, 0x7FU, 0x7FU,
|
||||
0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU, 0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U,
|
||||
0x00U, 0x01U, 0x7EU, 0x60U, 0x01U, 0x7EU, 0x01U, 0x7EU, 0x02U, 0x26U,
|
||||
0x03U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x02U, 0x5FU, 0x67U, 0x00U, 0x01U,
|
||||
0x03U, 0x65U, 0x6EU, 0x76U, 0x06U, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U,
|
||||
0x74U, 0x00U, 0x02U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x08U, 0x68U, 0x6FU,
|
||||
0x6FU, 0x6BU, 0x5FU, 0x70U, 0x6FU, 0x73U, 0x00U, 0x03U, 0x03U, 0x04U,
|
||||
0x03U, 0x04U, 0x00U, 0x00U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U, 0x07U,
|
||||
0x18U, 0x03U, 0x06U, 0x6DU, 0x65U, 0x6DU, 0x6FU, 0x72U, 0x79U, 0x02U,
|
||||
0x00U, 0x04U, 0x63U, 0x62U, 0x61U, 0x6BU, 0x00U, 0x03U, 0x04U, 0x68U,
|
||||
0x6FU, 0x6FU, 0x6BU, 0x00U, 0x05U, 0x0AU, 0x41U, 0x03U, 0x17U, 0x00U,
|
||||
0x20U, 0x00U, 0x42U, 0x00U, 0x57U, 0x04U, 0x7EU, 0x42U, 0x00U, 0x05U,
|
||||
0x20U, 0x00U, 0x20U, 0x00U, 0x10U, 0x02U, 0x7DU, 0x10U, 0x03U, 0x7CU,
|
||||
0x0BU, 0x0BU, 0x13U, 0x00U, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x00U,
|
||||
0x1AU, 0x41U, 0x00U, 0x41U, 0x00U, 0x42U, 0x05U, 0x10U, 0x03U, 0x10U,
|
||||
0x01U, 0x0BU, 0x13U, 0x00U, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x00U,
|
||||
0x1AU, 0x41U, 0x00U, 0x41U, 0x00U, 0x42U, 0x0AU, 0x10U, 0x03U, 0x10U,
|
||||
0x01U, 0x0BU,
|
||||
}},
|
||||
|
||||
/* ==== WASM: 9 ==== */
|
||||
{R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_b(int64_t n);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_a(int64_t n) {
|
||||
if (n <= 0) return 0;
|
||||
return n + func_b(n - 1);
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int64_t func_b(int64_t n) {
|
||||
if (n <= 0) return 0;
|
||||
return n + func_a(n - 1);
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = func_a(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(import "env" "_g" (func $_g (param i32 i32) (result i32)))
|
||||
(import "env" "accept" (func $accept (param i32 i32 i64) (result i64)))
|
||||
(type $func_type (func (param i64) (result i64)))
|
||||
(func $func_b (param $n i64) (result i64)
|
||||
(if (result i64)
|
||||
(i64.le_s (local.get $n) (i64.const 0))
|
||||
(then
|
||||
(i64.const 0)
|
||||
)
|
||||
(else
|
||||
(i64.add
|
||||
(local.get $n)
|
||||
(call $func_a
|
||||
(i64.sub (local.get $n) (i64.const 1))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $func_a (param $n i64) (result i64)
|
||||
(if (result i64)
|
||||
(i64.le_s (local.get $n) (i64.const 0))
|
||||
(then
|
||||
(i64.const 0)
|
||||
)
|
||||
(else
|
||||
(i64.add
|
||||
(local.get $n)
|
||||
(call $func_b
|
||||
(i64.sub (local.get $n) (i64.const 1))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $cbak (param $reserved i32) (result i64)
|
||||
(local $result i64)
|
||||
(drop (call $_g (i32.const 1) (i32.const 1)))
|
||||
(local.set $result (call $func_a (i64.const 5)))
|
||||
(call $accept (i32.const 0) (i32.const 0) (local.get $result))
|
||||
)
|
||||
(func $hook (param $reserved i32) (result i64)
|
||||
(local $result i64)
|
||||
(drop (call $_g (i32.const 1) (i32.const 1)))
|
||||
(local.set $result (call $func_a (i64.const 10)))
|
||||
(call $accept (i32.const 0) (i32.const 0) (local.get $result))
|
||||
)
|
||||
(export "cbak" (func $cbak))
|
||||
(export "hook" (func $hook)))
|
||||
)[test.hook]",
|
||||
{
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x18U,
|
||||
0x04U, 0x60U, 0x02U, 0x7FU, 0x7FU, 0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU,
|
||||
0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x60U,
|
||||
0x01U, 0x7EU, 0x01U, 0x7EU, 0x02U, 0x17U, 0x02U, 0x03U, 0x65U, 0x6EU,
|
||||
0x76U, 0x02U, 0x5FU, 0x67U, 0x00U, 0x00U, 0x03U, 0x65U, 0x6EU, 0x76U,
|
||||
0x06U, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x01U, 0x03U,
|
||||
0x04U, 0x03U, 0x02U, 0x03U, 0x03U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U,
|
||||
0x06U, 0x21U, 0x05U, 0x7FU, 0x01U, 0x41U, 0x80U, 0x88U, 0x04U, 0x0BU,
|
||||
0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U,
|
||||
0x08U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x88U, 0x04U, 0x0BU, 0x7FU,
|
||||
0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x07U, 0x08U, 0x01U, 0x04U, 0x68U,
|
||||
0x6FU, 0x6FU, 0x6BU, 0x00U, 0x02U, 0x0AU, 0xE3U, 0x80U, 0x00U, 0x03U,
|
||||
0x9FU, 0x80U, 0x00U, 0x00U, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x80U,
|
||||
0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x00U, 0x41U, 0x00U, 0x42U,
|
||||
0x05U, 0x10U, 0x83U, 0x80U, 0x80U, 0x80U, 0x00U, 0x10U, 0x81U, 0x80U,
|
||||
0x80U, 0x80U, 0x00U, 0x0BU, 0x9DU, 0x80U, 0x00U, 0x00U, 0x02U, 0x40U,
|
||||
0x20U, 0x00U, 0x42U, 0x01U, 0x59U, 0x0DU, 0x00U, 0x42U, 0x00U, 0x0FU,
|
||||
0x0BU, 0x20U, 0x00U, 0x42U, 0x7FU, 0x7CU, 0x10U, 0x84U, 0x80U, 0x80U,
|
||||
0x80U, 0x00U, 0x20U, 0x00U, 0x7CU, 0x0BU, 0x9DU, 0x80U, 0x00U, 0x00U,
|
||||
0x02U, 0x40U, 0x20U, 0x00U, 0x42U, 0x01U, 0x59U, 0x0DU, 0x00U, 0x42U,
|
||||
0x00U, 0x0FU, 0x0BU, 0x20U, 0x00U, 0x42U, 0x7FU, 0x7CU, 0x10U, 0x83U,
|
||||
0x80U, 0x80U, 0x80U, 0x00U, 0x20U, 0x00U, 0x7CU, 0x0BU,
|
||||
0x04U, 0x60U, 0x01U, 0x7EU, 0x01U, 0x7EU, 0x60U, 0x02U, 0x7FU, 0x7FU,
|
||||
0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU, 0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U,
|
||||
0x01U, 0x7FU, 0x01U, 0x7EU, 0x02U, 0x17U, 0x02U, 0x03U, 0x65U, 0x6EU,
|
||||
0x76U, 0x02U, 0x5FU, 0x67U, 0x00U, 0x01U, 0x03U, 0x65U, 0x6EU, 0x76U,
|
||||
0x06U, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x02U, 0x03U,
|
||||
0x05U, 0x04U, 0x00U, 0x00U, 0x03U, 0x03U, 0x07U, 0x0FU, 0x02U, 0x04U,
|
||||
0x63U, 0x62U, 0x61U, 0x6BU, 0x00U, 0x04U, 0x04U, 0x68U, 0x6FU, 0x6FU,
|
||||
0x6BU, 0x00U, 0x05U, 0x0AU, 0x65U, 0x04U, 0x17U, 0x00U, 0x20U, 0x00U,
|
||||
0x42U, 0x00U, 0x57U, 0x04U, 0x7EU, 0x42U, 0x00U, 0x05U, 0x20U, 0x00U,
|
||||
0x20U, 0x00U, 0x42U, 0x01U, 0x7DU, 0x10U, 0x03U, 0x7CU, 0x0BU, 0x0BU,
|
||||
0x17U, 0x00U, 0x20U, 0x00U, 0x42U, 0x00U, 0x57U, 0x04U, 0x7EU, 0x42U,
|
||||
0x00U, 0x05U, 0x20U, 0x00U, 0x20U, 0x00U, 0x42U, 0x01U, 0x7DU, 0x10U,
|
||||
0x02U, 0x7CU, 0x0BU, 0x0BU, 0x19U, 0x01U, 0x01U, 0x7EU, 0x41U, 0x01U,
|
||||
0x41U, 0x01U, 0x10U, 0x00U, 0x1AU, 0x42U, 0x05U, 0x10U, 0x03U, 0x21U,
|
||||
0x01U, 0x41U, 0x00U, 0x41U, 0x00U, 0x20U, 0x01U, 0x10U, 0x01U, 0x0BU,
|
||||
0x19U, 0x01U, 0x01U, 0x7EU, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x00U,
|
||||
0x1AU, 0x42U, 0x0AU, 0x10U, 0x03U, 0x21U, 0x01U, 0x41U, 0x00U, 0x41U,
|
||||
0x00U, 0x20U, 0x01U, 0x10U, 0x01U, 0x0BU,
|
||||
}},
|
||||
|
||||
/* ==== WASM: 10 ==== */
|
||||
{R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_d(int64_t n) {
|
||||
return n * 2;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_c(int64_t n) {
|
||||
return func_d(n) + 1;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_b(int64_t n) {
|
||||
return func_c(n) + 1;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t func_a(int64_t n) {
|
||||
return func_b(n) + 1;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = func_a(5);
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (result i64)))
|
||||
(type (;2;) (func (param i32 i32) (result i32)))
|
||||
(type (;3;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;4;) (func (param i64) (result i64)))
|
||||
(import "env" "hook_pos" (func (;0;) (type 1)))
|
||||
(import "env" "_g" (func (;1;) (type 2)))
|
||||
(import "env" "accept" (func (;2;) (type 3)))
|
||||
(func (;3;) (type 4) (param i64) (result i64)
|
||||
call 0
|
||||
local.get 0
|
||||
i64.add)
|
||||
(func (;4;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 1
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 34
|
||||
call 3
|
||||
call 2)
|
||||
(func (;5;) (type 0) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 1
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i64.const 5
|
||||
call 3
|
||||
call 2)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "cbak" (func 4))
|
||||
(export "hook" (func 5)))
|
||||
)[test.hook]",
|
||||
{
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x13U,
|
||||
0x03U, 0x60U, 0x02U, 0x7FU, 0x7FU, 0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU,
|
||||
0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x02U,
|
||||
0x17U, 0x02U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x02U, 0x5FU, 0x67U, 0x00U,
|
||||
0x00U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x06U, 0x61U, 0x63U, 0x63U, 0x65U,
|
||||
0x70U, 0x74U, 0x00U, 0x01U, 0x03U, 0x02U, 0x01U, 0x02U, 0x05U, 0x03U,
|
||||
0x01U, 0x00U, 0x02U, 0x06U, 0x21U, 0x05U, 0x7FU, 0x01U, 0x41U, 0x80U,
|
||||
0x88U, 0x04U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU,
|
||||
0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x88U,
|
||||
0x04U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU, 0x07U, 0x08U,
|
||||
0x01U, 0x04U, 0x68U, 0x6FU, 0x6FU, 0x6BU, 0x00U, 0x02U, 0x0AU, 0x9DU,
|
||||
0x80U, 0x00U, 0x01U, 0x99U, 0x80U, 0x00U, 0x00U, 0x41U, 0x01U, 0x41U,
|
||||
0x01U, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x00U,
|
||||
0x41U, 0x00U, 0x42U, 0x0DU, 0x10U, 0x81U, 0x80U, 0x80U, 0x80U, 0x00U,
|
||||
0x0BU,
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x1CU,
|
||||
0x05U, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x60U, 0x00U, 0x01U, 0x7EU,
|
||||
0x60U, 0x02U, 0x7FU, 0x7FU, 0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU, 0x7FU,
|
||||
0x7EU, 0x01U, 0x7EU, 0x60U, 0x01U, 0x7EU, 0x01U, 0x7EU, 0x02U, 0x26U,
|
||||
0x03U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x08U, 0x68U, 0x6FU, 0x6FU, 0x6BU,
|
||||
0x5FU, 0x70U, 0x6FU, 0x73U, 0x00U, 0x01U, 0x03U, 0x65U, 0x6EU, 0x76U,
|
||||
0x02U, 0x5FU, 0x67U, 0x00U, 0x02U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x06U,
|
||||
0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x03U, 0x03U, 0x04U,
|
||||
0x03U, 0x04U, 0x00U, 0x00U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U, 0x07U,
|
||||
0x18U, 0x03U, 0x06U, 0x6DU, 0x65U, 0x6DU, 0x6FU, 0x72U, 0x79U, 0x02U,
|
||||
0x00U, 0x04U, 0x63U, 0x62U, 0x61U, 0x6BU, 0x00U, 0x04U, 0x04U, 0x68U,
|
||||
0x6FU, 0x6FU, 0x6BU, 0x00U, 0x05U, 0x0AU, 0x31U, 0x03U, 0x07U, 0x00U,
|
||||
0x10U, 0x00U, 0x20U, 0x00U, 0x7CU, 0x0BU, 0x13U, 0x00U, 0x41U, 0x01U,
|
||||
0x41U, 0x01U, 0x10U, 0x01U, 0x1AU, 0x41U, 0x00U, 0x41U, 0x00U, 0x42U,
|
||||
0x22U, 0x10U, 0x03U, 0x10U, 0x02U, 0x0BU, 0x13U, 0x00U, 0x41U, 0x01U,
|
||||
0x41U, 0x01U, 0x10U, 0x01U, 0x1AU, 0x41U, 0x00U, 0x41U, 0x00U, 0x42U,
|
||||
0x05U, 0x10U, 0x03U, 0x10U, 0x02U, 0x0BU,
|
||||
}},
|
||||
|
||||
/* ==== WASM: 11 ==== */
|
||||
{R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t expensive_helper() {
|
||||
int64_t sum = 0;
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
_g(2, 101);
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = 0;
|
||||
result += expensive_helper();
|
||||
result += expensive_helper();
|
||||
result += expensive_helper();
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(type (;0;) (func (param i32 i32) (result i32)))
|
||||
(type (;1;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;2;) (func (param i32) (result i64)))
|
||||
(type (;3;) (func (result i64)))
|
||||
(import "env" "_g" (func (;0;) (type 0)))
|
||||
(import "env" "accept" (func (;1;) (type 1)))
|
||||
(func (;2;) (type 2) (param i32) (result i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
call 3
|
||||
call 3
|
||||
i64.add
|
||||
call 3
|
||||
i64.add
|
||||
call 1)
|
||||
(func (;3;) (type 3) (result i64)
|
||||
(local i64)
|
||||
i64.const 100
|
||||
local.set 0
|
||||
loop ;; label = @1
|
||||
i32.const 2
|
||||
i32.const 101
|
||||
call 0
|
||||
drop
|
||||
local.get 0
|
||||
i64.const 1
|
||||
i64.sub
|
||||
local.tee 0
|
||||
i64.eqz
|
||||
i32.eqz
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i64.const 4950)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "hook" (func 2)))
|
||||
)[test.hook]",
|
||||
{
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x17U,
|
||||
@@ -818,92 +934,135 @@ std::map<std::string, std::vector<uint8_t>> wasm = {
|
||||
0x00U, 0x01U, 0x7EU, 0x02U, 0x17U, 0x02U, 0x03U, 0x65U, 0x6EU, 0x76U,
|
||||
0x02U, 0x5FU, 0x67U, 0x00U, 0x00U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x06U,
|
||||
0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x01U, 0x03U, 0x03U,
|
||||
0x02U, 0x02U, 0x03U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U, 0x06U, 0x21U,
|
||||
0x05U, 0x7FU, 0x01U, 0x41U, 0x80U, 0x88U, 0x04U, 0x0BU, 0x7FU, 0x00U,
|
||||
0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU,
|
||||
0x7FU, 0x00U, 0x41U, 0x80U, 0x88U, 0x04U, 0x0BU, 0x7FU, 0x00U, 0x41U,
|
||||
0x80U, 0x08U, 0x0BU, 0x07U, 0x08U, 0x01U, 0x04U, 0x68U, 0x6FU, 0x6FU,
|
||||
0x6BU, 0x00U, 0x02U, 0x0AU, 0xD8U, 0x80U, 0x00U, 0x02U, 0xABU, 0x80U,
|
||||
0x00U, 0x00U, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x80U, 0x80U, 0x80U,
|
||||
0x80U, 0x00U, 0x1AU, 0x41U, 0x00U, 0x41U, 0x00U, 0x10U, 0x83U, 0x80U,
|
||||
0x80U, 0x80U, 0x00U, 0x10U, 0x83U, 0x80U, 0x80U, 0x80U, 0x00U, 0x7CU,
|
||||
0x10U, 0x83U, 0x80U, 0x80U, 0x80U, 0x00U, 0x7CU, 0x10U, 0x81U, 0x80U,
|
||||
0x80U, 0x80U, 0x00U, 0x0BU, 0xA6U, 0x80U, 0x00U, 0x01U, 0x01U, 0x7EU,
|
||||
0x42U, 0xE4U, 0x00U, 0x21U, 0x00U, 0x03U, 0x40U, 0x41U, 0x02U, 0x41U,
|
||||
0xE5U, 0x00U, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x20U,
|
||||
0x00U, 0x42U, 0x7FU, 0x7CU, 0x22U, 0x00U, 0x50U, 0x45U, 0x0DU, 0x00U,
|
||||
0x0BU, 0x42U, 0xD6U, 0x26U, 0x0BU,
|
||||
0x02U, 0x02U, 0x03U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U, 0x07U, 0x11U,
|
||||
0x02U, 0x06U, 0x6DU, 0x65U, 0x6DU, 0x6FU, 0x72U, 0x79U, 0x02U, 0x00U,
|
||||
0x04U, 0x68U, 0x6FU, 0x6FU, 0x6BU, 0x00U, 0x02U, 0x0AU, 0x3CU, 0x02U,
|
||||
0x17U, 0x00U, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x00U, 0x1AU, 0x41U,
|
||||
0x00U, 0x41U, 0x00U, 0x10U, 0x03U, 0x10U, 0x03U, 0x7CU, 0x10U, 0x03U,
|
||||
0x7CU, 0x10U, 0x01U, 0x0BU, 0x22U, 0x01U, 0x01U, 0x7EU, 0x42U, 0xE4U,
|
||||
0x00U, 0x21U, 0x00U, 0x03U, 0x40U, 0x41U, 0x02U, 0x41U, 0xE5U, 0x00U,
|
||||
0x10U, 0x00U, 0x1AU, 0x20U, 0x00U, 0x42U, 0x01U, 0x7DU, 0x22U, 0x00U,
|
||||
0x50U, 0x45U, 0x0DU, 0x00U, 0x0BU, 0x42U, 0xD6U, 0x26U, 0x0BU,
|
||||
}},
|
||||
|
||||
/* ==== WASM: 12 ==== */
|
||||
{R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g(uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept(uint32_t read_ptr, uint32_t read_len,
|
||||
int64_t error_code);
|
||||
|
||||
__attribute__((noinline))
|
||||
static int64_t large_helper() {
|
||||
int64_t sum = 0;
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
_g(2, 10001);
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int64_t hook(uint32_t reserved) {
|
||||
_g(1,1);
|
||||
int64_t result = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
_g(3, 11);
|
||||
result += large_helper();
|
||||
}
|
||||
return accept(0, 0, result);
|
||||
}
|
||||
(module
|
||||
(type (;0;) (func (param i32) (result i64)))
|
||||
(type (;1;) (func (param i32 i32) (result i32)))
|
||||
(type (;2;) (func (param i32 i32 i64) (result i64)))
|
||||
(type (;3;) (func (param i64) (result i64)))
|
||||
(import "env" "_g" (func (;0;) (type 1)))
|
||||
(import "env" "accept" (func (;1;) (type 2)))
|
||||
(func (;2;) (type 0) (param i32) (result i64)
|
||||
(local i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 10
|
||||
local.set 0
|
||||
i64.const 10
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
i32.const 3
|
||||
i32.const 11
|
||||
call 0
|
||||
drop
|
||||
i64.const 10
|
||||
call 3
|
||||
local.get 1
|
||||
i64.add
|
||||
local.set 1
|
||||
local.get 0
|
||||
i32.const 1
|
||||
i32.sub
|
||||
local.tee 0
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
local.get 1
|
||||
call 1)
|
||||
(func (;3;) (type 3) (param i64) (result i64)
|
||||
(local i64)
|
||||
i64.const 10000
|
||||
local.set 1
|
||||
loop ;; label = @1
|
||||
i32.const 2
|
||||
i32.const 10001
|
||||
call 0
|
||||
drop
|
||||
local.get 1
|
||||
i64.const 1
|
||||
i64.sub
|
||||
local.tee 1
|
||||
i64.eqz
|
||||
i32.eqz
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
local.get 0
|
||||
i64.const 49995000
|
||||
i64.add)
|
||||
(func (;4;) (type 0) (param i32) (result i64)
|
||||
(local i64)
|
||||
i32.const 1
|
||||
i32.const 1
|
||||
call 0
|
||||
drop
|
||||
i32.const 10
|
||||
local.set 0
|
||||
loop ;; label = @1
|
||||
i32.const 3
|
||||
i32.const 11
|
||||
call 0
|
||||
drop
|
||||
i64.const 0
|
||||
call 3
|
||||
local.get 1
|
||||
i64.add
|
||||
local.set 1
|
||||
local.get 0
|
||||
i32.const 1
|
||||
i32.sub
|
||||
local.tee 0
|
||||
br_if 0 (;@1;)
|
||||
end
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
local.get 1
|
||||
call 1)
|
||||
(memory (;0;) 2)
|
||||
(export "memory" (memory 0))
|
||||
(export "cbak" (func 2))
|
||||
(export "hook" (func 4)))
|
||||
)[test.hook]",
|
||||
{
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x17U,
|
||||
0x04U, 0x60U, 0x02U, 0x7FU, 0x7FU, 0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU,
|
||||
0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x60U,
|
||||
0x00U, 0x01U, 0x7EU, 0x02U, 0x17U, 0x02U, 0x03U, 0x65U, 0x6EU, 0x76U,
|
||||
0x02U, 0x5FU, 0x67U, 0x00U, 0x00U, 0x03U, 0x65U, 0x6EU, 0x76U, 0x06U,
|
||||
0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x01U, 0x03U, 0x03U,
|
||||
0x02U, 0x02U, 0x03U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U, 0x06U, 0x21U,
|
||||
0x05U, 0x7FU, 0x01U, 0x41U, 0x80U, 0x88U, 0x04U, 0x0BU, 0x7FU, 0x00U,
|
||||
0x41U, 0x80U, 0x08U, 0x0BU, 0x7FU, 0x00U, 0x41U, 0x80U, 0x08U, 0x0BU,
|
||||
0x7FU, 0x00U, 0x41U, 0x80U, 0x88U, 0x04U, 0x0BU, 0x7FU, 0x00U, 0x41U,
|
||||
0x80U, 0x08U, 0x0BU, 0x07U, 0x08U, 0x01U, 0x04U, 0x68U, 0x6FU, 0x6FU,
|
||||
0x6BU, 0x00U, 0x02U, 0x0AU, 0xA1U, 0x82U, 0x00U, 0x02U, 0xF0U, 0x81U,
|
||||
0x00U, 0x01U, 0x09U, 0x7EU, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x80U,
|
||||
0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x03U, 0x41U, 0x0BU, 0x10U,
|
||||
0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x10U, 0x83U, 0x80U, 0x80U,
|
||||
0x80U, 0x00U, 0x21U, 0x01U, 0x41U, 0x03U, 0x41U, 0x0BU, 0x10U, 0x80U,
|
||||
0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x10U, 0x83U, 0x80U, 0x80U, 0x80U,
|
||||
0x00U, 0x21U, 0x02U, 0x41U, 0x03U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U,
|
||||
0x80U, 0x80U, 0x00U, 0x1AU, 0x10U, 0x83U, 0x80U, 0x80U, 0x80U, 0x00U,
|
||||
0x21U, 0x03U, 0x41U, 0x03U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U,
|
||||
0x80U, 0x00U, 0x1AU, 0x10U, 0x83U, 0x80U, 0x80U, 0x80U, 0x00U, 0x21U,
|
||||
0x04U, 0x41U, 0x03U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U,
|
||||
0x00U, 0x1AU, 0x10U, 0x83U, 0x80U, 0x80U, 0x80U, 0x00U, 0x21U, 0x05U,
|
||||
0x41U, 0x03U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U,
|
||||
0x1AU, 0x10U, 0x83U, 0x80U, 0x80U, 0x80U, 0x00U, 0x21U, 0x06U, 0x41U,
|
||||
0x03U, 0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU,
|
||||
0x10U, 0x83U, 0x80U, 0x80U, 0x80U, 0x00U, 0x21U, 0x07U, 0x41U, 0x03U,
|
||||
0x41U, 0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x10U,
|
||||
0x83U, 0x80U, 0x80U, 0x80U, 0x00U, 0x21U, 0x08U, 0x41U, 0x03U, 0x41U,
|
||||
0x0BU, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x10U, 0x83U,
|
||||
0x80U, 0x80U, 0x80U, 0x00U, 0x21U, 0x09U, 0x41U, 0x03U, 0x41U, 0x0BU,
|
||||
0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x41U, 0x00U, 0x41U,
|
||||
0x00U, 0x10U, 0x83U, 0x80U, 0x80U, 0x80U, 0x00U, 0x20U, 0x09U, 0x20U,
|
||||
0x08U, 0x20U, 0x07U, 0x20U, 0x06U, 0x20U, 0x05U, 0x20U, 0x04U, 0x20U,
|
||||
0x03U, 0x20U, 0x02U, 0x20U, 0x01U, 0x7CU, 0x7CU, 0x7CU, 0x7CU, 0x7CU,
|
||||
0x7CU, 0x7CU, 0x7CU, 0x7CU, 0x10U, 0x81U, 0x80U, 0x80U, 0x80U, 0x00U,
|
||||
0x0BU, 0xAAU, 0x80U, 0x00U, 0x01U, 0x01U, 0x7EU, 0x42U, 0x90U, 0xCEU,
|
||||
0x00U, 0x21U, 0x00U, 0x03U, 0x40U, 0x41U, 0x02U, 0x41U, 0x91U, 0xCEU,
|
||||
0x00U, 0x10U, 0x80U, 0x80U, 0x80U, 0x80U, 0x00U, 0x1AU, 0x20U, 0x00U,
|
||||
0x42U, 0x7FU, 0x7CU, 0x22U, 0x00U, 0x50U, 0x45U, 0x0DU, 0x00U, 0x0BU,
|
||||
0x42U, 0xF8U, 0xB9U, 0xEBU, 0x17U, 0x0BU,
|
||||
0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U, 0x01U, 0x18U,
|
||||
0x04U, 0x60U, 0x01U, 0x7FU, 0x01U, 0x7EU, 0x60U, 0x02U, 0x7FU, 0x7FU,
|
||||
0x01U, 0x7FU, 0x60U, 0x03U, 0x7FU, 0x7FU, 0x7EU, 0x01U, 0x7EU, 0x60U,
|
||||
0x01U, 0x7EU, 0x01U, 0x7EU, 0x02U, 0x17U, 0x02U, 0x03U, 0x65U, 0x6EU,
|
||||
0x76U, 0x02U, 0x5FU, 0x67U, 0x00U, 0x01U, 0x03U, 0x65U, 0x6EU, 0x76U,
|
||||
0x06U, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x00U, 0x02U, 0x03U,
|
||||
0x04U, 0x03U, 0x00U, 0x03U, 0x00U, 0x05U, 0x03U, 0x01U, 0x00U, 0x02U,
|
||||
0x07U, 0x18U, 0x03U, 0x06U, 0x6DU, 0x65U, 0x6DU, 0x6FU, 0x72U, 0x79U,
|
||||
0x02U, 0x00U, 0x04U, 0x63U, 0x62U, 0x61U, 0x6BU, 0x00U, 0x02U, 0x04U,
|
||||
0x68U, 0x6FU, 0x6FU, 0x6BU, 0x00U, 0x04U, 0x0AU, 0x97U, 0x01U, 0x03U,
|
||||
0x37U, 0x01U, 0x01U, 0x7EU, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x00U,
|
||||
0x1AU, 0x41U, 0x0AU, 0x21U, 0x00U, 0x42U, 0x0AU, 0x21U, 0x01U, 0x03U,
|
||||
0x40U, 0x41U, 0x03U, 0x41U, 0x0BU, 0x10U, 0x00U, 0x1AU, 0x42U, 0x0AU,
|
||||
0x10U, 0x03U, 0x20U, 0x01U, 0x7CU, 0x21U, 0x01U, 0x20U, 0x00U, 0x41U,
|
||||
0x01U, 0x6BU, 0x22U, 0x00U, 0x0DU, 0x00U, 0x0BU, 0x41U, 0x00U, 0x41U,
|
||||
0x00U, 0x20U, 0x01U, 0x10U, 0x01U, 0x0BU, 0x29U, 0x01U, 0x01U, 0x7EU,
|
||||
0x42U, 0x90U, 0xCEU, 0x00U, 0x21U, 0x01U, 0x03U, 0x40U, 0x41U, 0x02U,
|
||||
0x41U, 0x91U, 0xCEU, 0x00U, 0x10U, 0x00U, 0x1AU, 0x20U, 0x01U, 0x42U,
|
||||
0x01U, 0x7DU, 0x22U, 0x01U, 0x50U, 0x45U, 0x0DU, 0x00U, 0x0BU, 0x20U,
|
||||
0x00U, 0x42U, 0xF8U, 0xB9U, 0xEBU, 0x17U, 0x7CU, 0x0BU, 0x33U, 0x01U,
|
||||
0x01U, 0x7EU, 0x41U, 0x01U, 0x41U, 0x01U, 0x10U, 0x00U, 0x1AU, 0x41U,
|
||||
0x0AU, 0x21U, 0x00U, 0x03U, 0x40U, 0x41U, 0x03U, 0x41U, 0x0BU, 0x10U,
|
||||
0x00U, 0x1AU, 0x42U, 0x00U, 0x10U, 0x03U, 0x20U, 0x01U, 0x7CU, 0x21U,
|
||||
0x01U, 0x20U, 0x00U, 0x41U, 0x01U, 0x6BU, 0x22U, 0x00U, 0x0DU, 0x00U,
|
||||
0x0BU, 0x41U, 0x00U, 0x41U, 0x00U, 0x20U, 0x01U, 0x10U, 0x01U, 0x0BU,
|
||||
}},
|
||||
|
||||
/* ==== WASM: 13 ==== */
|
||||
|
||||
Reference in New Issue
Block a user