Skip to content

Commit 9c6ff95

Browse files
committed
examples: cleanup rust examples
1 parent 9e463a2 commit 9c6ff95

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
See the [examples](examples) directory for examples of eBPF programs written in C, Rust and compiled to Wasm, covering the use cases from `tracing`, `networking` to `security`.
1818

19+
For tools to distribute Wasm-eBPF programs in [`OCI`](https://opencontainers.org/) images, please refer to [eunomia-bpf](https://github.com/eunomia-bpf/eunomia-bpf) repo.
20+
1921
## How it works
2022

2123
The wasm-bpf runtime require two parts: `the host side`(Outside the Wasm runtime) and the `Wasm guest side`(Inside the Wasm runtime).

examples/rust-bootstrap/src/main.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main(_env_json: u32, _str_len: i32) -> i32 {
1616
println!("Failed to load bpf object");
1717
return 1;
1818
}
19-
19+
// attach bpf program to func
2020
let attach_result = binding::wasm_attach_bpf_program(
2121
obj_ptr,
2222
"handle_exec\0".as_ptr() as u32,
@@ -26,6 +26,7 @@ fn main(_env_json: u32, _str_len: i32) -> i32 {
2626
println!("Attach handle_exit failed: {}", attach_result);
2727
return 1;
2828
}
29+
// attach bpf program to func
2930
let attach_result = binding::wasm_attach_bpf_program(
3031
obj_ptr,
3132
"handle_exit\0".as_ptr() as u32,
@@ -35,6 +36,7 @@ fn main(_env_json: u32, _str_len: i32) -> i32 {
3536
println!("Attach handle_exit failed: {}", attach_result);
3637
return 1;
3738
}
39+
// get the map fd for ring buffer
3840
let map_fd = binding::wasm_bpf_map_fd_by_name(obj_ptr, "rb\0".as_ptr() as u32);
3941
if map_fd < 0 {
4042
println!("Failed to get map fd: {}", map_fd);
@@ -69,7 +71,7 @@ struct Event {
6971
exit_event: u8,
7072
}
7173

72-
// #[export_name = "handle_event"]
74+
/// handle ring buffer events
7375
extern "C" fn handle_event(_ctx: u32, data: u32, _data_sz: u32) {
7476
let event_slice = unsafe { slice::from_raw_parts(data as *const Event, 1) };
7577
let event = &event_slice[0];
@@ -107,5 +109,4 @@ extern "C" fn handle_event(_ctx: u32, data: u32, _data_sz: u32) {
107109
.unwrap()
108110
);
109111
}
110-
// println!("{}",event.exit_event);
111112
}

0 commit comments

Comments
 (0)