简体   繁体   English

有没有办法用最新的 kernel 创建 vDSO?

[英]Is there a way to create a vDSO with the latest kernel?

I'm trying to do a vDSO using latest kernel source code.我正在尝试使用最新的 kernel 源代码进行 vDSO。 I was following this tutorial https://www.linuxjournal.com/content/creating-vdso-colonels-other-chicken?page=0,0 However I didn't find some functions like update_vsyscall() and vdso directory in linux-4.20.13/arch/x86/vdso.我正在关注本教程https://www.linuxjournal.com/content/creating-vdso-colonels-other-chicken?page=0,0但是我没有在 linux 中找到一些函数,如 update_vsyscall() 和 vdso 目录- 4.20.13/arch/x86/vdso。 My question is: is there a way to make a virtual syscall, like gettimeofday(), using the new kernel codes?我的问题是:有没有办法使用新的 kernel 代码进行虚拟系统调用,例如 gettimeofday()?

vdso directory in vdso目录

arch/x86/entry/vdso

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/x86/entry/vdso?h=v4.20.13 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/arch/x86/entry/vdso?h=v4.20.13

For example, add a function directly to vclock_gettime.c, rebuild the kernel, and reboot 例如,直接向vclock_gettime.c添加一个函数,重建内核,然后重新启动

diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c
index 007b3fe9d727..a49bef48a9dc 100644
--- a/arch/x86/entry/vdso/vclock_gettime.c
+++ b/arch/x86/entry/vdso/vclock_gettime.c
@@ -238,3 +238,8 @@ notrace time_t __vdso_time(time_t *t)
 }
 time_t time(time_t *t)
    __attribute__((weak, alias("__vdso_time")));
+
+notrace int __vdso_add(int x, int y)
+{
+   return x + y;
+}
diff --git a/arch/x86/entry/vdso/vdso.lds.S b/arch/x86/entry/vdso/vdso.lds.S
index d3a2dce4cfa9..4b976c119845 100644
--- a/arch/x86/entry/vdso/vdso.lds.S
+++ b/arch/x86/entry/vdso/vdso.lds.S
@@ -25,6 +25,7 @@ VERSION {
            __vdso_getcpu;
            time;
            __vdso_time;
+           __vdso_add;
    local: *;
    };
 }

Write a test case in user mode 在用户模式下编写测试用例

gcc -otest test.c vdso64.so gcc -otest test.c vdso64.so

#include <stdio.h>

extern int __vdso_add(int x, int y);

int main()
{
    printf("vdso_add: %d\n", __vdso_add(1, 3));
    return 0;
}

Please see example in linux kernel /src/Documentation/vDSO/vdso_test.c.请参阅 linux kernel /src/Documentation/vDSO/vdso_test.c 中的示例。 not sure how the main() above will work without call vdso_sym() for example, in vdso_test.c to use gettimeofday:不确定上面的 main() 如何在不调用vdso_sym()的情况下工作,例如,在 vdso_test.c 中使用 gettimeofday:

gtod_t gtod = (gtod_t)vdso_sym("LINUX_2.6", "__vdso_gettimeofday");

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM