lib.rs 915 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #![feature(never_type)]
  2. #![allow(clippy::missing_safety_doc)]
  3. #![no_std]
  4. pub use aya_bpf_bindings::bindings;
  5. mod args;
  6. pub mod helpers;
  7. pub mod maps;
  8. pub mod programs;
  9. pub use aya_bpf_cty as cty;
  10. use core::ffi::c_void;
  11. use cty::{c_char, c_int, c_long};
  12. use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid};
  13. pub use aya_bpf_macros as macros;
  14. pub const TASK_COMM_LEN: usize = 16;
  15. pub trait BpfContext {
  16. fn as_ptr(&self) -> *mut c_void;
  17. #[inline]
  18. fn command(&self) -> Result<[c_char; TASK_COMM_LEN], c_long> {
  19. bpf_get_current_comm()
  20. }
  21. fn pid(&self) -> u32 {
  22. bpf_get_current_pid_tgid() as u32
  23. }
  24. fn tgid(&self) -> u32 {
  25. (bpf_get_current_pid_tgid() >> 32) as u32
  26. }
  27. }
  28. #[no_mangle]
  29. pub unsafe extern "C" fn memset(s: *mut u8, c: c_int, n: usize) {
  30. let base = s as usize;
  31. for i in 0..n {
  32. *((base + i) as *mut u8) = c as u8;
  33. }
  34. }