简体   繁体   English

如何在 vvar.h 中为我的新 VSDO 函数正确创建一个新变量?

[英]How can I correctly create a new variable in vvar.h for my new VSDO func?

I am trying to declare a new variable in vvar.h and define it near my new VDSO function.我试图在vvar.h中声明一个新变量并在我的新 VDSO function 附近定义它。 So that I could use this variable in my vdso function.这样我就可以在我的 vdso function 中使用这个变量。

I have a question about VVar.我有一个关于 VVar 的问题。 According to the description in arch/x86/include/asm/vvar.h , when I declare here a new variable as DECLARE_VVAR(0, int, count) , I should use DEFINE_VVAR(type, name) to define this variable somewhere else.根据arch/x86/include/asm/vvar.h中的描述,当我在这里声明一个新变量为DECLARE_VVAR(0, int, count)时,我应该使用DEFINE_VVAR(type, name)在其他地方定义这个变量。

The problem is after I defined this variable somewhere else, like DEFINE_VVAR(int, count) , when I am trying to assign an integer value to this variable count , it is failed.问题是在我在其他地方定义了这个变量之后,比如DEFINE_VVAR(int, count) ,当我试图将 integer 值分配给这个变量count时,它失败了。 This is because after kernel version 5.2 #define DEFINE_VVAR(type, name) has been changed from #define DEFINE_VVAR(type, name) type name to #define DEFINE_VVAR(type, name) type name[CS_BASES] .这是因为在 kernel 版本 5.2 之后#define DEFINE_VVAR(type, name)已从#define DEFINE_VVAR(type, name) type name更改为#define DEFINE_VVAR(type, name) type name[CS_BASES] Right now this variable count is an integer array instead of type integer.现在这个变量count是一个 integer 数组,而不是类型 integer。 Therefore I can't assign a integer value to it.因此我无法为其分配 integer 值。 Do you know how to fix it?你知道如何解决吗?

VVAR.h: https://elixir.bootlin.com/linux/v5.12/source/arch/x86/include/asm/vvar.h#L43 VVAR.h: https://elixir.bootlin.com/linux/v5.12/source/arch/x86/include/asm/vvar.h#L43

Typically, you cannot add a variable simply through DECLARE_VVAR macro.通常,您不能简单地通过DECLARE_VVAR宏添加变量。

The first thing you have to be aware of is that .vvar is a page of memory located inside the memory (more specifically, before .vdso ) and could access by both kernel and userland.您必须知道的第一件事是.vvar是 memory 的页面,位于 memory 内部(更具体地说,在.vdso之前)并且可以由 Z50484C19F1AFDAF3841A0D821ED3 和用户访问You can see this inside the linker script https://elixir.bootlin.com/linux/latest/source/arch/x86/entry/vdso/vdso-layout.lds.S .您可以在 linker 脚本https://elixir.bootlin.com/linux/latest/source/arch/x86/entry/vdso/vdso-layout.lds.S中看到这一点。 For now, kernel already has a data structure `struct video to format the data inside this page.目前,kernel 已经有了一个数据结构 `struct video 来格式化这个页面里面的数据。

Second, assume you want to add a variable inside the .vvar page and access it in your new vdso function, the easiest way is to add it inside the sturct vdso structure of include/vdso/datapage.h: https://elixir.bootlin.com/linux/latest/source/include/vdso/datapage.h .其次,假设您要在.vvar页面中添加一个变量并在新的 vdso function 中访问它,最简单的方法是将其添加到 include/vdso/datapage.h 的sturct vdso结构中: https://elixir。 bootlin.com/linux/latest/source/include/vdso/datapage.h After that, you can update them inside the kernel (for example, in schedule) in the same way as other vvar variables.之后,您可以像其他 vvar 变量一样在 kernel(例如,按计划)内更新它们。

Second, if you want to own your own vvar page, you have to define your own vvar data structure inside the datapage.h and do not forget DEFINE_VVAR in vsyscall.h : https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/vdso/vsyscall.h ALso, since the vvar memory layout is compact, you also need to allocate another page through linker script: https://elixir.bootlin.com/linux/latest/source/arch/x86/entry/vdso/vdso-layout.lds.S by change vvar_start =. - 4 * PAGE_SIZE;其次,如果你想拥有自己的 vvar 页面,你必须在vsyscall.h中定义自己的 vvar 数据结构,不要忘记DEFINE_VVAR中的datapage.hhttps://elixir.bootlin.com/linux/latest/ source/arch/x86/include/asm/vdso/vsyscall.h ALso , since the vvar memory layout is compact, you also need to allocate another page through linker script: https://elixir.bootlin.com/linux/latest/ source/arch/x86/entry/vdso/vdso-layout.lds.S通过更改vvar_start =. - 4 * PAGE_SIZE; vvar_start =. - 4 * PAGE_SIZE; into vvar_start =. - 5 * PAGE_SIZE;进入vvar_start =. - 5 * PAGE_SIZE; vvar_start =. - 5 * PAGE_SIZE;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 shell 脚本中动态生成新的变量名? - How can I generate new variable names on the fly in a shell script? 导出新变量时如何合并变量名? - How can I combine a variable name when export a new variable? 如何以编程方式创建新的 cron 作业? - How can I programmatically create a new cron job? 如何在我的Android设备上创建新的虚拟鼠标设备? - How can i create new virtual mouse device on my android device? 如何将 /var/log/syslog 中的每条新记录接收到我的 Net Core 守护程序 - How I can receice each new record in /var/log/syslog to my Net Core daemon 在linux中创建一个新的环境变量[openwrt] - create a new environment variable in linux [openwrt] 我如何在新终端中开始bash? - How i can start bash in a new terminal? 在执行bash脚本期间如何更改用户身份,并继续以新用户身份运行命令? - How can I change users in during my bash script excecution and continue running commands with the new user? 如果在 Ubuntu18.04 上安装了两个 perl 版本,我怎样才能将新的 perl 版本设为默认? - If there are two perl versions installled on Ubuntu18.04, how can I make the new perl version my default? 我如何重新启动我的网站并将新更改应用到 docker 容器? - How can i restart my website and apply new changes to a docker container?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM