gettimeofday.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright (C) 2018-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. /* Get the current time of day and timezone information,
  15. putting it into *tv and *tz. If tz is null, *tz is not filled.
  16. Returns 0 on success, -1 on errors. */
  17. #ifdef SHARED
  18. # define __gettimeofday __redirect___gettimeofday
  19. # include <sys/time.h>
  20. # undef __gettimeofday
  21. # define HAVE_VSYSCALL
  22. # include <dl-vdso.h>
  23. # include <sysdep-vdso.h>
  24. /* Used as a fallback in the ifunc resolver if VDSO is not available
  25. and for libc.so internal __gettimeofday calls. */
  26. static int
  27. __gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz)
  28. {
  29. return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
  30. }
  31. /* PREPARE_VERSION will need an __LP64__ ifdef when ILP32 support
  32. goes in. See _libc_vdso_platform_setup in
  33. sysdeps/unix/sysv/linux/aarch64/init-first.c. */
  34. # undef INIT_ARCH
  35. # define INIT_ARCH() \
  36. PREPARE_VERSION (linux_version, "LINUX_2.6.39", 123718537); \
  37. void *vdso_gettimeofday = \
  38. _dl_vdso_vsym ("__kernel_gettimeofday", &linux_version);
  39. libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday,
  40. vdso_gettimeofday ?: (void *) __gettimeofday_vsyscall)
  41. __hidden_ver1 (__gettimeofday_vsyscall, __GI___gettimeofday,
  42. __gettimeofday_vsyscall);
  43. #else
  44. # include <sys/time.h>
  45. # include <sysdep.h>
  46. int
  47. __gettimeofday (struct timeval *tv, struct timezone *tz)
  48. {
  49. return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
  50. }
  51. libc_hidden_def (__gettimeofday)
  52. #endif
  53. weak_alias (__gettimeofday, gettimeofday)
  54. libc_hidden_weak (gettimeofday)