从内核syscall获取用户空间RBP注册 [英] Get userspace RBP register from kernel syscall

查看:187
本文介绍了从内核syscall获取用户空间RBP注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个内核系统调用,我想读取用户的基本指针寄存器(RBP).也许我可以使用为参数传递的pt_regs结构来做到这一点,不是吗?

I am writing a kernel system call and I want to read the base pointer register (RBP) of the user. Maybe I can do that using the pt_regs struct that is passed for parameter, isn't it?

示例代码:

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?

这是我的用户代码

 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):

#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;
}

这篇关于从内核syscall获取用户空间RBP注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆