mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-20 12:16:30 +00:00
feat(clif-backend,singlepass-backend) Feed imported functions with FuncCtx.vmctx
.
This commit is contained in:
@ -776,7 +776,7 @@ impl FuncEnvironment for FunctionEnvironment {
|
|||||||
let imported_func_ctx_vmctx_addr =
|
let imported_func_ctx_vmctx_addr =
|
||||||
pos.func.create_global_value(ir::GlobalValueData::Load {
|
pos.func.create_global_value(ir::GlobalValueData::Load {
|
||||||
base: imported_func_ctx_addr,
|
base: imported_func_ctx_addr,
|
||||||
offset: (0 as i32).into(),
|
offset: (vm::FuncCtx::offset_vmctx() as i32).into(),
|
||||||
global_type: ptr_type,
|
global_type: ptr_type,
|
||||||
readonly: true,
|
readonly: true,
|
||||||
});
|
});
|
||||||
|
@ -518,7 +518,7 @@ pub struct FuncEnv {
|
|||||||
/// only.
|
/// only.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub(crate) struct FuncCtx {
|
pub struct FuncCtx {
|
||||||
/// The `Ctx` pointer.
|
/// The `Ctx` pointer.
|
||||||
pub(crate) vmctx: NonNull<Ctx>,
|
pub(crate) vmctx: NonNull<Ctx>,
|
||||||
|
|
||||||
@ -529,6 +529,20 @@ pub(crate) struct FuncCtx {
|
|||||||
pub(crate) func_env: Option<NonNull<FuncEnv>>,
|
pub(crate) func_env: Option<NonNull<FuncEnv>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FuncCtx {
|
||||||
|
pub fn offset_vmctx() -> u8 {
|
||||||
|
0 * (mem::size_of::<usize>() as u8)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn offset_func_env() -> u8 {
|
||||||
|
1 * (mem::size_of::<usize>() as u8)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size() -> u8 {
|
||||||
|
mem::size_of::<Self>() as u8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An imported function is a function pointer associated to a
|
/// An imported function is a function pointer associated to a
|
||||||
/// function context.
|
/// function context.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -687,7 +701,9 @@ impl Anyfunc {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod vm_offset_tests {
|
mod vm_offset_tests {
|
||||||
use super::{Anyfunc, Ctx, ImportedFunc, InternalCtx, LocalGlobal, LocalMemory, LocalTable};
|
use super::{
|
||||||
|
Anyfunc, Ctx, FuncCtx, ImportedFunc, InternalCtx, LocalGlobal, LocalMemory, LocalTable,
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn vmctx() {
|
fn vmctx() {
|
||||||
@ -764,6 +780,19 @@ mod vm_offset_tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn func_ctx() {
|
||||||
|
assert_eq!(
|
||||||
|
FuncCtx::offset_vmctx() as usize,
|
||||||
|
offset_of!(FuncCtx => vmctx).get_byte_offset(),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
FuncCtx::offset_func_env() as usize,
|
||||||
|
offset_of!(FuncCtx => func_env).get_byte_offset(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn imported_func() {
|
fn imported_func() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -558,6 +558,7 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
|
|||||||
let imported_func = vm::ImportedFunc::size() as usize * id;
|
let imported_func = vm::ImportedFunc::size() as usize * id;
|
||||||
let imported_func_addr = imported_func + vm::ImportedFunc::offset_func() as usize;
|
let imported_func_addr = imported_func + vm::ImportedFunc::offset_func() as usize;
|
||||||
let imported_func_ctx_addr = imported_func + vm::ImportedFunc::offset_func_ctx() as usize;
|
let imported_func_ctx_addr = imported_func + vm::ImportedFunc::offset_func_ctx() as usize;
|
||||||
|
let imported_func_ctx_vmctx_addr = vm::FuncCtx::offset_vmctx() as usize;
|
||||||
|
|
||||||
a.emit_mov(
|
a.emit_mov(
|
||||||
Size::S64,
|
Size::S64,
|
||||||
@ -569,6 +570,11 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
|
|||||||
Location::Memory(GPR::RAX, imported_func_ctx_addr as i32),
|
Location::Memory(GPR::RAX, imported_func_ctx_addr as i32),
|
||||||
Location::GPR(GPR::RDI),
|
Location::GPR(GPR::RDI),
|
||||||
);
|
);
|
||||||
|
a.emit_mov(
|
||||||
|
Size::S64,
|
||||||
|
Location::Memory(GPR::RDI, imported_func_ctx_vmctx_addr as i32),
|
||||||
|
Location::GPR(GPR::RDI),
|
||||||
|
);
|
||||||
a.emit_mov(
|
a.emit_mov(
|
||||||
Size::S64,
|
Size::S64,
|
||||||
Location::Memory(GPR::RAX, imported_func_addr as i32),
|
Location::Memory(GPR::RAX, imported_func_addr as i32),
|
||||||
|
Reference in New Issue
Block a user