问题描述
我正在编写一个内核系统调用,我想读取用户的基本指针寄存器(RBP)。也许我可以使用传递给参数的pt_regs
结构来做到这一点,不是吗?
示例代码:
unsigned long int data;
asmlinkage int my_read(int d)
{
get_rbp_of_userStack(&data);#or somthing like that
}
我知道这些数据保存在上下文切换的某个地方,如何获取?
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();
}
解决方法
您可以使用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;
}