Skip to content

Commit

Permalink
examples: cleanup rust examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwei37 committed Feb 14, 2023
1 parent 9e463a2 commit 9c6ff95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

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`.

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.

## How it works

The wasm-bpf runtime require two parts: `the host side`(Outside the Wasm runtime) and the `Wasm guest side`(Inside the Wasm runtime).
Expand Down
7 changes: 4 additions & 3 deletions examples/rust-bootstrap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main(_env_json: u32, _str_len: i32) -> i32 {
println!("Failed to load bpf object");
return 1;
}

// attach bpf program to func
let attach_result = binding::wasm_attach_bpf_program(
obj_ptr,
"handle_exec\0".as_ptr() as u32,
Expand All @@ -26,6 +26,7 @@ fn main(_env_json: u32, _str_len: i32) -> i32 {
println!("Attach handle_exit failed: {}", attach_result);
return 1;
}
// attach bpf program to func
let attach_result = binding::wasm_attach_bpf_program(
obj_ptr,
"handle_exit\0".as_ptr() as u32,
Expand All @@ -35,6 +36,7 @@ fn main(_env_json: u32, _str_len: i32) -> i32 {
println!("Attach handle_exit failed: {}", attach_result);
return 1;
}
// get the map fd for ring buffer
let map_fd = binding::wasm_bpf_map_fd_by_name(obj_ptr, "rb\0".as_ptr() as u32);
if map_fd < 0 {
println!("Failed to get map fd: {}", map_fd);
Expand Down Expand Up @@ -69,7 +71,7 @@ struct Event {
exit_event: u8,
}

// #[export_name = "handle_event"]
/// handle ring buffer events
extern "C" fn handle_event(_ctx: u32, data: u32, _data_sz: u32) {
let event_slice = unsafe { slice::from_raw_parts(data as *const Event, 1) };
let event = &event_slice[0];
Expand Down Expand Up @@ -107,5 +109,4 @@ extern "C" fn handle_event(_ctx: u32, data: u32, _data_sz: u32) {
.unwrap()
);
}
// println!("{}",event.exit_event);
}

0 comments on commit 9c6ff95

Please sign in to comment.