summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@amacapital.net>2014-02-27 16:17:54 -0800
committerAndy Lutomirski <luto@amacapital.net>2014-02-27 16:17:54 -0800
commitd92d6d30974c6545dffa3919ed9bd8460e3dff9a (patch)
tree9040843a8b243a0abcdaa22ddb9df24556de0ea0
parentd05e9b6ce09805af68dd10636f19ee3466a5efbc (diff)
downloadmisc-tests-d92d6d30974c6545dffa3919ed9bd8460e3dff9a.tar.gz
Fix test_vsyscall for 32-bit builds
-rw-r--r--test_vsyscall.cc34
1 files changed, 24 insertions, 10 deletions
diff --git a/test_vsyscall.cc b/test_vsyscall.cc
index b6a6a12..14c49bf 100644
--- a/test_vsyscall.cc
+++ b/test_vsyscall.cc
@@ -22,25 +22,33 @@ static inline int modify_ldt(int mode, void *ptr, unsigned long size)
return (ret == 0 ? 0 : -1);
}
+#ifdef __x86_64__
+# define VSYS(x) (x)
+#else
+# define VSYS(x) 0
+#endif
+
/* vsyscalls and vDSO */
typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz);
-const gtod_t vgtod = (gtod_t)0xffffffffff600000;
+const gtod_t vgtod = (gtod_t)VSYS(0xffffffffff600000);
gtod_t vdso_gtod;
typedef int (*vgettime_t)(clockid_t, timespec *);
vgettime_t vdso_gettime;
typedef long (*time_func_t)(time_t *t);
-const time_func_t vtime = (time_func_t)0xffffffffff600400;
+const time_func_t vtime = (time_func_t)VSYS(0xffffffffff600400);
time_func_t vdso_time;
typedef long (*getcpu_t)(unsigned *, unsigned *, struct getcpu_cache*);
-const getcpu_t vgetcpu = (getcpu_t)0xffffffffff600800;
+const getcpu_t vgetcpu = (getcpu_t)VSYS(0xffffffffff600800);
getcpu_t vdso_getcpu;
void init_vdso()
{
void *vdso = dlopen("linux-vdso.so.1", RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
+ if (!vdso)
+ vdso = dlopen("linux-gate.so.1", RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
if (!vdso) {
printf("Warning: failed to find vDSO\n");
return;
@@ -156,7 +164,9 @@ int test(int argc, char **argv)
int ret_vdso = -1;
if (vdso_gtod)
ret_vdso = vdso_gtod(&tv_vdso, &tz_vdso);
- int ret_vsys = vgtod(&tv_vsys, &tz_vsys);
+ int ret_vsys = -1;
+ if (vgtod)
+ vgtod(&tv_vsys, &tz_vsys);
if (ret_sys) {
printf(" syscall failed\n");
@@ -183,7 +193,8 @@ int test(int argc, char **argv)
t_sys = sys_time(&t2_sys);
if (vdso_time)
t_vdso = vdso_time(&t2_vdso);
- t_vsys = vtime(&t2_vsys);
+ if (vtime)
+ t_vsys = vtime(&t2_vsys);
if (t_sys < 0 || t_sys != t2_sys) {
printf(" syscall failed (ret:%ld output:%ld)\n", t_sys, t2_sys);
} else {
@@ -194,10 +205,12 @@ int test(int argc, char **argv)
printf(" vDSO offset = %ld\n", t_vdso - t_sys);
}
- if (t_vsys < 0 || t_vsys != t2_vsys)
- printf(" vsyscall failed (ret:%ld output:%ld)\n", t_vsys, t2_vsys);
- else
- printf(" vsyscall offset = %ld\n", t_vsys - t_sys);
+ if (vtime) {
+ if (t_vsys < 0 || t_vsys != t2_vsys)
+ printf(" vsyscall failed (ret:%ld output:%ld)\n", t_vsys, t2_vsys);
+ else
+ printf(" vsyscall offset = %ld\n", t_vsys - t_sys);
+ }
}
printf("Testing getcpu...\n");
@@ -205,7 +218,8 @@ int test(int argc, char **argv)
ret_sys = sys_getcpu(&cpu_sys, &node_sys, 0);
if (vdso_getcpu)
ret_vdso = vdso_getcpu(&cpu_vdso, &node_vdso, 0);
- ret_vsys = vgetcpu(&cpu_vsys, &node_vsys, 0);
+ if (vgetcpu)
+ ret_vsys = vgetcpu(&cpu_vsys, &node_vsys, 0);
if (!ret_sys)
printf(" syscall: cpu=%u node=%u\n", cpu_sys, node_sys);
if (ret_vdso && vdso_getcpu)