Merge "bionic: add vdso time()"

This commit is contained in:
Treehugger Robot 2018-01-11 15:46:18 +00:00 committed by Gerrit Code Review
commit 25a3087d6d
3 changed files with 17 additions and 3 deletions

View File

@ -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);

View File

@ -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
};

View File

@ -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);