diff --git a/examples/allowed-memory.o b/examples/allowed-memory.o deleted file mode 100644 index 4b15bef5..00000000 Binary files a/examples/allowed-memory.o and /dev/null differ diff --git a/examples/allowed-memory/.cargo/config.toml b/examples/allowed-memory/.cargo/config.toml new file mode 100644 index 00000000..8092581e --- /dev/null +++ b/examples/allowed-memory/.cargo/config.toml @@ -0,0 +1,6 @@ +[build] +target = "bpfel-unknown-none" +rustflags = "-C debuginfo=2 -C link-arg=--btf" + +[unstable] +build-std = ["core"] diff --git a/examples/allowed-memory/Cargo.toml b/examples/allowed-memory/Cargo.toml new file mode 100644 index 00000000..ee7a6d03 --- /dev/null +++ b/examples/allowed-memory/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "allowed-memory" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0/MIT" + +[dependencies] +aya-ebpf = "0.1.0" + +[[bin]] +name = "allowed-memory" +path = "src/main.rs" +test = false +bench = false + +[profile.dev] +opt-level = 3 +debug = false +debug-assertions = false +overflow-checks = false +lto = true +panic = "abort" +incremental = false +codegen-units = 1 +rpath = false + +[profile.release] +lto = true +panic = "abort" +codegen-units = 1 + diff --git a/examples/allowed-memory/allowed-memory.o b/examples/allowed-memory/allowed-memory.o new file mode 100644 index 00000000..b6429c37 Binary files /dev/null and b/examples/allowed-memory/allowed-memory.o differ diff --git a/examples/allowed-memory/rust-toolchain.toml b/examples/allowed-memory/rust-toolchain.toml new file mode 100644 index 00000000..24ce3918 --- /dev/null +++ b/examples/allowed-memory/rust-toolchain.toml @@ -0,0 +1,13 @@ +[toolchain] +channel = "nightly" +# The source code of rustc, provided by the rust-src component, is needed for +# building eBPF programs. +components = [ + "cargo", + "clippy", + "rust-docs", + "rust-src", + "rust-std", + "rustc", + "rustfmt", +] diff --git a/examples/ebpf-allowed-memory.rs b/examples/allowed-memory/src/main.rs similarity index 100% rename from examples/ebpf-allowed-memory.rs rename to examples/allowed-memory/src/main.rs diff --git a/examples/allowed_memory.rs b/examples/allowed_memory.rs index 554f5fe3..cd84c241 100644 --- a/examples/allowed_memory.rs +++ b/examples/allowed_memory.rs @@ -8,14 +8,7 @@ use std::{iter::FromIterator, ptr::addr_of}; extern crate rbpf; -// The following example uses an ELF file that was compiled from the ebpf-allowed-memory.rs file -// It is built using the [aya framework](https://aya-rs.dev/). -// Once the aya dependencies (rust-nightly, latest llvm and latest bpf-linker) are installed, it -// can be compiled via -// -// ```bash -// cargo build --target=bpfel-unknown-none -Z build-std=core -// ``` +const OBJ_FILE_PATH: &str = "examples/allowed-memory/allowed-memory.o"; const BPF_MAP_LOOKUP_ELEM_IDX: u32 = 1; @@ -41,7 +34,7 @@ fn bpf_lookup_elem(_map: u64, key_addr: u64, _flags: u64, _u4: u64, _u5: u64) -> } fn main() { - let file = elf::File::open_path("examples/allowed-memory.o").unwrap(); + let file = elf::File::open_path(OBJ_FILE_PATH).unwrap(); let func = file.get_section("classifier").unwrap(); let mut vm = rbpf::EbpfVmNoData::new(Some(&func.data)).unwrap();