diff --git a/ebpf/aya-ebpf/src/lib.rs b/ebpf/aya-ebpf/src/lib.rs index cbefd462..b9cce9fe 100644 --- a/ebpf/aya-ebpf/src/lib.rs +++ b/ebpf/aya-ebpf/src/lib.rs @@ -134,18 +134,8 @@ pub fn check_bounds_signed(value: i64, lower: i64, upper: i64) -> bool { } #[macro_export] -macro_rules! prelude { +macro_rules! main_stub { () => { - /// Defines our panic handler when compiling for eBPF. - /// - /// eBPF programs are not allowed to panic, meaning this handler won't actually ever be called. - /// Because we compile with `no_std`, we need to define one. - #[cfg(target_arch = "bpf")] - #[panic_handler] - fn panic(_info: &core::panic::PanicInfo) -> ! { - loop {} - } - #[cfg(not(target_arch = "bpf"))] fn main() { panic!(r#"eBPF kernels are not designed to be executed in user-space. This main function is only a placeholder to allow the code to compile on the host system (i.e. on any system that is not `target_arch = "bpf"`). This works in tandem with the `no_main` attribute which is only applied when compiling for `target_arch = "bpf"`."#) @@ -153,6 +143,18 @@ macro_rules! prelude { }; } +/// Defines our panic handler when compiling for eBPF. +/// +/// eBPF programs are not allowed to panic, meaning this handler won't actually ever be called. +/// Because we compile with `no_std`, we need to define one. +/// +/// Including the panic handler within `aya-ebpf` means every eBPF will automatically have this panic handler defined. +#[cfg(target_arch = "bpf")] +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} + #[inline] fn insert( def: *mut bindings::bpf_map_def, diff --git a/test/integration-ebpf/src/bpf_probe_read.rs b/test/integration-ebpf/src/bpf_probe_read.rs index e01021ed..1f6cff15 100644 --- a/test/integration-ebpf/src/bpf_probe_read.rs +++ b/test/integration-ebpf/src/bpf_probe_read.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{ helpers::{bpf_probe_read_kernel_str_bytes, bpf_probe_read_user_str_bytes}, diff --git a/test/integration-ebpf/src/log.rs b/test/integration-ebpf/src/log.rs index 7c4daf61..94a10533 100644 --- a/test/integration-ebpf/src/log.rs +++ b/test/integration-ebpf/src/log.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use core::net::{IpAddr, Ipv4Addr, Ipv6Addr}; diff --git a/test/integration-ebpf/src/map_test.rs b/test/integration-ebpf/src/map_test.rs index 54db9f98..4fca2223 100644 --- a/test/integration-ebpf/src/map_test.rs +++ b/test/integration-ebpf/src/map_test.rs @@ -3,7 +3,7 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{ macros::{map, socket_filter}, diff --git a/test/integration-ebpf/src/memmove_test.rs b/test/integration-ebpf/src/memmove_test.rs index 9fb65d84..33af46e3 100644 --- a/test/integration-ebpf/src/memmove_test.rs +++ b/test/integration-ebpf/src/memmove_test.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use core::mem; diff --git a/test/integration-ebpf/src/name_test.rs b/test/integration-ebpf/src/name_test.rs index dc5fa3ba..653f84d0 100644 --- a/test/integration-ebpf/src/name_test.rs +++ b/test/integration-ebpf/src/name_test.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{bindings::xdp_action, macros::xdp, programs::XdpContext}; diff --git a/test/integration-ebpf/src/pass.rs b/test/integration-ebpf/src/pass.rs index 91d627d9..0e711958 100644 --- a/test/integration-ebpf/src/pass.rs +++ b/test/integration-ebpf/src/pass.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{bindings::xdp_action, macros::xdp, programs::XdpContext}; diff --git a/test/integration-ebpf/src/raw_tracepoint.rs b/test/integration-ebpf/src/raw_tracepoint.rs index 24e6563d..6c543e29 100644 --- a/test/integration-ebpf/src/raw_tracepoint.rs +++ b/test/integration-ebpf/src/raw_tracepoint.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{ macros::{map, raw_tracepoint}, diff --git a/test/integration-ebpf/src/redirect.rs b/test/integration-ebpf/src/redirect.rs index 2e16bc7b..e8b72812 100644 --- a/test/integration-ebpf/src/redirect.rs +++ b/test/integration-ebpf/src/redirect.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{ bindings::xdp_action, diff --git a/test/integration-ebpf/src/relocations.rs b/test/integration-ebpf/src/relocations.rs index 37d03c98..49ca1576 100644 --- a/test/integration-ebpf/src/relocations.rs +++ b/test/integration-ebpf/src/relocations.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use core::hint; diff --git a/test/integration-ebpf/src/ring_buf.rs b/test/integration-ebpf/src/ring_buf.rs index 609784db..f4e8dd10 100644 --- a/test/integration-ebpf/src/ring_buf.rs +++ b/test/integration-ebpf/src/ring_buf.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{ macros::{map, uprobe}, diff --git a/test/integration-ebpf/src/simple_prog.rs b/test/integration-ebpf/src/simple_prog.rs index 79c968dc..c9aacd75 100644 --- a/test/integration-ebpf/src/simple_prog.rs +++ b/test/integration-ebpf/src/simple_prog.rs @@ -3,7 +3,7 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{macros::socket_filter, programs::SkBuffContext}; diff --git a/test/integration-ebpf/src/strncmp.rs b/test/integration-ebpf/src/strncmp.rs index 157e31fc..a05b295e 100644 --- a/test/integration-ebpf/src/strncmp.rs +++ b/test/integration-ebpf/src/strncmp.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{ cty::c_long, diff --git a/test/integration-ebpf/src/tcx.rs b/test/integration-ebpf/src/tcx.rs index 6df69dee..bbc78040 100644 --- a/test/integration-ebpf/src/tcx.rs +++ b/test/integration-ebpf/src/tcx.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{bindings::tcx_action_base::TCX_NEXT, macros::classifier, programs::TcContext}; diff --git a/test/integration-ebpf/src/test.rs b/test/integration-ebpf/src/test.rs index 70b0a585..0493e090 100644 --- a/test/integration-ebpf/src/test.rs +++ b/test/integration-ebpf/src/test.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{ bindings::{bpf_ret_code, xdp_action}, diff --git a/test/integration-ebpf/src/two_progs.rs b/test/integration-ebpf/src/two_progs.rs index 18fecf85..397c0cc3 100644 --- a/test/integration-ebpf/src/two_progs.rs +++ b/test/integration-ebpf/src/two_progs.rs @@ -2,7 +2,7 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{macros::tracepoint, programs::TracePointContext}; diff --git a/test/integration-ebpf/src/uprobe_cookie.rs b/test/integration-ebpf/src/uprobe_cookie.rs index 127c40cc..a30a26e7 100644 --- a/test/integration-ebpf/src/uprobe_cookie.rs +++ b/test/integration-ebpf/src/uprobe_cookie.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{ EbpfContext as _, helpers, diff --git a/test/integration-ebpf/src/xdp_sec.rs b/test/integration-ebpf/src/xdp_sec.rs index efb7dc45..4d94f6fe 100644 --- a/test/integration-ebpf/src/xdp_sec.rs +++ b/test/integration-ebpf/src/xdp_sec.rs @@ -1,6 +1,6 @@ #![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_main)] -aya_ebpf::prelude!(); +aya_ebpf::main_stub!(); use aya_ebpf::{bindings::xdp_action::XDP_PASS, macros::xdp, programs::XdpContext};