#ifndef _CURRENT_C_ #define _CURRENT_C_ /* -*- linux-c -*- */ /** @file current.c * @brief Functions to get the current state. */ /** @addtogroup current Current State * Functions to get the current state. * @{ */ /** Get the current return address. * Call from kprobes (not jprobes). * @param regs The pt_regs saved by the kprobe. * @return The return address saved in esp or rsp. * @note i386 and x86_64 only so far. */ unsigned long _stp_ret_addr (struct pt_regs *regs) { #ifdef __x86_64__ unsigned long *ra = (unsigned long *)regs->rsp; #else unsigned long *ra = (unsigned long *)regs->esp; #endif if (ra) return *ra; else return 0; } #ifdef __x86_64__ #include void _stp_print_regs(struct pt_regs * regs) { unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs; unsigned int fsindex,gsindex; unsigned int ds,cs,es; _stp_printf("\n"); // print_modules(); _stp_printf("Pid: %d, comm: %.20s %s\n", current->pid, current->comm, system_utsname.release); _stp_printf("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->rip); _stp_symbol_print (regs->rip); _stp_printf("\nRSP: %04lx:%016lx EFLAGS: %08lx\n", regs->ss, regs->rsp, regs->eflags); _stp_printf("RAX: %016lx RBX: %016lx RCX: %016lx\n", regs->rax, regs->rbx, regs->rcx); _stp_printf("RDX: %016lx RSI: %016lx RDI: %016lx\n", regs->rdx, regs->rsi, regs->rdi); _stp_printf("RBP: %016lx R08: %016lx R09: %016lx\n", regs->rbp, regs->r8, regs->r9); _stp_printf("R10: %016lx R11: %016lx R12: %016lx\n", regs->r10, regs->r11, regs->r12); _stp_printf("R13: %016lx R14: %016lx R15: %016lx\n", regs->r13, regs->r14, regs->r15); asm("movl %%ds,%0" : "=r" (ds)); asm("movl %%cs,%0" : "=r" (cs)); asm("movl %%es,%0" : "=r" (es)); asm("movl %%fs,%0" : "=r" (fsindex)); asm("movl %%gs,%0" : "=r" (gsindex)); rdmsrl(MSR_FS_BASE, fs); rdmsrl(MSR_GS_BASE, gs); rdmsrl(MSR_KERNEL_GS_BASE, shadowgs); asm("movq %%cr0, %0": "=r" (cr0)); asm("movq %%cr2, %0": "=r" (cr2)); asm("movq %%cr3, %0": "=r" (cr3)); asm("movq %%cr4, %0": "=r" (cr4)); _stp_printf("FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n", fs,fsindex,gs,gsindex,shadowgs); _stp_printf("CS: %04x DS: %04x ES: %04x CR0: %016lx\n", cs, ds, es, cr0); _stp_printf("CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3, cr4); _stp_print_flush(); } #endif /* __x86_64__ */ /** @} */ #endif /* _CURRENT_C_ */