Skip to content

Commit

Permalink
Renames MM_PROGRAM_START => MM_RODATA_START.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Oct 15, 2024
1 parent 9f1ec04 commit eda17c6
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 112 deletions.
4 changes: 2 additions & 2 deletions src/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ fn get_host_ptr<C: ContextObject>(
interpreter: &mut Interpreter<C>,
mut vm_addr: u64,
) -> Result<*mut u8, EbpfError> {
if vm_addr < ebpf::MM_PROGRAM_START {
vm_addr += ebpf::MM_PROGRAM_START;
if vm_addr < ebpf::MM_RODATA_START {
vm_addr += ebpf::MM_RODATA_START;
}
match interpreter.vm.memory_mapping.map(
AccessType::Load,
Expand Down
23 changes: 12 additions & 11 deletions src/ebpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ pub const HOST_ALIGN: usize = 16;
/// Upper half of a pointer is the region index, lower half the virtual address inside that region.
pub const VIRTUAL_ADDRESS_BITS: usize = 32;

// Memory map regions virtual addresses need to be (1 << VIRTUAL_ADDRESS_BITS) bytes apart.
// Also the region at index 0 should be skipped to catch NULL ptr accesses.

/// Start of the program bits (text and ro segments) in the memory map
pub const MM_PROGRAM_START: u64 = 0x100000000;
/// Start of the stack in the memory map
pub const MM_STACK_START: u64 = 0x200000000;
/// Start of the heap in the memory map
pub const MM_HEAP_START: u64 = 0x300000000;
/// Start of the input buffers in the memory map
pub const MM_INPUT_START: u64 = 0x400000000;
/// Size (and alignment) of a memory region
pub const MM_REGION_SIZE: u64 = 1 << VIRTUAL_ADDRESS_BITS;
/// Virtual address of the bytecode region (not available in SBPFv1)
pub const MM_BYTECODE_START: u64 = 0;
/// Virtual address of the readonly data region (also contains the bytecode in SBPFv1)
pub const MM_RODATA_START: u64 = MM_REGION_SIZE;
/// Virtual address of the stack region
pub const MM_STACK_START: u64 = MM_REGION_SIZE * 2;
/// Virtual address of the heap region
pub const MM_HEAP_START: u64 = MM_REGION_SIZE * 3;
/// Virtual address of the input region
pub const MM_INPUT_START: u64 = MM_REGION_SIZE * 4;

// eBPF op codes.
// See also https://www.kernel.org/doc/Documentation/networking/filter.txt
Expand Down
Loading

0 comments on commit eda17c6

Please sign in to comment.