|
| 1 | +// TODO: #![warn(missing_docs)] |
| 2 | +// TODO: #![warn(missing_doc_code_examples)] |
1 | 3 | //! Primitives for the eBPF instruction set. See [kernel docs](https://www.kernel.org/doc/html/latest/bpf/instruction-set.html) |
2 | 4 | //! for the canonical details |
3 | 5 | //! |
@@ -65,22 +67,48 @@ pub enum Class { |
65 | 67 | JMP32 = sys::BPF_JMP32 as u8, |
66 | 68 | } |
67 | 69 |
|
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. |
69 | 88 | /// |
70 | 89 | /// Source: [kernel tree](https://github.com/torvalds/linux/blob/d569e86915b7f2f9795588591c8d5ea0b66481cb/tools/include/uapi/linux/bpf.h#L53) |
71 | 90 | #[repr(u8)] |
72 | 91 | #[derive(Debug, TryFromPrimitive, IntoPrimitive, Clone, Copy, PartialEq, Eq, Hash)] |
73 | 92 | pub enum Register { |
74 | 93 | /// Usually used as either the return value in function calls or as the exit value in programs |
75 | 94 | R0 = sys::BPF_REG_0 as u8, |
| 95 | + /// |
76 | 96 | R1 = sys::BPF_REG_1 as u8, |
| 97 | + /// |
77 | 98 | R2 = sys::BPF_REG_2 as u8, |
| 99 | + /// |
78 | 100 | R3 = sys::BPF_REG_3 as u8, |
| 101 | + /// |
79 | 102 | R4 = sys::BPF_REG_4 as u8, |
| 103 | + /// |
80 | 104 | R5 = sys::BPF_REG_5 as u8, |
| 105 | + /// |
81 | 106 | R6 = sys::BPF_REG_6 as u8, |
| 107 | + /// |
82 | 108 | R7 = sys::BPF_REG_7 as u8, |
| 109 | + /// |
83 | 110 | R8 = sys::BPF_REG_8 as u8, |
| 111 | + /// |
84 | 112 | R9 = sys::BPF_REG_9 as u8, |
85 | 113 | /// Read-only frame pointer register |
86 | 114 | R10 = sys::BPF_REG_10 as u8, |
|
0 commit comments