Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Fix naming and assembler
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Oct 11, 2024
1 parent 415fc80 commit d0466fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,15 @@ fn make_instruction_map(sbpf_version: SBPFVersion) -> HashMap<String, (Instructi

// Miscellaneous.
entry("ja", JumpUnconditional, ebpf::JA);
if sbpf_version == SBPFVersion::V1 {
entry("syscall", Syscall, ebpf::CALL_IMM);
} else {
entry("syscall", Syscall, ebpf::SYSCALL);
}
entry(
"syscall",
Syscall,
if sbpf_version == SBPFVersion::V1 {
ebpf::CALL_IMM
} else {
ebpf::SYSCALL
},
);
entry("call", CallImm, ebpf::CALL_IMM);
entry("callx", CallReg, ebpf::CALL_REG);
entry("lddw", LoadDwImm, ebpf::LD_DW_IMM);
Expand Down
12 changes: 7 additions & 5 deletions src/ebpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ pub const BPF_JSGT: u8 = 0x60;
pub const BPF_JSGE: u8 = 0x70;
/// BPF JMP operation code: syscall function call.
pub const BPF_CALL: u8 = 0x80;
/// BPF JMP operation code: return from program (V1) or syscall (V2).
pub const BPF_EXIT_SYSCALL: u8 = 0x90;
/// BPF JMP operation code: return from program (V1).
pub const BPF_EXIT: u8 = 0x90;
/// BPF JMP operation code: static syscall (V2).
pub const BPF_SYSCALL: u8 = 0x90;
/// BPF JMP operation code: jump if lower than.
pub const BPF_JLT: u8 = 0xa0;
/// BPF JMP operation code: jump if lower or equal.
Expand Down Expand Up @@ -481,11 +483,11 @@ pub const CALL_IMM: u8 = BPF_JMP | BPF_CALL;
/// BPF opcode: tail call.
pub const CALL_REG: u8 = BPF_JMP | BPF_X | BPF_CALL;
/// BPF opcode: `exit` /// `return r0`. /// Valid only for SBPFv1
pub const EXIT: u8 = BPF_JMP | BPF_EXIT_SYSCALL;
pub const EXIT: u8 = BPF_JMP | BPF_EXIT;
/// BPF opcode: `return` /// `return r0`. /// Valid only for SBPFv2
pub const RETURN: u8 = BPF_JMP | BPF_X | BPF_EXIT_SYSCALL;
pub const RETURN: u8 = BPF_JMP | BPF_X | BPF_EXIT;
/// BPF opcode: `syscall` /// `syscall imm`. /// Valid only for SBPFv2
pub const SYSCALL: u8 = BPF_JMP | BPF_EXIT_SYSCALL;
pub const SYSCALL: u8 = BPF_JMP | BPF_SYSCALL;

// Used in JIT
/// Mask to extract the operation class from an operation code.
Expand Down
2 changes: 1 addition & 1 deletion src/insn_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ impl<'i> Exit<'i> {

impl Instruction for Exit<'_> {
fn opt_code_byte(&self) -> u8 {
BPF_EXIT_SYSCALL | BPF_JMP
BPF_EXIT | BPF_JMP
}

fn get_insn_mut(&mut self) -> &mut Insn {
Expand Down

0 comments on commit d0466fe

Please sign in to comment.