Skip to content

Commit 6a05ead

Browse files
committed
Add #![no_builtins]
See aya-rs/aya#698 for rationale.
1 parent ac7ee1f commit 6a05ead

File tree

9 files changed

+26
-17
lines changed

9 files changed

+26
-17
lines changed

docs/book/start/hello-xdp.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ The logic for this program is located in `xdp-hello-ebpf/src/main.rs` and curren
2424

2525
1. `#![no_std]` is required since we cannot use the standard library.
2626
2. `#![no_main]` is required as we have no main function.
27-
3. The `#[panic_handler]` is required to keep the compiler happy, although it is never used since we cannot panic.
28-
4. This indicates that this function is an XDP program.
29-
5. Our main entry point defers to another function and performs error handling, returning `XDP_ABORTED`, which will drop the packet.
30-
6. Write a log entry every time a packet is received.
31-
7. This function returns a `Result` that permits all traffic.
27+
3. `#![no_builtins]` is required as we cannot use LLVM intrinsics.
28+
4. The `#[panic_handler]` is required to keep the compiler happy, although it is never used since we cannot panic.
29+
5. This indicates that this function is an XDP program.
30+
6. Our main entry point defers to another function and performs error handling, returning `XDP_ABORTED`, which will drop the packet.
31+
7. Write a log entry every time a packet is received.
32+
8. This function returns a `Result` that permits all traffic.
3233

3334
Now we can compile this using `cargo xtask build-ebpf`.
3435

examples/aya-tool/myapp-ebpf/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![no_std]
1+
#![no_builtins]
22
#![no_main]
3+
#![no_std]
34

45
#[allow(non_upper_case_globals)]
56
#[allow(non_snake_case)]

examples/cgroup-skb-egress/cgroup-skb-egress-ebpf/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![no_std]
1+
#![no_builtins]
22
#![no_main]
3+
#![no_std]
34

45
use aya_bpf::{
56
macros::{cgroup_skb, map},

examples/kprobetcp/kprobetcp-ebpf/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![no_std]
1+
#![no_builtins]
22
#![no_main]
3+
#![no_std]
34

45
#[allow(non_upper_case_globals)]
56
#[allow(non_snake_case)]

examples/lsm-nice/lsm-nice-ebpf/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![no_std]
1+
#![no_builtins]
22
#![no_main]
3+
#![no_std]
34

45
use aya_bpf::{cty::c_int, macros::lsm, programs::LsmContext};
56
use aya_log_ebpf::info;

examples/tc-egress/tc-egress-ebpf/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![no_std]
1+
#![no_builtins]
22
#![no_main]
3+
#![no_std]
34

45
use aya_bpf::{
56
bindings::{TC_ACT_PIPE, TC_ACT_SHOT},

examples/xdp-drop/xdp-drop-ebpf/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![no_std]
1+
#![no_builtins]
22
#![no_main]
3+
#![no_std]
34
#![allow(nonstandard_style, dead_code)]
45

56
use aya_bpf::{
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#![no_std] // (1)
22
#![no_main] // (2)
3+
#![no_builtins] // (3)
34

45
use aya_bpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};
56
use aya_log_ebpf::info;
67

7-
#[xdp(name = "xdp_hello")] // (4)
8+
#[xdp(name = "xdp_hello")] // (5)
89
pub fn xdp_hello(ctx: XdpContext) -> u32 {
9-
// (5)
10+
// (6)
1011
match unsafe { try_xdp_hello(ctx) } {
1112
Ok(ret) => ret,
1213
Err(_) => xdp_action::XDP_ABORTED,
1314
}
1415
}
1516

1617
unsafe fn try_xdp_hello(ctx: XdpContext) -> Result<u32, u32> {
17-
// (6)
18-
info!(&ctx, "received a packet");
1918
// (7)
19+
info!(&ctx, "received a packet");
20+
// (8)
2021
Ok(xdp_action::XDP_PASS)
2122
}
2223

23-
#[panic_handler] // (3)
24+
#[panic_handler] // (4)
2425
fn panic(_info: &core::panic::PanicInfo) -> ! {
2526
unsafe { core::hint::unreachable_unchecked() }
2627
}

examples/xdp-log/xdp-log-ebpf/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![no_std]
1+
#![no_builtins]
22
#![no_main]
3+
#![no_std]
34

45
use aya_bpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};
56
use aya_log_ebpf::info;

0 commit comments

Comments
 (0)