| 1 | /* gettimeofday - set time. Linux version. |
| 2 | Copyright (C) 2020 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public License as |
| 7 | published by the Free Software Foundation; either version 2.1 of the |
| 8 | License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | /* Optimize the function call by setting the PLT directly to vDSO symbol. */ |
| 20 | #ifdef USE_IFUNC_GETTIMEOFDAY |
| 21 | # include <time.h> |
| 22 | # include <string.h> |
| 23 | # include <sysdep.h> |
| 24 | # include <sysdep-vdso.h> |
| 25 | |
| 26 | # ifdef SHARED |
| 27 | # include <dl-vdso.h> |
| 28 | # include <libc-vdso.h> |
| 29 | |
| 30 | static int |
| 31 | __gettimeofday_syscall (struct timeval *restrict tv, void *restrict tz) |
| 32 | { |
| 33 | if (__glibc_unlikely (tz != 0)) |
| 34 | memset (tz, 0, sizeof *tz); |
| 35 | return INLINE_SYSCALL_CALL (gettimeofday, tv, tz); |
| 36 | } |
| 37 | |
| 38 | # undef INIT_ARCH |
| 39 | # define INIT_ARCH() \ |
| 40 | void *vdso_gettimeofday = dl_vdso_vsym (HAVE_GETTIMEOFDAY_VSYSCALL) |
| 41 | libc_ifunc (__gettimeofday, |
| 42 | vdso_gettimeofday ? VDSO_IFUNC_RET (vdso_gettimeofday) |
| 43 | : (void *) __gettimeofday_syscall) |
| 44 | |
| 45 | # else |
| 46 | int |
| 47 | __gettimeofday (struct timeval *restrict tv, void *restrict tz) |
| 48 | { |
| 49 | if (__glibc_unlikely (tz != 0)) |
| 50 | memset (tz, 0, sizeof *tz); |
| 51 | |
| 52 | return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); |
| 53 | } |
| 54 | # endif |
| 55 | weak_alias (__gettimeofday, gettimeofday) |
| 56 | #else /* USE_IFUNC_GETTIMEOFDAY */ |
| 57 | # include <time/gettimeofday.c> |
| 58 | #endif |
| 59 | |