|
Packit |
6c4009 |
/* Resolve function pointers to VDSO functions.
|
|
Packit |
6c4009 |
Copyright (C) 2005-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef _LIBC_VDSO_H
|
|
Packit |
6c4009 |
#define _LIBC_VDSO_H
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef SHARED
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sysdep-vdso.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
extern int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *)
|
|
Packit |
6c4009 |
attribute_hidden;
|
|
Packit |
6c4009 |
extern int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *);
|
|
Packit |
6c4009 |
extern int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *);
|
|
Packit |
6c4009 |
extern unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void);
|
|
Packit |
6c4009 |
extern int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *);
|
|
Packit |
6c4009 |
extern time_t (*VDSO_SYMBOL(time)) (time_t *);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if defined(__PPC64__) || defined(__powerpc64__)
|
|
Packit |
6c4009 |
extern void *VDSO_SYMBOL(sigtramp_rt64);
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
extern void *VDSO_SYMBOL(sigtramp32);
|
|
Packit |
6c4009 |
extern void *VDSO_SYMBOL(sigtramp_rt32);
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if (defined(__PPC64__) || defined(__powerpc64__)) && _CALL_ELF != 2
|
|
Packit |
6c4009 |
/* The correct solution is for _dl_vdso_vsym to return the address of the OPD
|
|
Packit |
6c4009 |
for the kernel VDSO function. That address would then be stored in the
|
|
Packit |
6c4009 |
__vdso_* variables and returned as the result of the IFUNC resolver function.
|
|
Packit |
6c4009 |
Yet, the kernel does not contain any OPD entries for the VDSO functions
|
|
Packit |
6c4009 |
(incomplete implementation). However, PLT relocations for IFUNCs still expect
|
|
Packit |
6c4009 |
the address of an OPD to be returned from the IFUNC resolver function (since
|
|
Packit |
6c4009 |
PLT entries on PPC64 are just copies of OPDs). The solution for now is to
|
|
Packit |
6c4009 |
create an artificial static OPD for each VDSO function returned by a resolver
|
|
Packit |
6c4009 |
function. The TOC value is set to a non-zero value to avoid triggering lazy
|
|
Packit |
6c4009 |
symbol resolution via .glink0/.plt0 for a zero TOC (requires thread-safe PLT
|
|
Packit |
6c4009 |
sequences) when the dynamic linker isn't prepared for it e.g. RTLD_NOW. None
|
|
Packit |
6c4009 |
of the kernel VDSO routines use the TOC or AUX values so any non-zero value
|
|
Packit |
6c4009 |
will work. Note that function pointer comparisons will not use this artificial
|
|
Packit |
6c4009 |
static OPD since those are resolved via ADDR64 relocations and will point at
|
|
Packit |
6c4009 |
the non-IFUNC default OPD for the symbol. Lastly, because the IFUNC relocations
|
|
Packit |
6c4009 |
are processed immediately at startup the resolver functions and this code need
|
|
Packit |
6c4009 |
not be thread-safe, but if the caller writes to a PLT slot it must do so in a
|
|
Packit |
6c4009 |
thread-safe manner with all the required barriers. */
|
|
Packit |
6c4009 |
#define VDSO_IFUNC_RET(value) \
|
|
Packit |
6c4009 |
({ \
|
|
Packit |
6c4009 |
static Elf64_FuncDesc vdso_opd = { .fd_toc = ~0x0 }; \
|
|
Packit |
6c4009 |
vdso_opd.fd_func = (Elf64_Addr)value; \
|
|
Packit |
6c4009 |
&vdso_opd; \
|
|
Packit |
6c4009 |
})
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
#define VDSO_IFUNC_RET(value) ((void *) (value))
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* _LIBC_VDSO_H */
|