lib.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #![no_std]
  2. pub mod bpf_probe_read {
  3. pub const RESULT_BUF_LEN: usize = 1024;
  4. #[derive(Copy, Clone)]
  5. #[repr(C)]
  6. pub struct TestResult {
  7. pub buf: [u8; RESULT_BUF_LEN],
  8. pub len: Option<Result<usize, i64>>,
  9. }
  10. #[cfg(feature = "user")]
  11. unsafe impl aya::Pod for TestResult {}
  12. }
  13. pub mod raw_tracepoint {
  14. #[repr(C)]
  15. #[derive(Clone, Copy)]
  16. pub struct SysEnterEvent {
  17. pub common_type: u16,
  18. pub common_flags: u8,
  19. _padding: u8, // Padding must be explicit to ensure zero-initialization.
  20. }
  21. #[cfg(feature = "user")]
  22. unsafe impl aya::Pod for SysEnterEvent {}
  23. }
  24. pub mod ring_buf {
  25. // This structure's definition is duplicated in the probe.
  26. #[repr(C)]
  27. #[derive(Clone, Copy, Debug, Eq, PartialEq, Default)]
  28. pub struct Registers {
  29. pub dropped: u64,
  30. pub rejected: u64,
  31. }
  32. impl core::ops::Add for Registers {
  33. type Output = Self;
  34. fn add(self, rhs: Self) -> Self::Output {
  35. Self {
  36. dropped: self.dropped + rhs.dropped,
  37. rejected: self.rejected + rhs.rejected,
  38. }
  39. }
  40. }
  41. impl<'a> core::iter::Sum<&'a Registers> for Registers {
  42. fn sum<I: Iterator<Item = &'a Registers>>(iter: I) -> Self {
  43. iter.fold(Default::default(), |a, b| a + *b)
  44. }
  45. }
  46. #[cfg(feature = "user")]
  47. unsafe impl aya::Pod for Registers {}
  48. }
  49. pub mod strncmp {
  50. #[derive(Copy, Clone)]
  51. #[repr(C)]
  52. pub struct TestResult(pub core::cmp::Ordering);
  53. #[cfg(feature = "user")]
  54. unsafe impl aya::Pod for TestResult {}
  55. }