The Pedigree Project  0.1
glue-infoblock.c
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 // Contains implementations of syscalls that use global info blocks instead of
21 // native syscalls proper.
22 
23 #include <stdint.h>
24 #include <sys/select.h>
25 #include <time.h>
26 
27 #include "pedigree/kernel/process/InfoBlock.h"
28 
30 static struct InfoBlock *infoBlock = (struct InfoBlock *) 0xFFFFFFFF8FFF0000;
31 
32 struct getcpu_cache;
33 
34 int __vdso_clock_gettime(clockid_t clock_id, struct timespec *tp);
35 int __vdso_gettimeofday(struct timeval *tv, void *tz);
36 int __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *cache);
37 time_t __vdso_time(time_t *tloc);
38 
39 int __vdso_clock_gettime(clockid_t clock_id, struct timespec *tp)
40 {
41  // 'now' is in nanoseconds.
43  uint64_t now = infoBlock->now;
44  tp->tv_sec = now / 1000000000U;
45  tp->tv_nsec = now % 1000000000U;
46 
47  return 0;
48 }
49 
50 int __vdso_gettimeofday(struct timeval *tv, void *tz)
51 {
52  if (tv)
53  {
54  // 'now' is in nanoseconds.
55  uint64_t now = infoBlock->now;
56  tv->tv_sec = now / 1000000000U;
57  tv->tv_usec = now / 1000U;
58  }
59 
61 
62  return 0;
63 }
64 
65 int __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *cache)
66 {
67  if (cpu)
68  {
69  *cpu = 0;
70  }
71 
72  if (node)
73  {
74  *node = 0;
75  }
76 
77  return 0;
78 }
79 
80 time_t __vdso_time(time_t *tloc)
81 {
82  if (tloc)
83  {
84  *tloc = infoBlock->now_s;
85  }
86 
87  return infoBlock->now_s;
88 }
89 
90 __asm__(".symver __vdso_clock_gettime,__vdso_clock_gettime@LINUX_2.6");
91 __asm__(".symver __vdso_gettimeofday,__vdso_gettimeofday@LINUX_2.6");
92 __asm__(".symver __vdso_getcpu,__vdso_getcpu@LINUX_2.6");
93 __asm__(".symver __vdso_time,__vdso_time@LINUX_2.6");
94 
95 int clock_gettime(clockid_t, struct timespec *)
96  __attribute__((weak, alias("__vdso_clock_gettime")));
97 int gettimeofday(struct timeval *__restrict, void *__restrict)
98  __attribute__((weak, alias("__vdso_gettimeofday")));
99 int getcpu(unsigned *, unsigned *, struct getcpu_cache *)
100  __attribute__((weak, alias("__vdso_getcpu")));
101 time_t time(time_t *) __attribute__((weak, alias("__vdso_time")));
uint64_t now
Current timestamp in nanoseconds since the UNIX epoch.
Definition: InfoBlock.h:32
uint64_t now_s
Current timestamp in seconds since the UNIX epoch.
Definition: InfoBlock.h:35