Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor - Adds macro declare_builtin_function #530

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/elf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use test::Bencher;
fn loader() -> Arc<BuiltinProgram<TestContextObject>> {
let mut function_registry = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry
.register_function_hashed(*b"log", syscalls::bpf_syscall_string)
.register_function_hashed(*b"log", syscalls::SyscallString::vm)
.unwrap();
Arc::new(BuiltinProgram::new_loader(
Config::default(),
Expand Down
4 changes: 2 additions & 2 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,10 +1203,10 @@ mod test {
let mut function_registry =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry
.register_function_hashed(*b"log", syscalls::bpf_syscall_string)
.register_function_hashed(*b"log", syscalls::SyscallString::vm)
.unwrap();
function_registry
.register_function_hashed(*b"log_64", syscalls::bpf_syscall_u64)
.register_function_hashed(*b"log_64", syscalls::SyscallU64::vm)
.unwrap();
Arc::new(BuiltinProgram::new_loader(
Config::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ mod tests {
let mut function_registry =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry
.register_function_hashed(*b"gather_bytes", syscalls::bpf_gather_bytes)
.register_function_hashed(*b"gather_bytes", syscalls::SyscallGatherBytes::vm)
.unwrap();
let loader = BuiltinProgram::new_loader(
Config {
Expand Down
30 changes: 30 additions & 0 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,33 @@ impl<C: ContextObject> std::fmt::Debug for BuiltinProgram<C> {
Ok(())
}
}

/// Generates an adapter for a BuiltinFunction between the Rust and the VM interface
#[macro_export]
macro_rules! declare_builtin_function {
($(#[$attr:meta])* $name:ident, $rust:item) => {
$(#[$attr])*
pub struct $name {}
impl $name {
/// Rust interface
$rust
/// VM interface
#[allow(clippy::too_many_arguments)]
pub fn vm(
context_object: &mut TestContextObject,
arg_a: u64,
arg_b: u64,
arg_c: u64,
arg_d: u64,
arg_e: u64,
memory_mapping: &mut $crate::memory_region::MemoryMapping,
program_result: &mut $crate::vm::ProgramResult,
) {
let converted_result: $crate::vm::ProgramResult = Self::rust(
context_object, arg_a, arg_b, arg_c, arg_d, arg_e, memory_mapping,
).into();
*program_result = converted_result;
}
}
};
}
Loading