rethook.c 1001 B

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #include <linux/rethook.h>
  3. #include <linux/kprobes.h>
  4. #include "rethook.h"
  5. void arch_rethook_prepare(struct rethook_node *rh, struct pt_regs *regs, bool mcount)
  6. {
  7. rh->ret_addr = regs->gprs[14];
  8. rh->frame = regs->gprs[15];
  9. /* Replace the return addr with trampoline addr */
  10. regs->gprs[14] = (unsigned long)&arch_rethook_trampoline;
  11. }
  12. NOKPROBE_SYMBOL(arch_rethook_prepare);
  13. void arch_rethook_fixup_return(struct pt_regs *regs,
  14. unsigned long correct_ret_addr)
  15. {
  16. /* Replace fake return address with real one. */
  17. regs->gprs[14] = correct_ret_addr;
  18. }
  19. NOKPROBE_SYMBOL(arch_rethook_fixup_return);
  20. /*
  21. * Called from arch_rethook_trampoline
  22. */
  23. unsigned long arch_rethook_trampoline_callback(struct pt_regs *regs)
  24. {
  25. return rethook_trampoline_handler(regs, regs->gprs[15]);
  26. }
  27. NOKPROBE_SYMBOL(arch_rethook_trampoline_callback);
  28. /* assembler function that handles the rethook must not be probed itself */
  29. NOKPROBE_SYMBOL(arch_rethook_trampoline);