/* Compute the address of the breakpoint instruction and return it. * *Notethatuprobe_get_swbp_addrisdefinedasaweaksymbolin *kernel/events/uprobe.c.
*/ unsignedlong uprobe_get_swbp_addr(struct pt_regs *regs)
{ return instruction_pointer(regs);
}
/* Fill in the xol area with the probed instruction followed by the *single-steptrap.Somefixupsinthecopiedinstructionare *performedatthispoint. * *Notethatuprobe_xol_copyisdefinedasaweaksymbolin *kernel/events/uprobe.c.
*/ void arch_uprobe_copy_ixol(struct page *page, unsignedlong vaddr, void *src, unsignedlong len)
{ const u32 stp_insn = UPROBE_STP_INSN;
u32 insn = *(u32 *) src;
/* Branches annulling their delay slot must be fixed to not do *so.Clearingtheannulbitontheseinstructionswecanbe *surethesingle-stepbreakpointintheXOLslotwillbe *executed.
*/
/* Instruction analysis/validity. * *Thisfunctionreturns0onsuccessora-venumberonerror.
*/ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm, unsignedlong addr)
{ /* Any unsupported instruction? Then return -EINVAL */ return0;
}
/* If INSN is a relative control transfer instruction, return the *correctedbranchdestinationvalue. * *Notethatregs->tpcandregs->tnpcstillholdthevaluesofthe *programcountersatthetimeofthesingle-steptrapduetothe *executionoftheUPROBE_STP_INSNatutask->xol_vaddr+4. *
*/ staticunsignedlong relbranch_fixup(u32 insn, struct uprobe_task *utask, struct pt_regs *regs)
{ /* Branch not taken, no mods necessary. */ if (regs->tnpc == regs->tpc + 0x4UL) return utask->autask.saved_tnpc + 0x4UL;
/* The three cases are call, branch w/prediction, *andtraditionalbranch.
*/ if ((insn & 0xc0000000) == 0x40000000 ||
(insn & 0xc1c00000) == 0x00400000 ||
(insn & 0xc1c00000) == 0x00800000) { unsignedlong real_pc = (unsignedlong) utask->vaddr; unsignedlong ixol_addr = utask->xol_vaddr;
/* The instruction did all the work for us *already,justapplytheoffsettothecorrect *instructionlocation.
*/ return (real_pc + (regs->tnpc - ixol_addr));
}
/* It is jmpl or some other absolute PC modification instruction, *leaveNPCas-is.
*/ return regs->tnpc;
}
/* If INSN is an instruction which writes its PC location *intoadestinationregister,fixthatup.
*/ staticint retpc_fixup(struct pt_regs *regs, u32 insn, unsignedlong real_pc)
{ unsignedlong *slot = NULL; int rc = 0;
/* Simplest case is 'call', which always uses %o7 */ if ((insn & 0xc0000000) == 0x40000000)
slot = ®s->u_regs[UREG_I7];
/* 'jmpl' encodes the register inside of the opcode */ if ((insn & 0xc1f80000) == 0x81c00000) { unsignedlong rd = ((insn >> 25) & 0x1f);
if (rd <= 15) {
slot = ®s->u_regs[rd];
} else { unsignedlong fp = regs->u_regs[UREG_FP]; /* Hard case, it goes onto the stack. */
flushw_all();
/* Single-stepping can be avoided for certain instructions: NOPs and *instructionsthatcanbeemulated.Thisfunctiondetermines *whethertheinstructionwheretheuprobeisinstalledfallsinone *ofthesecasesandemulatesit. * *Thisfunctionreturnstrueifthesingle-steppingcanbeskipped, *falseotherwise.
*/ bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)
{ /* We currently only emulate NOP instructions.
*/
/* Prepare to execute out of line. At this point *current->utask->xol_vaddrpointstoanallocatedXOLslotproperly *initializedwiththeoriginalinstructionandthesingle-stepping *trapinstruction. * *Thisfunctionreturns0onsuccess,anyothernumberonerror.
*/ int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
{ struct uprobe_task *utask = current->utask; struct arch_uprobe_task *autask = ¤t->utask->autask;
/* Save the current program counters so they can be restored *later.
*/
autask->saved_tpc = regs->tpc;
autask->saved_tnpc = regs->tnpc;
/* Adjust PC and NPC so the first instruction in the XOL slot *willbeexecutedbytheusertask.
*/
instruction_pointer_set(regs, utask->xol_vaddr);
return0;
}
/* Prepare to resume execution after the single-step. Called after *single-stepping.ToavoidtheSMPproblemsthatcanoccurwhenwe *temporarilyputbacktheoriginalopcodetosingle-step,we *single-steppedacopyoftheinstruction. * *Thisfunctionreturns0onsuccess,anyothernumberonerror.
*/ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
{ struct uprobe_task *utask = current->utask; struct arch_uprobe_task *autask = &utask->autask;
u32 insn = auprobe->ixol; int rc = 0;
/* Handler for uprobe traps. This is called from the traps table and *triggerstheproperdienotification.
*/
asmlinkage void uprobe_trap(struct pt_regs *regs, unsignedlong trap_level)
{
BUG_ON(trap_level != 0x173 && trap_level != 0x174);
/* We are only interested in user-mode code. Uprobe traps *shallnotbepresentinkernelcode.
*/ if (!user_mode(regs)) {
local_irq_enable();
bad_trap(regs, trap_level); return;
}
/* Callback routine for handling die notifications.
*/ int arch_uprobe_exception_notify(struct notifier_block *self, unsignedlong val, void *data)
{ int ret = NOTIFY_DONE; struct die_args *args = (struct die_args *)data;
/* We are only interested in userspace traps */ if (args->regs && !user_mode(args->regs)) return NOTIFY_DONE;
switch (val) { case DIE_BPT: if (uprobe_pre_sstep_notifier(args->regs))
ret = NOTIFY_STOP; break;
case DIE_SSTEP: if (uprobe_post_sstep_notifier(args->regs))
ret = NOTIFY_STOP;
default: break;
}
return ret;
}
/* This function gets called when a XOL instruction either gets *trappedorthethreadhasafatalsignal,soresettheinstruction *pointertoitsprobedaddress.
*/ void arch_uprobe_abort_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
{ struct uprobe_task *utask = current->utask;
instruction_pointer_set(regs, utask->vaddr);
}
/* If xol insn itself traps and generates a signal(Say, *SIGILL/SIGSEGV/etc),thendetectthecasewhereasinglestepped *instructionjumpsbacktoitsownaddress.
*/ bool arch_uprobe_xol_was_trapped(struct task_struct *t)
{ returnfalse;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.