Add clippy coverage for doctests

pull/1386/head
Tamir Duberstein 1 week ago
parent 18c7f7ccd6
commit 112ab47fcd
No known key found for this signature in database

@ -119,29 +119,26 @@ jobs:
RUST_BACKTRACE: full RUST_BACKTRACE: full
run: | run: |
set -euxo pipefail set -euxo pipefail
cargo hack test --all-targets --feature-powerset \ cargo hack test --all-targets \
--exclude aya-ebpf \ --exclude aya-ebpf \
--exclude aya-ebpf-bindings \ --exclude aya-ebpf-bindings \
--exclude aya-log-ebpf \ --exclude aya-log-ebpf \
--exclude integration-ebpf \ --exclude integration-ebpf \
--exclude integration-test \ --exclude integration-test \
--exclude xtask \ --feature-powerset
--workspace
- name: Doctests - name: Doctests
env: env:
RUST_BACKTRACE: full RUST_BACKTRACE: full
run: | run: |
set -euxo pipefail set -euxo pipefail
cargo hack test --doc --feature-powerset \ cargo hack test --doc \
--exclude aya-ebpf \ --exclude aya-ebpf \
--exclude aya-ebpf-bindings \ --exclude aya-ebpf-bindings \
--exclude aya-log-ebpf \ --exclude aya-log-ebpf \
--exclude init \
--exclude integration-ebpf \ --exclude integration-ebpf \
--exclude integration-test \ --exclude integration-test \
--exclude xtask \ --feature-powerset
--workspace
build-test-aya-ebpf: build-test-aya-ebpf:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -175,35 +172,44 @@ jobs:
# to the overhead of setting up the job - so this saves a bunch of # to the overhead of setting up the job - so this saves a bunch of
# machine time. # machine time.
for arch in aarch64 arm loongarch64 mips powerpc64 riscv64 s390x x86_64; do for arch in aarch64 arm loongarch64 mips powerpc64 riscv64 s390x x86_64; do
echo "::group::arch=$arch"
export RUSTFLAGS="--cfg bpf_target_arch=\"$arch\""
for target in bpfeb-unknown-none bpfel-unknown-none; do for target in bpfeb-unknown-none bpfel-unknown-none; do
echo "::group::Build and test for $arch / $target" echo "::group::target=$target"
if ! ( if ! (
cargo +nightly hack build \
RUSTFLAGS="--cfg bpf_target_arch=\"$arch\"" cargo +nightly hack build \ --release \
--target "$target" \ --target "$target" \
-Z build-std=core \ -Z build-std=core \
--package aya-ebpf \ --package aya-ebpf \
--package aya-ebpf-bindings \
--package aya-log-ebpf \ --package aya-log-ebpf \
--package integration-ebpf \
--feature-powerset --feature-powerset
); then
cargo hack test \ failures+=("build: $arch/$target")
--doc \ fi
echo "::endgroup::"
done
if ! (
RUSTDOCFLAGS=$RUSTFLAGS cargo +nightly hack test --doc \
--package aya-ebpf \ --package aya-ebpf \
--package aya-ebpf-bindings \
--package aya-log-ebpf \ --package aya-log-ebpf \
--package integration-ebpf \
--feature-powerset --feature-powerset
); then ); then
echo "FAILED: $arch / $target" failures+=("doctests: $arch")
failures+=("$arch/$target")
fi fi
echo "::endgroup::" echo "::endgroup::"
done done
done
if ((${#failures[@]})); then if ((${#failures[@]})); then
echo "::error::Some builds/tests failed:" echo "::error::Some builds/tests failed:"
printf ' %s\n' "${failures[@]}" printf ' %s\n' "${failures[@]}"
exit 1 exit 1
fi fi
run-integration-test: run-integration-test:
strategy: strategy:
fail-fast: false fail-fast: false

@ -216,14 +216,11 @@ pub fn cgroup_skb(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// pub fn connect4(ctx: SockAddrContext) -> i32 { /// pub fn connect4(ctx: SockAddrContext) -> i32 {
/// match try_connect4(ctx) { /// match try_connect4(ctx) {
/// Ok(ret) => ret, /// Ok(ret) => ret,
/// Err(ret) => match ret.try_into() { /// Err(ret) => ret,
/// Ok(rt) => rt,
/// Err(_) => 1,
/// },
/// } /// }
/// } /// }
/// ///
/// fn try_connect4(ctx: SockAddrContext) -> Result<i32, i64> { /// fn try_connect4(ctx: SockAddrContext) -> Result<i32, i32> {
/// Ok(0) /// Ok(0)
/// } /// }
/// ``` /// ```
@ -440,7 +437,7 @@ pub fn btf_tracepoint(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// ///
///#[stream_parser] ///#[stream_parser]
///fn stream_parser(ctx: SkBuffContext) -> u32 { ///fn stream_parser(ctx: SkBuffContext) -> u32 {
/// match { try_stream_parser(ctx) } { /// match try_stream_parser(ctx) {
/// Ok(ret) => ret, /// Ok(ret) => ret,
/// Err(ret) => ret, /// Err(ret) => ret,
/// } /// }
@ -470,7 +467,7 @@ pub fn stream_parser(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// ///
///#[stream_verdict] ///#[stream_verdict]
///fn stream_verdict(ctx: SkBuffContext) -> u32 { ///fn stream_verdict(ctx: SkBuffContext) -> u32 {
/// match { try_stream_verdict(ctx) } { /// match try_stream_verdict(ctx) {
/// Ok(ret) => ret, /// Ok(ret) => ret,
/// Err(ret) => ret, /// Err(ret) => ret,
/// } /// }
@ -507,7 +504,7 @@ fn sk_skb(kind: SkSkbKind, attrs: TokenStream, item: TokenStream) -> TokenStream
/// ///
/// #[socket_filter] /// #[socket_filter]
/// pub fn accept_all(_ctx: SkBuffContext) -> i64 { /// pub fn accept_all(_ctx: SkBuffContext) -> i64 {
/// return 0 /// 0
/// } /// }
/// ``` /// ```
#[proc_macro_attribute] #[proc_macro_attribute]
@ -531,9 +528,10 @@ pub fn socket_filter(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(non_camel_case_types)]
/// use aya_ebpf::{macros::fentry, programs::FEntryContext}; /// use aya_ebpf::{macros::fentry, programs::FEntryContext};
/// # #[expect(non_camel_case_types)]
/// # type filename = u32; /// # type filename = u32;
/// # #[expect(non_camel_case_types)]
/// # type path = u32; /// # type path = u32;
/// ///
/// #[fentry(function = "filename_lookup")] /// #[fentry(function = "filename_lookup")]
@ -573,9 +571,10 @@ pub fn fentry(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(non_camel_case_types)]
/// use aya_ebpf::{macros::fexit, programs::FExitContext}; /// use aya_ebpf::{macros::fexit, programs::FExitContext};
/// # #[expect(non_camel_case_types)]
/// # type filename = u32; /// # type filename = u32;
/// # #[expect(non_camel_case_types)]
/// # type path = u32; /// # type path = u32;
/// ///
/// #[fexit(function = "filename_lookup")] /// #[fexit(function = "filename_lookup")]
@ -658,7 +657,7 @@ pub fn flow_dissector(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// #[sk_lookup] /// #[sk_lookup]
/// pub fn accept_all(_ctx: SkLookupContext) -> u32 { /// pub fn accept_all(_ctx: SkLookupContext) -> u32 {
/// // use sk_assign to redirect /// // use sk_assign to redirect
/// return 0 /// 0
/// } /// }
/// ``` /// ```
#[proc_macro_attribute] #[proc_macro_attribute]
@ -688,7 +687,7 @@ pub fn sk_lookup(attrs: TokenStream, item: TokenStream) -> TokenStream {
/// #[cgroup_device] /// #[cgroup_device]
/// pub fn cgroup_dev(ctx: DeviceContext) -> i32 { /// pub fn cgroup_dev(ctx: DeviceContext) -> i32 {
/// // Reject all device access /// // Reject all device access
/// return 0; /// 0
/// } /// }
/// ``` /// ```
#[proc_macro_attribute] #[proc_macro_attribute]

@ -36,13 +36,13 @@ use crate::{
/// let flags = 0; /// let flags = 0;
/// ///
/// // bpf_tail_call(ctx, JUMP_TABLE, 0) will jump to prog_0 /// // bpf_tail_call(ctx, JUMP_TABLE, 0) will jump to prog_0
/// prog_array.set(0, &prog_0_fd, flags); /// prog_array.set(0, prog_0_fd, flags);
/// ///
/// // bpf_tail_call(ctx, JUMP_TABLE, 1) will jump to prog_1 /// // bpf_tail_call(ctx, JUMP_TABLE, 1) will jump to prog_1
/// prog_array.set(1, &prog_1_fd, flags); /// prog_array.set(1, prog_1_fd, flags);
/// ///
/// // bpf_tail_call(ctx, JUMP_TABLE, 2) will jump to prog_2 /// // bpf_tail_call(ctx, JUMP_TABLE, 2) will jump to prog_2
/// prog_array.set(2, &prog_2_fd, flags); /// prog_array.set(2, prog_2_fd, flags);
/// # Ok::<(), aya::EbpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_PROG_ARRAY")] #[doc(alias = "BPF_MAP_TYPE_PROG_ARRAY")]

@ -1229,10 +1229,9 @@ impl_info!(
/// use aya::programs::loaded_links; /// use aya::programs::loaded_links;
/// ///
/// for info in loaded_links() { /// for info in loaded_links() {
/// if let Ok(info) = info { /// let info = info.unwrap();
/// println!("loaded link: {}", info.id()); /// println!("loaded link: {}", info.id());
/// } /// }
/// }
/// ``` /// ```
pub fn loaded_links() -> impl Iterator<Item = Result<LinkInfo, LinkError>> { pub fn loaded_links() -> impl Iterator<Item = Result<LinkInfo, LinkError>> {
iter_link_ids() iter_link_ids()

@ -323,7 +323,9 @@ fn parse_kernel_symbols(reader: impl BufRead) -> Result<BTreeMap<u64, String>, i
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
/// # #[expect(deprecated)]
/// use aya::util::syscall_prefix; /// use aya::util::syscall_prefix;
/// # #[expect(deprecated)]
/// let prefix = syscall_prefix().unwrap(); /// let prefix = syscall_prefix().unwrap();
/// let syscall_fname = format!("{prefix}exec"); /// let syscall_fname = format!("{prefix}exec");
/// ``` /// ```

@ -18,17 +18,30 @@ cargo +nightly hack clippy "$@" \
-C panic=abort \ -C panic=abort \
-Zpanic_abort_tests -Zpanic_abort_tests
export CLIPPY_ARGS='--deny=warnings'
export RUSTDOCFLAGS='--no-run -Z unstable-options --test-builder clippy-driver'
cargo +nightly hack test --doc "$@" --feature-powerset
for arch in aarch64 arm loongarch64 mips powerpc64 riscv64 s390x x86_64; do for arch in aarch64 arm loongarch64 mips powerpc64 riscv64 s390x x86_64; do
export RUSTFLAGS="--cfg bpf_target_arch=\"$arch\""
for target in bpfeb-unknown-none bpfel-unknown-none; do for target in bpfeb-unknown-none bpfel-unknown-none; do
RUSTFLAGS="--cfg bpf_target_arch=\"$arch\"" cargo +nightly hack clippy \ cargo +nightly hack clippy \
--target "$target" \ --target "$target" \
-Zbuild-std=core \ -Zbuild-std=core \
--package aya-ebpf-bindings \
--package aya-ebpf \ --package aya-ebpf \
--package aya-ebpf-bindings \
--package aya-log-ebpf \ --package aya-log-ebpf \
--package integration-ebpf \ --package integration-ebpf \
--feature-powerset \ --feature-powerset \
-- --deny warnings -- --deny warnings
done done
RUSTDOCFLAGS="$RUSTDOCFLAGS $RUSTFLAGS" cargo +nightly hack test --doc "$@" \
--package aya-ebpf \
--package aya-ebpf-bindings \
--package aya-log-ebpf \
--package integration-ebpf \
--feature-powerset
done done

@ -35,7 +35,6 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read}; /// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const c_int = 0 as _; /// # let kernel_ptr: *const c_int = 0 as _;
@ -74,7 +73,6 @@ pub unsafe fn bpf_probe_read<T>(src: *const T) -> Result<T, c_long> {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_buf}; /// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_buf};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let ptr: *const u8 = 0 as _; /// # let ptr: *const u8 = 0 as _;
@ -103,7 +101,6 @@ pub unsafe fn bpf_probe_read_buf(src: *const u8, dst: &mut [u8]) -> Result<(), c
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_user}; /// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_user};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let user_ptr: *const c_int = 0 as _; /// # let user_ptr: *const c_int = 0 as _;
@ -140,7 +137,6 @@ pub unsafe fn bpf_probe_read_user<T>(src: *const T) -> Result<T, c_long> {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_user_buf}; /// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_user_buf};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let user_ptr: *const u8 = 0 as _; /// # let user_ptr: *const u8 = 0 as _;
@ -170,7 +166,6 @@ pub unsafe fn bpf_probe_read_user_buf(src: *const u8, dst: &mut [u8]) -> Result<
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_kernel}; /// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_kernel};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const c_int = 0 as _; /// # let kernel_ptr: *const c_int = 0 as _;
@ -207,7 +202,6 @@ pub unsafe fn bpf_probe_read_kernel<T>(src: *const T) -> Result<T, c_long> {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_kernel_buf}; /// # use aya_ebpf::{cty::{c_int, c_long}, helpers::bpf_probe_read_kernel_buf};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const u8 = 0 as _; /// # let kernel_ptr: *const u8 = 0 as _;
@ -240,11 +234,12 @@ pub unsafe fn bpf_probe_read_kernel_buf(src: *const u8, dst: &mut [u8]) -> Resul
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)] /// # #[expect(deprecated)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_str}; /// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_str};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const u8 = 0 as _; /// # let kernel_ptr: *const u8 = 0 as _;
/// let mut my_str = [0u8; 16]; /// let mut my_str = [0u8; 16];
/// # #[expect(deprecated)]
/// let num_read = unsafe { bpf_probe_read_str(kernel_ptr, &mut my_str)? }; /// let num_read = unsafe { bpf_probe_read_str(kernel_ptr, &mut my_str)? };
/// ///
/// // Do something with num_read and my_str /// // Do something with num_read and my_str
@ -276,11 +271,12 @@ pub unsafe fn bpf_probe_read_str(src: *const u8, dest: &mut [u8]) -> Result<usiz
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)] /// # #[expect(deprecated)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_user_str}; /// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_user_str};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let user_ptr: *const u8 = 0 as _; /// # let user_ptr: *const u8 = 0 as _;
/// let mut my_str = [0u8; 16]; /// let mut my_str = [0u8; 16];
/// # #[expect(deprecated)]
/// let num_read = unsafe { bpf_probe_read_user_str(user_ptr, &mut my_str)? }; /// let num_read = unsafe { bpf_probe_read_user_str(user_ptr, &mut my_str)? };
/// ///
/// // Do something with num_read and my_str /// // Do something with num_read and my_str
@ -315,7 +311,6 @@ pub unsafe fn bpf_probe_read_user_str(src: *const u8, dest: &mut [u8]) -> Result
/// eBPF stack limit is 512 bytes): /// eBPF stack limit is 512 bytes):
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_user_str_bytes}; /// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_user_str_bytes};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let user_ptr: *const u8 = 0 as _; /// # let user_ptr: *const u8 = 0 as _;
@ -421,11 +416,12 @@ fn read_str_bytes(len: i64, dest: &[u8]) -> Result<&[u8], c_long> {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)] /// # #[expect(deprecated)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_kernel_str}; /// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_kernel_str};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const u8 = 0 as _; /// # let kernel_ptr: *const u8 = 0 as _;
/// let mut my_str = [0u8; 16]; /// let mut my_str = [0u8; 16];
/// # #[expect(deprecated)]
/// let num_read = unsafe { bpf_probe_read_kernel_str(kernel_ptr, &mut my_str)? }; /// let num_read = unsafe { bpf_probe_read_kernel_str(kernel_ptr, &mut my_str)? };
/// ///
/// // Do something with num_read and my_str /// // Do something with num_read and my_str
@ -464,7 +460,6 @@ pub unsafe fn bpf_probe_read_kernel_str(src: *const u8, dest: &mut [u8]) -> Resu
/// eBPF stack limit is 512 bytes): /// eBPF stack limit is 512 bytes):
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_kernel_str_bytes}; /// # use aya_ebpf::{cty::c_long, helpers::bpf_probe_read_kernel_str_bytes};
/// # fn try_test() -> Result<(), c_long> { /// # fn try_test() -> Result<(), c_long> {
/// # let kernel_ptr: *const u8 = 0 as _; /// # let kernel_ptr: *const u8 = 0 as _;
@ -554,7 +549,6 @@ pub unsafe fn bpf_probe_read_kernel_str_bytes(
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{ /// # use aya_ebpf::{
/// # cty::{c_int, c_long}, /// # cty::{c_int, c_long},
/// # helpers::bpf_probe_write_user, /// # helpers::bpf_probe_write_user,
@ -587,7 +581,6 @@ pub unsafe fn bpf_probe_write_user<T>(dst: *mut T, src: *const T) -> Result<(),
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::helpers::bpf_get_current_comm; /// # use aya_ebpf::helpers::bpf_get_current_comm;
/// let comm = bpf_get_current_comm(); /// let comm = bpf_get_current_comm();
/// ///
@ -622,7 +615,6 @@ pub fn bpf_get_current_comm() -> Result<[u8; 16], c_long> {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::helpers::bpf_get_current_pid_tgid; /// # use aya_ebpf::helpers::bpf_get_current_pid_tgid;
/// let tgid = (bpf_get_current_pid_tgid() >> 32) as u32; /// let tgid = (bpf_get_current_pid_tgid() >> 32) as u32;
/// let pid = bpf_get_current_pid_tgid() as u32; /// let pid = bpf_get_current_pid_tgid() as u32;
@ -645,7 +637,6 @@ pub fn bpf_get_current_pid_tgid() -> u64 {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::helpers::bpf_get_current_uid_gid; /// # use aya_ebpf::helpers::bpf_get_current_uid_gid;
/// let gid = (bpf_get_current_uid_gid() >> 32) as u32; /// let gid = (bpf_get_current_uid_gid() >> 32) as u32;
/// let uid = bpf_get_current_uid_gid() as u32; /// let uid = bpf_get_current_uid_gid() as u32;

@ -14,7 +14,6 @@ use crate::{
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// use aya_ebpf::{macros::map, maps::ProgramArray, cty::c_long}; /// use aya_ebpf::{macros::map, maps::ProgramArray, cty::c_long};
/// # use aya_ebpf::{programs::LsmContext}; /// # use aya_ebpf::{programs::LsmContext};
/// ///
@ -24,8 +23,8 @@ use crate::{
/// # unsafe fn try_test(ctx: &LsmContext) -> Result<(), c_long> { /// # unsafe fn try_test(ctx: &LsmContext) -> Result<(), c_long> {
/// let index: u32 = 13; /// let index: u32 = 13;
/// ///
/// if let Err(e) = JUMP_TABLE.tail_call(ctx, index) { /// unsafe {
/// return Err(e); /// JUMP_TABLE.tail_call(ctx, index)?;
/// } /// }
/// ///
/// # Err(-1) /// # Err(-1)

@ -16,10 +16,10 @@ impl FEntryContext {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(non_camel_case_types)]
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::c_int, programs::FEntryContext}; /// # use aya_ebpf::{cty::c_int, programs::FEntryContext};
/// # #[expect(non_camel_case_types)]
/// # type pid_t = c_int; /// # type pid_t = c_int;
/// # #[expect(non_camel_case_types)]
/// # struct task_struct { /// # struct task_struct {
/// # pid: pid_t, /// # pid: pid_t,
/// # } /// # }

@ -16,10 +16,10 @@ impl FExitContext {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(non_camel_case_types)]
/// # #![expect(dead_code)]
/// # use aya_ebpf::{cty::c_int, programs::FExitContext}; /// # use aya_ebpf::{cty::c_int, programs::FExitContext};
/// # #[expect(non_camel_case_types)]
/// # type pid_t = c_int; /// # type pid_t = c_int;
/// # #[expect(non_camel_case_types)]
/// # struct task_struct { /// # struct task_struct {
/// # pid: pid_t, /// # pid: pid_t,
/// # } /// # }

@ -25,7 +25,6 @@ impl LsmContext {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{programs::LsmContext, cty::{c_int, c_ulong}}; /// # use aya_ebpf::{programs::LsmContext, cty::{c_int, c_ulong}};
/// unsafe fn try_lsm_mmap_addr(ctx: LsmContext) -> Result<i32, i32> { /// unsafe fn try_lsm_mmap_addr(ctx: LsmContext) -> Result<i32, i32> {
/// // In the kernel, this hook is defined as: /// // In the kernel, this hook is defined as:

@ -16,16 +16,18 @@ impl ProbeContext {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(non_camel_case_types)]
/// # #![expect(dead_code)]
/// # use aya_ebpf::{programs::ProbeContext, cty::c_int, helpers::bpf_probe_read}; /// # use aya_ebpf::{programs::ProbeContext, cty::c_int, helpers::bpf_probe_read};
/// # #[expect(non_camel_case_types)]
/// # type pid_t = c_int; /// # type pid_t = c_int;
/// # #[expect(non_camel_case_types)]
/// # struct task_struct { /// # struct task_struct {
/// # pid: pid_t, /// # pid: pid_t,
/// # } /// # }
/// unsafe fn try_kprobe_try_to_wake_up(ctx: ProbeContext) -> Result<u32, u32> { /// unsafe fn try_kprobe_try_to_wake_up(ctx: ProbeContext) -> Result<u32, u32> {
/// let tp: *const task_struct = ctx.arg(0).ok_or(1u32)?; /// let tp: *const task_struct = ctx.arg(0).ok_or(1u32)?;
/// let pid = bpf_probe_read(&(*tp).pid as *const pid_t).map_err(|_| 1u32)?; /// let pid = unsafe {
/// bpf_probe_read(core::ptr::addr_of!((*tp).pid))
/// }.map_err(|err| err as u32)?;
/// ///
/// // Do something with pid or something else with tp /// // Do something with pid or something else with tp
/// ///

@ -16,7 +16,6 @@ impl RetProbeContext {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{programs::RetProbeContext, cty::c_int}; /// # use aya_ebpf::{programs::RetProbeContext, cty::c_int};
/// unsafe fn try_kretprobe_try_to_wake_up(ctx: RetProbeContext) -> Result<u32, u32> { /// unsafe fn try_kretprobe_try_to_wake_up(ctx: RetProbeContext) -> Result<u32, u32> {
/// let retval: c_int = ctx.ret(); /// let retval: c_int = ctx.ret();

@ -384,8 +384,8 @@ impl SkBuffContext {
/// fn try_cgroup_skb(ctx: SkBuffContext) -> Result<i32, i32> { /// fn try_cgroup_skb(ctx: SkBuffContext) -> Result<i32, i32> {
/// let len = ETH_HLEN + IP_HLEN + UDP_HLEN; /// let len = ETH_HLEN + IP_HLEN + UDP_HLEN;
/// match ctx.pull_data(len as u32) { /// match ctx.pull_data(len as u32) {
/// Ok(()) => return Ok(0), /// Ok(()) => Ok(0),
/// Err(ret) => return Err(ret as i32), /// Err(ret) => Err(ret as i32),
/// } /// }
/// } /// }
/// ``` /// ```

@ -176,8 +176,8 @@ impl TcContext {
/// fn try_classifier(ctx: TcContext) -> Result<i32, i32> { /// fn try_classifier(ctx: TcContext) -> Result<i32, i32> {
/// let len = ETH_HLEN + IP_HLEN + UDP_HLEN; /// let len = ETH_HLEN + IP_HLEN + UDP_HLEN;
/// match ctx.pull_data(len as u32) { /// match ctx.pull_data(len as u32) {
/// Ok(()) => return Ok(0), /// Ok(()) => Ok(0),
/// Err(ret) => return Err(ret as i32), /// Err(ret) => Err(ret as i32),
/// } /// }
/// } /// }
/// ``` /// ```

@ -19,7 +19,6 @@ impl BtfTracePointContext {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// # #![expect(dead_code)]
/// # use aya_ebpf::{programs::BtfTracePointContext, cty::{c_int, c_ulong, c_char}}; /// # use aya_ebpf::{programs::BtfTracePointContext, cty::{c_int, c_ulong, c_char}};
/// unsafe fn try_tp_btf_sched_process_fork(ctx: BtfTracePointContext) -> Result<u32, u32> { /// unsafe fn try_tp_btf_sched_process_fork(ctx: BtfTracePointContext) -> Result<u32, u32> {
/// // Grab arguments /// // Grab arguments

@ -115,10 +115,10 @@ fn test_log(ctx: ProbeContext) {
let buf = &buf[..core::cmp::min(len, buf.len())]; let buf = &buf[..core::cmp::min(len, buf.len())];
info!(&ctx, "variable length buffer: {:x}", buf); info!(&ctx, "variable length buffer: {:x}", buf);
info!(&ctx, "2KiB array: {:x}", &TWO_KB_ARRAY); info!(&ctx, "2KiB array: {:x}", TWO_KB_ARRAY.as_slice());
info!(&ctx, "4KiB array: {:x}", &FOUR_KB_ARRAY); info!(&ctx, "4KiB array: {:x}", FOUR_KB_ARRAY.as_slice());
// This one is too big and should be dropped. // This one is too big and should be dropped.
info!(&ctx, "8KiB array: {:x}", &EIGHT_KB_ARRAY); info!(&ctx, "8KiB array: {:x}", EIGHT_KB_ARRAY.as_slice());
} }
#[uprobe] #[uprobe]

Loading…
Cancel
Save