1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This is the VDSO for sandboxed binaries. This file just contains the entry
// points to the VDSO. All of the real work is done in vdso_time.cc
#define _DEFAULT_SOURCE // ensure glibc provides struct timezone.
#include <sys/time.h>
#include <time.h>
#include "vdso/syscalls.h"
#include "vdso/vdso_time.h"
namespace vdso {
// __vdso_clock_gettime() implements clock_gettime()
extern "C" int __vdso_clock_gettime(clockid_t clock, struct timespec* ts) {
int ret;
switch (clock) {
case CLOCK_REALTIME:
ret = ClockRealtime(ts);
break;
case CLOCK_MONOTONIC:
ret = ClockMonotonic(ts);
break;
default:
ret = sys_clock_gettime(clock, ts);
break;
}
return ret;
}
extern "C" int clock_gettime(clockid_t clock, struct timespec* ts)
__attribute__((weak, alias("__vdso_clock_gettime")));
// __vdso_gettimeofday() implements gettimeofday()
extern "C" int __vdso_gettimeofday(struct timeval* tv, struct timezone* tz) {
if (tv) {
struct timespec ts;
int ret = ClockRealtime(&ts);
if (ret) {
return ret;
}
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
}
// Nobody should be calling gettimeofday() with a non-NULL
// timezone pointer. If they do then they will get zeros.
if (tz) {
tz->tz_minuteswest = 0;
tz->tz_dsttime = 0;
}
return 0;
}
extern "C" int gettimeofday(struct timeval* tv, struct timezone* tz)
__attribute__((weak, alias("__vdso_gettimeofday")));
// __vdso_time() implements time()
extern "C" time_t __vdso_time(time_t* t) {
struct timespec ts;
ClockRealtime(&ts);
if (t) {
*t = ts.tv_sec;
}
return ts.tv_sec;
}
extern "C" time_t time(time_t* t) __attribute__((weak, alias("__vdso_time")));
// __vdso_getcpu() implements getcpu()
extern "C" long __vdso_getcpu(unsigned* cpu, unsigned* node,
struct getcpu_cache* cache) {
// No optimizations yet, just make the real system call.
return sys_getcpu(cpu, node, cache);
}
extern "C" long getcpu(unsigned* cpu, unsigned* node,
struct getcpu_cache* cache)
__attribute__((weak, alias("__vdso_getcpu")));
} // namespace vdso
|