1

我正在尝试使用最新的内核源代码进行 vDSO。我正在关注本教程https://www.linuxjournal.com/content/creating-vdso-colonels-other-chicken?page=0,0 但是我没有在 linux- 中找到一些函数,如 update_vsyscall() 和 vdso 目录4.20.13/arch/x86/vdso。我的问题是:有没有办法使用新的内核代码进行虚拟系统调用,例如 gettimeofday()?

4

1 回答 1

4

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

比如直接在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: *;
    };
 }

在用户态写一个测试用例

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;
}
于 2019-03-28T03:21:46.217 回答