Merge "Fix vdso system call fallback failures."

This commit is contained in:
Treehugger Robot 2017-11-28 19:05:18 +00:00 committed by Gerrit Code Review
commit 7d5777ef15
1 changed files with 11 additions and 6 deletions

View File

@ -26,11 +26,18 @@
#include <unistd.h>
#include "private/KernelArgumentBlock.h"
static inline int vdso_return(int result) {
if (__predict_true(result == 0)) return 0;
errno = -result;
return -1;
}
int clock_gettime(int clock_id, timespec* tp) {
auto vdso_clock_gettime = reinterpret_cast<decltype(&clock_gettime)>(
__libc_globals->vdso[VDSO_CLOCK_GETTIME].fn);
if (__predict_true(vdso_clock_gettime)) {
return vdso_clock_gettime(clock_id, tp);
return vdso_return(vdso_clock_gettime(clock_id, tp));
}
return __clock_gettime(clock_id, tp);
}
@ -39,17 +46,15 @@ int gettimeofday(timeval* tv, struct timezone* tz) {
auto vdso_gettimeofday = reinterpret_cast<decltype(&gettimeofday)>(
__libc_globals->vdso[VDSO_GETTIMEOFDAY].fn);
if (__predict_true(vdso_gettimeofday)) {
return vdso_gettimeofday(tv, tz);
return vdso_return(vdso_gettimeofday(tv, tz));
}
return __gettimeofday(tv, tz);
}
void __libc_init_vdso(libc_globals* globals, KernelArgumentBlock& args) {
auto&& vdso = globals->vdso;
vdso[VDSO_CLOCK_GETTIME] = { VDSO_CLOCK_GETTIME_SYMBOL,
reinterpret_cast<void*>(__clock_gettime) };
vdso[VDSO_GETTIMEOFDAY] = { VDSO_GETTIMEOFDAY_SYMBOL,
reinterpret_cast<void*>(__gettimeofday) };
vdso[VDSO_CLOCK_GETTIME] = { VDSO_CLOCK_GETTIME_SYMBOL, nullptr };
vdso[VDSO_GETTIMEOFDAY] = { VDSO_GETTIMEOFDAY_SYMBOL, nullptr };
// Do we have a vdso?
uintptr_t vdso_ehdr_addr = args.getauxval(AT_SYSINFO_EHDR);