strncmp.rs 823 B

12345678910111213141516171819202122232425262728293031323334
  1. #![no_std]
  2. #![no_main]
  3. use aya_ebpf::{
  4. cty::c_long,
  5. helpers::{bpf_probe_read_user_str_bytes, bpf_strncmp},
  6. macros::{map, uprobe},
  7. maps::Array,
  8. programs::ProbeContext,
  9. };
  10. use integration_common::strncmp::TestResult;
  11. #[map]
  12. static RESULT: Array<TestResult> = Array::with_max_entries(1, 0);
  13. #[uprobe]
  14. pub fn test_bpf_strncmp(ctx: ProbeContext) -> Result<(), c_long> {
  15. let s1: *const u8 = ctx.arg(0).ok_or(-1)?;
  16. let mut b1 = [0u8; 3];
  17. let _: &[u8] = unsafe { bpf_probe_read_user_str_bytes(s1, &mut b1) }?;
  18. let ptr = RESULT.get_ptr_mut(0).ok_or(-1)?;
  19. let dst = unsafe { ptr.as_mut() };
  20. let TestResult(dst_res) = dst.ok_or(-1)?;
  21. *dst_res = bpf_strncmp(&b1, c"ff");
  22. Ok(())
  23. }
  24. #[cfg(not(test))]
  25. #[panic_handler]
  26. fn panic(_info: &core::panic::PanicInfo) -> ! {
  27. loop {}
  28. }