relocations.rs 995 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #![no_std]
  2. #![no_main]
  3. use core::hint;
  4. use aya_ebpf::{
  5. macros::{map, uprobe},
  6. maps::Array,
  7. programs::ProbeContext,
  8. };
  9. #[map]
  10. static RESULTS: Array<u64> = Array::with_max_entries(3, 0);
  11. #[uprobe]
  12. pub fn test_64_32_call_relocs(_ctx: ProbeContext) {
  13. // this will link set_result and do a forward call
  14. set_result(0, hint::black_box(1));
  15. // set_result is already linked, this will just do the forward call
  16. set_result(1, hint::black_box(2));
  17. // this will link set_result_backward after set_result. Then will do a
  18. // backward call to set_result.
  19. set_result_backward(2, hint::black_box(3));
  20. }
  21. #[inline(never)]
  22. fn set_result(index: u32, value: u64) {
  23. unsafe {
  24. if let Some(v) = RESULTS.get_ptr_mut(index) {
  25. *v = value;
  26. }
  27. }
  28. }
  29. #[inline(never)]
  30. fn set_result_backward(index: u32, value: u64) {
  31. set_result(index, value);
  32. }
  33. #[cfg(not(test))]
  34. #[panic_handler]
  35. fn panic(_info: &core::panic::PanicInfo) -> ! {
  36. loop {}
  37. }