GNU Linux-libre 4.14.313-gnu1
[releases.git] / arch / x86 / um / vdso / um_vdso.c
1 /*
2  * Copyright (C) 2011 Richard Weinberger <richrd@nod.at>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This vDSO turns all calls into a syscall so that UML can trap them.
9  */
10
11
12 /* Disable profiling for userspace code */
13 #define DISABLE_BRANCH_PROFILING
14
15 #include <linux/time.h>
16 #include <linux/getcpu.h>
17 #include <asm/unistd.h>
18
19 int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
20 {
21         long ret;
22
23         asm("syscall"
24                 : "=a" (ret)
25                 : "0" (__NR_clock_gettime), "D" (clock), "S" (ts)
26                 : "rcx", "r11", "memory");
27
28         return ret;
29 }
30 int clock_gettime(clockid_t, struct timespec *)
31         __attribute__((weak, alias("__vdso_clock_gettime")));
32
33 int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
34 {
35         long ret;
36
37         asm("syscall"
38                 : "=a" (ret)
39                 : "0" (__NR_gettimeofday), "D" (tv), "S" (tz)
40                 : "rcx", "r11", "memory");
41
42         return ret;
43 }
44 int gettimeofday(struct timeval *, struct timezone *)
45         __attribute__((weak, alias("__vdso_gettimeofday")));
46
47 time_t __vdso_time(time_t *t)
48 {
49         long secs;
50
51         asm volatile("syscall"
52                 : "=a" (secs)
53                 : "0" (__NR_time), "D" (t) : "cc", "r11", "cx", "memory");
54
55         return secs;
56 }
57 int time(time_t *t) __attribute__((weak, alias("__vdso_time")));
58
59 long
60 __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused)
61 {
62         /*
63          * UML does not support SMP, we can cheat here. :)
64          */
65
66         if (cpu)
67                 *cpu = 0;
68         if (node)
69                 *node = 0;
70
71         return 0;
72 }
73
74 long getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
75         __attribute__((weak, alias("__vdso_getcpu")));