dl-vdso-calls.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef _DL_VDSO_CALLS_H
  2. #define _DL_VDSO_CALLS_H
  3. #include <sys/time.h>
  4. #include <sys/syscall.h>
  5. #include <errno.h>
  6. #include <time.h>
  7. void __attribute__((weak)) *_get__dl__vdso_clock_gettime(void);
  8. #if defined(__UCLIBC_USE_TIME64__)
  9. #include "internal/time64_helpers.h"
  10. void __attribute__((weak)) *_get__dl__vdso_clock_gettime64(void);
  11. typedef int (*clock_gettime_func)(clockid_t clock_id, struct __ts64_struct *tp);
  12. #else
  13. typedef int (*clock_gettime_func)(clockid_t clock_id, struct timespec *tp);
  14. #endif
  15. extern int __libc_clock_gettime(clockid_t clock_id, struct timespec *tp);
  16. static int __attribute__ ((used)) __generic_vdso_clock_gettime(clockid_t clock_id, struct timespec *tp);
  17. static int __attribute__ ((used)) __generic_vdso_clock_gettime(clockid_t clock_id, struct timespec *tp)
  18. {
  19. void *impl = NULL;
  20. #if defined(__UCLIBC_USE_TIME64__)
  21. if (&_get__dl__vdso_clock_gettime64 && (impl = _get__dl__vdso_clock_gettime64())) {
  22. struct __ts64_struct __ts64;
  23. int __ret = ((clock_gettime_func)impl)(clock_id, &__ts64);
  24. if (__ret != 0) {
  25. __set_errno(-__ret);
  26. return -1;
  27. }
  28. if (tp) {
  29. tp->tv_sec = __ts64.tv_sec;
  30. tp->tv_nsec = __ts64.tv_nsec;
  31. }
  32. return 0;
  33. }
  34. /* fallback to syscall */
  35. return __libc_clock_gettime(clock_id, tp);
  36. #else
  37. if (&_get__dl__vdso_clock_gettime && (impl = _get__dl__vdso_clock_gettime())) {
  38. int __ret = ((clock_gettime_func)impl)(clock_id, tp);
  39. if (__ret != 0) {
  40. __set_errno(-__ret);
  41. return -1;
  42. }
  43. return 0;
  44. }
  45. /* fallback to syscall */
  46. return __libc_clock_gettime(clock_id, tp);
  47. #endif
  48. }
  49. static int __attribute__ ((used)) __generic_vdso_gettimeofday(struct timeval *tv, __timezone_ptr_t tz)
  50. {
  51. struct timespec ts;
  52. int __res = __generic_vdso_clock_gettime(CLOCK_REALTIME, &ts);
  53. tv->tv_sec = ts.tv_sec;
  54. tv->tv_usec = (suseconds_t)ts.tv_nsec / 1000;
  55. return __res;
  56. }
  57. #endif /* _DL_VDSO_CALLS_H */