Move `panic_handler` to `aya-ebpf`

reviewable/pr1229/r9
Thomas Eizinger 3 weeks ago
parent 91d66b6121
commit a3959d8d9f
No known key found for this signature in database
GPG Key ID: 05633CD77196CAF3

@ -134,18 +134,8 @@ pub fn check_bounds_signed(value: i64, lower: i64, upper: i64) -> bool {
} }
#[macro_export] #[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"))] #[cfg(not(target_arch = "bpf"))]
fn main() { 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"`."#) 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] #[inline]
fn insert<K, V>( fn insert<K, V>(
def: *mut bindings::bpf_map_def, def: *mut bindings::bpf_map_def,

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{ use aya_ebpf::{
helpers::{bpf_probe_read_kernel_str_bytes, bpf_probe_read_user_str_bytes}, helpers::{bpf_probe_read_kernel_str_bytes, bpf_probe_read_user_str_bytes},

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use core::net::{IpAddr, Ipv4Addr, Ipv6Addr};

@ -3,7 +3,7 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{ use aya_ebpf::{
macros::{map, socket_filter}, macros::{map, socket_filter},

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use core::mem; use core::mem;

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{bindings::xdp_action, macros::xdp, programs::XdpContext}; use aya_ebpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{bindings::xdp_action, macros::xdp, programs::XdpContext}; use aya_ebpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{ use aya_ebpf::{
macros::{map, raw_tracepoint}, macros::{map, raw_tracepoint},

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{ use aya_ebpf::{
bindings::xdp_action, bindings::xdp_action,

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use core::hint; use core::hint;

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{ use aya_ebpf::{
macros::{map, uprobe}, macros::{map, uprobe},

@ -3,7 +3,7 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{macros::socket_filter, programs::SkBuffContext}; use aya_ebpf::{macros::socket_filter, programs::SkBuffContext};

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{ use aya_ebpf::{
cty::c_long, cty::c_long,

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![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}; use aya_ebpf::{bindings::tcx_action_base::TCX_NEXT, macros::classifier, programs::TcContext};

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{ use aya_ebpf::{
bindings::{bpf_ret_code, xdp_action}, bindings::{bpf_ret_code, xdp_action},

@ -2,7 +2,7 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{macros::tracepoint, programs::TracePointContext}; use aya_ebpf::{macros::tracepoint, programs::TracePointContext};

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::prelude!(); aya_ebpf::main_stub!();
use aya_ebpf::{ use aya_ebpf::{
EbpfContext as _, helpers, EbpfContext as _, helpers,

@ -1,6 +1,6 @@
#![cfg_attr(target_arch = "bpf", no_std)] #![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)] #![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}; use aya_ebpf::{bindings::xdp_action::XDP_PASS, macros::xdp, programs::XdpContext};

Loading…
Cancel
Save