From 7dd2e3d1f87559636ba33a7bbb76e57f20d43e8e Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Mon, 7 Mar 2022 10:11:30 +0000 Subject: [PATCH] bpf: Improve documentation of set_global method Use `static` instead of `const` and mention the necessity of using `core::ptr::read_volatile`. Signed-off-by: Michal Rostecki --- aya/src/bpf.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index afedf3ed..656d8bd7 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -222,9 +222,18 @@ impl<'a> BpfLoader<'a> { /// Sets the value of a global variable /// /// From Rust eBPF, a global variable would be constructed as follows: - /// ```no run + /// ```no_run /// #[no_mangle] - /// const VERSION = 0; + /// static VERSION: i32 = 0; + /// ``` + /// Then it would be accessed with `core::ptr::read_volatile` inside + /// functions: + /// ```no_run + /// # #[no_mangle] + /// # static VERSION: i32 = 0; + /// # unsafe fn try_test() { + /// let version = core::ptr::read_volatile(&VERSION); + /// # } /// ``` /// If using a struct, ensure that it is `#[repr(C)]` to ensure the size will /// match that of the corresponding ELF symbol.