aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2018-01-11 15:46:18 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-01-11 15:46:18 +0000
commit25a3087d6dde58e126c5ecb1033319ff333fcc59 (patch)
tree1789fb1df0c8befc8a678f3704d6f11445acfdd4
parentb1e90d29ac22cf9c33662bf11a8b63b7f8f5d37a (diff)
parent4473ccd5b002b70b04fbcfb1e7e1b93aec7f86d2 (diff)
downloadbionic-25a3087d6dde58e126c5ecb1033319ff333fcc59.tar.gz
Merge "bionic: add vdso time()"
-rw-r--r--libc/bionic/vdso.cpp10
-rw-r--r--libc/private/bionic_vdso.h4
-rw-r--r--libc/upstream-openbsd/lib/libc/gen/time.c6
3 files changed, 17 insertions, 3 deletions
diff --git a/libc/bionic/vdso.cpp b/libc/bionic/vdso.cpp
index 00d649039..44899e7cf 100644
--- a/libc/bionic/vdso.cpp
+++ b/libc/bionic/vdso.cpp
@@ -60,11 +60,21 @@ int gettimeofday(timeval* tv, struct timezone* tz) {
return __gettimeofday(tv, tz);
}
+time_t time(time_t* t) {
+ auto vdso_time = reinterpret_cast<decltype(&time)>(
+ __libc_globals->vdso[VDSO_TIME].fn);
+ if (__predict_true(vdso_time)) {
+ return vdso_time(t);
+ }
+ return __time(t);
+}
+
void __libc_init_vdso(libc_globals* globals, KernelArgumentBlock& args) {
auto&& vdso = globals->vdso;
vdso[VDSO_CLOCK_GETTIME] = { VDSO_CLOCK_GETTIME_SYMBOL, nullptr };
vdso[VDSO_CLOCK_GETRES] = { VDSO_CLOCK_GETRES_SYMBOL, nullptr };
vdso[VDSO_GETTIMEOFDAY] = { VDSO_GETTIMEOFDAY_SYMBOL, nullptr };
+ vdso[VDSO_TIME] = { VDSO_TIME_SYMBOL, nullptr };
// Do we have a vdso?
uintptr_t vdso_ehdr_addr = args.getauxval(AT_SYSINFO_EHDR);
diff --git a/libc/private/bionic_vdso.h b/libc/private/bionic_vdso.h
index ed11501e1..8c4d8d2aa 100644
--- a/libc/private/bionic_vdso.h
+++ b/libc/private/bionic_vdso.h
@@ -35,15 +35,18 @@
#define VDSO_CLOCK_GETTIME_SYMBOL "__kernel_clock_gettime"
#define VDSO_CLOCK_GETRES_SYMBOL "__kernel_clock_getres"
#define VDSO_GETTIMEOFDAY_SYMBOL "__kernel_gettimeofday"
+#define VDSO_TIME_SYMBOL "__kernel_time"
#else
#define VDSO_CLOCK_GETTIME_SYMBOL "__vdso_clock_gettime"
#define VDSO_CLOCK_GETRES_SYMBOL "__vdso_clock_getres"
#define VDSO_GETTIMEOFDAY_SYMBOL "__vdso_gettimeofday"
+#define VDSO_TIME_SYMBOL "__vdso_time"
#endif
extern "C" int __clock_gettime(int, timespec*);
extern "C" int __clock_getres(int, timespec*);
extern "C" int __gettimeofday(timeval*, struct timezone*);
+extern "C" time_t __time(time_t*);
struct vdso_entry {
const char* name;
@@ -54,6 +57,7 @@ enum {
VDSO_CLOCK_GETTIME = 0,
VDSO_CLOCK_GETRES,
VDSO_GETTIMEOFDAY,
+ VDSO_TIME,
VDSO_END
};
diff --git a/libc/upstream-openbsd/lib/libc/gen/time.c b/libc/upstream-openbsd/lib/libc/gen/time.c
index 6fcf1cde2..afe463b64 100644
--- a/libc/upstream-openbsd/lib/libc/gen/time.c
+++ b/libc/upstream-openbsd/lib/libc/gen/time.c
@@ -28,11 +28,12 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#include <sys/time.h>
#include <time.h>
-time_t
-time(time_t *t)
+__LIBC_HIDDEN__ time_t
+__time(time_t *t)
{
struct timeval tt;
@@ -42,4 +43,3 @@ time(time_t *t)
*t = (time_t)tt.tv_sec;
return (tt.tv_sec);
}
-DEF_STRONG(time);