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

最佳答案

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

关于c - 有没有办法用最新的内核创建vDSO?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55357984/

10-09 13:16