[英]Get userspace RBP register from kernel syscall
I am writing a kernel system call and I want to read the base pointer register (RBP) of the user.我正在编写内核系统调用,我想读取用户的基指针寄存器 (RBP)。 Maybe I can do that using the
pt_regs
struct that is passed for parameter, isn't it?也许我可以使用为参数传递的
pt_regs
结构来做到这一点,不是吗?
Example code:示例代码:
unsigned long int data;
asmlinkage int my_read(int d)
{
get_rbp_of_userStack(&data);#or somthing like that
}
I know this data saved somewhere for the context switch, how can I get to it?我知道这些数据保存在某处用于上下文切换,我怎样才能得到它?
this is my user code这是我的用户代码
void rar()
{//rbp here should be rsp when it call so it basically the return addres of the main
char t[10];
getchar();
}
int main()
{
rar();
}
You can use the task_pt_regs()
macro to get the current
task's user registers (saved at the moment of syscall entry):您可以使用
task_pt_regs()
宏来获取current
任务的用户寄存器(在进入系统调用时保存):
#include <asm/processor.h>
SYSCALL_DEFINE1(foo, int, d)
{
const struct pt_regs *user_regs = task_pt_regs(current);
unsigned long rbp = user_regs->bp;
/ * Do whatever you need... */
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.