diff options
Diffstat (limited to 'runtime/current.c')
-rw-r--r-- | runtime/current.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/runtime/current.c b/runtime/current.c new file mode 100644 index 00000000..78820c40 --- /dev/null +++ b/runtime/current.c @@ -0,0 +1,34 @@ +#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; +} +/** @} */ +#endif /* _CURRENT_C_ */ |