1 // SPDX-License-Identifier: GPL-2.0-only 1 2 /* 3 * PowerPC implementation of rethook. This dep 4 */ 5 6 #include <linux/kprobes.h> 7 #include <linux/rethook.h> 8 9 /* 10 * Function return trampoline: 11 * - init_kprobes() establishes a probepoi 12 * - When the probed function returns, thi 13 * causes the handlers to fire 14 */ 15 asm(".global arch_rethook_trampoline\n" 16 ".type arch_rethook_trampoline, @funct 17 "arch_rethook_trampoline:\n" 18 "nop\n" 19 "blr\n" 20 ".size arch_rethook_trampoline, .-arch 21 22 /* 23 * Called when the probe at kretprobe trampoli 24 */ 25 static int trampoline_rethook_handler(struct k 26 { 27 return !rethook_trampoline_handler(reg 28 } 29 NOKPROBE_SYMBOL(trampoline_rethook_handler); 30 31 void arch_rethook_prepare(struct rethook_node 32 { 33 rh->ret_addr = regs->link; 34 rh->frame = regs->gpr[1]; 35 36 /* Replace the return addr with trampo 37 regs->link = (unsigned long)arch_retho 38 } 39 NOKPROBE_SYMBOL(arch_rethook_prepare); 40 41 /* This is called from rethook_trampoline_hand 42 void arch_rethook_fixup_return(struct pt_regs 43 { 44 /* 45 * We get here through one of two path 46 * 1. by taking a trap -> kprobe_handl 47 * 2. by optprobe branch -> optimized_ 48 * 49 * When going back through (1), we nee 50 * as it is used to determine the retu 51 * For (2), since nip is not honoured 52 * the link register properly so that 53 * arch_rethook_trampoline jumps back 54 * 55 * For nip, we should set the address 56 * we end up emulating it in kprobe_ha 57 * again. 58 */ 59 regs_set_return_ip(regs, orig_ret_addr 60 regs->link = orig_ret_address; 61 } 62 NOKPROBE_SYMBOL(arch_rethook_fixup_return); 63 64 static struct kprobe trampoline_p = { 65 .addr = (kprobe_opcode_t *) &arch_reth 66 .pre_handler = trampoline_rethook_hand 67 }; 68 69 /* rethook initializer */ 70 int __init arch_init_kprobes(void) 71 { 72 return register_kprobe(&trampoline_p); 73 } 74
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.