diff --git a/lib/dynasm-backend/src/codegen_x64.rs b/lib/dynasm-backend/src/codegen_x64.rs index 09c8059c8..1e45fcde5 100644 --- a/lib/dynasm-backend/src/codegen_x64.rs +++ b/lib/dynasm-backend/src/codegen_x64.rs @@ -83,7 +83,9 @@ lazy_static! { ; push r14 ; push r13 ; push r12 - ; sub rsp, 8 // align to 16 bytes + ; push r11 + ; push rbp + ; mov rbp, rsp ; mov r15, rdi ; mov r14, rsi @@ -95,34 +97,56 @@ lazy_static! { ; sub r14, 8 ; cmp r14, r15 ; jb >stack_ready + ; mov rsi, [r14] - ; sub r14, 8 ; cmp r14, r15 ; jb >stack_ready + ; mov rdx, [r14] - ; sub r14, 8 ; cmp r14, r15 ; jb >stack_ready + ; mov rcx, [r14] - ; sub r14, 8 ; cmp r14, r15 ; jb >stack_ready + ; mov r8, [r14] - ; sub r14, 8 ; cmp r14, r15 ; jb >stack_ready - ; mov r9, [r14] - ; ud2 // FIXME + ; mov r9, [r14] + ; sub r14, 8 + ; cmp r14, r15 + ; jb >stack_ready + + ; mov rax, r14 + ; sub rax, r15 + ; sub rsp, rax + ; sub rsp, 8 + ; mov rax, QWORD 0xfffffffffffffff0u64 as i64 + ; and rsp, rax + ; mov rax, rsp + ; loop_begin: + ; mov r11, [r14] + ; mov [rax], r11 + ; sub r14, 8 + ; add rax, 8 + ; cmp r14, r15 + ; jb >stack_ready + ; jmp x, - None => { - eprintln!("empty table entry"); - protect_unix::trigger_trap(); - } - }; + if anyfunc.func.is_null() { + eprintln!("null anyfunc"); + protect_unix::trigger_trap(); + } - if ctx.signatures[SigIndex::new(sig_index)] - != ctx.signatures[ctx.function_signatures[func_index]] - { + if anyfunc.sig_id.0 != dynamic_sigindex.0 { eprintln!("signature mismatch"); protect_unix::trigger_trap(); } - let func = ctx.function_pointers[func_index.index() as usize].0; - CALL_WASM( - stack_top, - stack_base as usize - stack_top as usize, - func as _, - memory_base, - vmctx, - ) as u64 + CONSTRUCT_STACK_AND_CALL_NATIVE(stack_top, stack_base, anyfunc.ctx, anyfunc.func) } #[repr(u64)] diff --git a/lib/dynasm-backend/src/lib.rs b/lib/dynasm-backend/src/lib.rs index 088aa42ce..5eb91f8e5 100644 --- a/lib/dynasm-backend/src/lib.rs +++ b/lib/dynasm-backend/src/lib.rs @@ -46,16 +46,6 @@ impl CacheGen for Placeholder { } } -impl FuncResolver for Placeholder { - fn get( - &self, - _module: &ModuleInner, - _local_func_index: LocalFuncIndex, - ) -> Option> { - NonNull::new(0x3f3f3f3f3f3f3f3fusize as *mut vm::Func) - } -} - pub struct SinglePassCompiler {} impl SinglePassCompiler { pub fn new() -> Self { diff --git a/lib/runtime-core/src/backing.rs b/lib/runtime-core/src/backing.rs index 2c9630764..856d6770e 100644 --- a/lib/runtime-core/src/backing.rs +++ b/lib/runtime-core/src/backing.rs @@ -234,7 +234,6 @@ impl LocalBacking { func, ctx, sig_id, - func_index: Some(func_index), }; } }); @@ -278,7 +277,6 @@ impl LocalBacking { func, ctx, sig_id, - func_index: Some(func_index), }; } }); diff --git a/lib/runtime-core/src/table/anyfunc.rs b/lib/runtime-core/src/table/anyfunc.rs index 8312e2506..789f67ada 100644 --- a/lib/runtime-core/src/table/anyfunc.rs +++ b/lib/runtime-core/src/table/anyfunc.rs @@ -107,7 +107,6 @@ impl AnyfuncTable { func: ptr, ctx: ptr::null_mut(), sig_id, - func_index: None, } } AnyfuncInner::Managed(ref func) => { @@ -118,7 +117,6 @@ impl AnyfuncTable { func: func.raw(), ctx: func.instance_inner.vmctx, sig_id, - func_index: Some(func.func_index), } } }; diff --git a/lib/runtime-core/src/vm.rs b/lib/runtime-core/src/vm.rs index b668833cd..6e2a48aa1 100644 --- a/lib/runtime-core/src/vm.rs +++ b/lib/runtime-core/src/vm.rs @@ -38,7 +38,7 @@ pub struct Ctx { /// from a static, module-local signature id to a runtime-global /// signature id. This is used to allow call-indirect to other /// modules safely. - pub(crate) dynamic_sigindices: *const SigId, + pub dynamic_sigindices: *const SigId, pub(crate) local_functions: *const *const Func, @@ -302,7 +302,6 @@ pub struct Anyfunc { pub func: *const Func, pub ctx: *mut Ctx, pub sig_id: SigId, - pub func_index: Option, } impl Anyfunc { @@ -311,7 +310,6 @@ impl Anyfunc { func: ptr::null(), ctx: ptr::null_mut(), sig_id: SigId(u32::max_value()), - func_index: None, } }