gpt4 book ai didi

c - 有没有办法使用最新内核创建 vDSO?

转载 作者:行者123 更新时间:2023-11-30 14:40:49 28 4
gpt4 key购买 nike

我正在尝试使用最新的内核源代码创建 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com