[英]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.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通过更改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.