Skip to content

Commit

Permalink
Add #![no_builtins]
Browse files Browse the repository at this point in the history
See aya-rs/aya#698 for rationale.
  • Loading branch information
tamird committed Nov 7, 2023
1 parent bfe031e commit 506312b
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 17 deletions.
11 changes: 6 additions & 5 deletions docs/book/start/hello-xdp.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ The logic for this program is located in `xdp-hello-ebpf/src/main.rs` and curren

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

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

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
@@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]

#[allow(non_upper_case_globals)]
#[allow(non_snake_case)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]

use aya_bpf::{
macros::{cgroup_skb, map},
Expand Down
3 changes: 2 additions & 1 deletion examples/kprobetcp/kprobetcp-ebpf/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]

#[allow(non_upper_case_globals)]
#[allow(non_snake_case)]
Expand Down
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
@@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]

use aya_bpf::{cty::c_int, macros::lsm, programs::LsmContext};
use aya_log_ebpf::info;
Expand Down
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
@@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]

use aya_bpf::{
bindings::{TC_ACT_PIPE, TC_ACT_SHOT},
Expand Down
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
@@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]
#![allow(nonstandard_style, dead_code)]

use aya_bpf::{
Expand Down
11 changes: 6 additions & 5 deletions examples/xdp-hello/xdp-hello-ebpf/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#![no_std] // (1)
#![no_main] // (2)
#![no_builtins] // (3)

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

#[xdp] // (4)
#[xdp] // (5)
pub fn xdp_hello(ctx: XdpContext) -> u32 {
// (5)
// (6)
match unsafe { try_xdp_hello(ctx) } {
Ok(ret) => ret,
Err(_) => xdp_action::XDP_ABORTED,
}
}

unsafe fn try_xdp_hello(ctx: XdpContext) -> Result<u32, u32> {
// (6)
info!(&ctx, "received a packet");
// (7)
info!(&ctx, "received a packet");
// (8)
Ok(xdp_action::XDP_PASS)
}

#[panic_handler] // (3)
#[panic_handler] // (4)
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
}
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
@@ -1,5 +1,6 @@
#![no_std]
#![no_builtins]
#![no_main]
#![no_std]

use aya_bpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};
use aya_log_ebpf::info;
Expand Down

0 comments on commit 506312b

Please sign in to comment.