Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use infinite loop in panic handlers #173

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading