I'm trying to do a vDSO using latest kernel source code. 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. My question is: is there a way to make a virtual syscall, like gettimeofday(), using the new kernel codes?
vdso directory in
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
For example, add a function directly to vclock_gettime.c, rebuild the kernel, and reboot
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
#include <stdio.h>
extern int __vdso_add(int x, int y);
int main()
{
printf("vdso_add: %d\n", __vdso_add(1, 3));
return 0;
}