lib.rs 891 B

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