diff --git a/libc/bionic/vdso.cpp b/libc/bionic/vdso.cpp index 8cdb504d4..969c39f03 100644 --- a/libc/bionic/vdso.cpp +++ b/libc/bionic/vdso.cpp @@ -26,11 +26,18 @@ #include #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( __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( __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(__clock_gettime) }; - vdso[VDSO_GETTIMEOFDAY] = { VDSO_GETTIMEOFDAY_SYMBOL, - reinterpret_cast(__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);