Skip to content

Commit 1c52c44

Browse files
committed
bpf-rs: ebpf register docs
Signed-off-by: Milan <[email protected]>
1 parent ea30c23 commit 1c52c44

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

bpf-rs/src/insns.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: #![warn(missing_docs)]
2+
// TODO: #![warn(missing_doc_code_examples)]
13
//! Primitives for the eBPF instruction set. See [kernel docs](https://www.kernel.org/doc/html/latest/bpf/instruction-set.html)
24
//! for the canonical details
35
//!
@@ -65,22 +67,48 @@ pub enum Class {
6567
JMP32 = sys::BPF_JMP32 as u8,
6668
}
6769

68-
/// Register variants
70+
/// # eBPF Registers
71+
///
72+
/// Quoting the [kernel documentation](https://www.kernel.org/doc/html/latest/bpf/instruction-set.html#registers-and-calling-convention)
73+
/// on eBPF registers:
74+
///
75+
/// > eBPF has **10 general purpose registers** and a read-only frame pointer register, all of which are 64-bits wide.
76+
/// >
77+
/// > The eBPF calling convention is defined as:
78+
/// >
79+
/// > - `R0`: return value from function calls, and exit value for eBPF programs
80+
/// >
81+
/// > - `R1` - `R5`: arguments for function calls
82+
/// >
83+
/// > - `R6` - `R9`: callee saved registers that function calls will preserve
84+
/// >
85+
/// > - `R10`: read-only frame pointer to access stack
86+
/// >
87+
/// > `R0` - `R5` are scratch registers and eBPF programs needs to spill/fill them if necessary across calls.
6988
///
7089
/// Source: [kernel tree](https://github.com/torvalds/linux/blob/d569e86915b7f2f9795588591c8d5ea0b66481cb/tools/include/uapi/linux/bpf.h#L53)
7190
#[repr(u8)]
7291
#[derive(Debug, TryFromPrimitive, IntoPrimitive, Clone, Copy, PartialEq, Eq, Hash)]
7392
pub enum Register {
7493
/// Usually used as either the return value in function calls or as the exit value in programs
7594
R0 = sys::BPF_REG_0 as u8,
95+
///
7696
R1 = sys::BPF_REG_1 as u8,
97+
///
7798
R2 = sys::BPF_REG_2 as u8,
99+
///
78100
R3 = sys::BPF_REG_3 as u8,
101+
///
79102
R4 = sys::BPF_REG_4 as u8,
103+
///
80104
R5 = sys::BPF_REG_5 as u8,
105+
///
81106
R6 = sys::BPF_REG_6 as u8,
107+
///
82108
R7 = sys::BPF_REG_7 as u8,
109+
///
83110
R8 = sys::BPF_REG_8 as u8,
111+
///
84112
R9 = sys::BPF_REG_9 as u8,
85113
/// Read-only frame pointer register
86114
R10 = sys::BPF_REG_10 as u8,

bpf-rs/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use thiserror::Error as ThisError;
2626

2727
pub use libbpf_sys;
2828

29+
/// Propagates error variants from libbpf-sys
2930
#[derive(ThisError, Debug)]
3031
pub enum Error {
3132
#[error("errno: {0}")]
@@ -36,7 +37,7 @@ pub enum Error {
3637
Unknown(i32),
3738
}
3839

39-
// Highly coupled to the proc macro bpf_rs_macros::Derive
40+
// WARNING: Highly coupled to the proc macro bpf_rs_macros::Derive
4041
trait StaticName {
4142
fn name(&self) -> &'static str;
4243
}

0 commit comments

Comments
 (0)