2 * linux/arch/x86_64/kernel/vsyscall.c
4 * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
6 * Thanks to hpa@transmeta.com for some useful hint.
7 * Special thanks to Ingo Molnar for his early experience with
8 * a different vsyscall implementation for Linux/IA32 and for the name.
10 * vsyscall 1 is located at -10Mbyte, vsyscall 2 is located
11 * at virtual address -10Mbyte+1024bytes etc... There are at max 8192
12 * vsyscalls. One vsyscall can reserve more than 1 slot to avoid
13 * jumping out of line if necessary.
15 * $Id: vsyscall.c,v 1.26 2003/02/18 11:55:47 ak Exp $
21 * 1) make page fault handler detect faults on page1-page-last of the vsyscall
22 * virtual space, and make it increase %rip and write -ENOSYS in %rax (so
23 * we'll be able to upgrade to a new glibc without upgrading kernel after
24 * we add more vsyscalls.
25 * 2) Possibly we need a fixmap table for the vsyscalls too if we want
26 * to avoid SIGSEGV and we want to return -EFAULT from the vsyscalls as well.
27 * Can we segfault inside a "syscall"? We can fix this anytime and those fixes
28 * won't be visible for userspace. Not fixing this is a noop for correct programs,
29 * broken programs will segfault and there's no security risk until we choose to
32 * These are not urgent things that we need to address only before shipping the first
33 * production binary kernels.
36 #include <linux/time.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
41 #include <asm/vsyscall.h>
42 #include <asm/pgtable.h>
44 #include <asm/fixmap.h>
45 #include <asm/errno.h>
48 #include <asm/unistd.h>
50 #define __vsyscall(nr) __attribute__ ((unused,__section__(".vsyscall_" #nr)))
52 #define force_inline inline __attribute__((always_inline))
54 long __vxtime_sequence[2] __section_vxtime_sequence;
56 static force_inline void do_vgettimeofday(struct timeval * tv)
59 unsigned long sec, usec;
62 sequence = __vxtime_sequence[1];
66 usec = __xtime.tv_usec + (__jiffies - __wall_jiffies) * (1000000 / HZ);
68 switch (__vxtime.mode) {
73 usec += (((t - __vxtime.last_tsc) * __vxtime.tsc_quot) >> 32);
77 usec += ((readl(fix_to_virt(VSYSCALL_HPET) + 0xf0) - __vxtime.last) * __vxtime.quot) >> 32;
83 } while (sequence != __vxtime_sequence[0]);
85 tv->tv_sec = sec + usec / 1000000;
86 tv->tv_usec = usec % 1000000;
90 static force_inline void do_get_tz(struct timezone * tz)
95 sequence = __vxtime_sequence[1];
101 } while (sequence != __vxtime_sequence[0]);
104 static long __vsyscall(0) vgettimeofday(struct timeval * tv, struct timezone * tz)
107 do_vgettimeofday(tv);
115 static time_t __vsyscall(1) vtime(time_t * tp)
118 vgettimeofday(&tv, NULL);
119 if (tp) *tp = tv.tv_sec;
123 static long __vsyscall(2) venosys_0(void)
128 static long __vsyscall(3) venosys_1(void)
133 extern char vsyscall_syscall[], __vsyscall_0[];
135 static void __init map_vsyscall(void)
137 unsigned long physaddr_page0 = __pa_symbol(&__vsyscall_0);
138 __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_page0, PAGE_KERNEL_VSYSCALL);
140 __set_fixmap(VSYSCALL_HPET, hpet_address, PAGE_KERNEL_VSYSCALL);
143 static int __init vsyscall_init(void)
145 if ((unsigned long) &vgettimeofday != VSYSCALL_ADDR(__NR_vgettimeofday))
146 panic("vgettimeofday link addr broken");
147 if ((unsigned long) &vtime != VSYSCALL_ADDR(__NR_vtime))
148 panic("vtime link addr broken");
149 if (VSYSCALL_ADDR(0) != __fix_to_virt(VSYSCALL_FIRST_PAGE))
150 panic("fixmap first vsyscall %lx should be %lx", __fix_to_virt(VSYSCALL_FIRST_PAGE),
156 __initcall(vsyscall_init);