Skip to content

Commit

Permalink
Use infinite loop in panic handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Oct 20, 2024
1 parent 286823c commit 45851a9
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 10 deletions.
6 changes: 4 additions & 2 deletions docs/book/programs/xdp.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ map definitions (for our HashMap) and XDP program macros (`macros::{map, xdp}`)
Here's how the code looks:

```rust
#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}
```

Expand Down Expand Up @@ -245,9 +246,10 @@ use network_types::{
ip::Ipv4Hdr,
};

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}

#[map]
Expand Down
3 changes: 2 additions & 1 deletion examples/aya-tool/myapp-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ unsafe fn try_task_alloc(ctx: LsmContext) -> Result<i32, i32> {
Ok(0)
}

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ fn try_cgroup_skb_egress(ctx: SkBuffContext) -> Result<i32, i64> {

const ETH_P_IP: u32 = 8;

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}
3 changes: 2 additions & 1 deletion examples/kprobetcp/kprobetcp-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ fn try_kprobetcp(ctx: ProbeContext) -> Result<u32, i64> {
}
}

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}
3 changes: 2 additions & 1 deletion examples/lsm-nice/lsm-nice-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ unsafe fn try_task_setnice(ctx: LsmContext) -> Result<i32, i32> {
Ok(0)
}

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}
3 changes: 2 additions & 1 deletion examples/tc-egress/tc-egress-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ fn try_tc_egress(ctx: TcContext) -> Result<i32, ()> {
Ok(action)
}

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}
3 changes: 2 additions & 1 deletion examples/xdp-drop/xdp-drop-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use network_types::{
ip::Ipv4Hdr,
};

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}

#[map] // (1)
Expand Down
3 changes: 2 additions & 1 deletion examples/xdp-hello/xdp-hello-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ unsafe fn try_xdp_hello(ctx: XdpContext) -> Result<u32, u32> {
Ok(xdp_action::XDP_PASS)
}

#[cfg(not(test))]
#[panic_handler] // (3)
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}
3 changes: 2 additions & 1 deletion examples/xdp-log/xdp-log-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use network_types::{
udp::UdpHdr,
};

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}

#[xdp]
Expand Down

0 comments on commit 45851a9

Please sign in to comment.