vdso.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Copyright (C) 2018 Intel Corporation
  2. Isaku Yamahata <isaku.yamahata at gmail.com>
  3. <isaku.yamahata at intel.com>
  4. All Rights Reserved.
  5. This file is part of Graphene Library OS.
  6. Graphene Library OS is free software: you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public License
  8. as published by the Free Software Foundation, either version 3 of the
  9. License, or (at your option) any later version.
  10. Graphene Library OS 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
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <shim_types.h>
  18. /*
  19. * The symbols below need to be exported for libsysdb to inject those values,
  20. * but relocation (.rela.dyn section) isn't wanted in the code generation.
  21. */
  22. #define EXPORT_SYMBOL(name) extern __typeof__(name) __vdso_##name __attribute__((alias(#name)))
  23. static int (*shim_clock_gettime)(clockid_t clock, struct timespec* t) = NULL;
  24. static int (*shim_gettimeofday)(struct timeval* tv, struct timezone* tz) = NULL;
  25. static time_t (*shim_time)(time_t* t) = NULL;
  26. static long (*shim_getcpu)(unsigned* cpu, struct getcpu_cache* unused) = NULL;
  27. EXPORT_SYMBOL(shim_clock_gettime);
  28. EXPORT_SYMBOL(shim_gettimeofday);
  29. EXPORT_SYMBOL(shim_time);
  30. EXPORT_SYMBOL(shim_getcpu);
  31. #define EXPORT_WEAK_SYMBOL(name) \
  32. __typeof__(__vdso_##name) name __attribute__((weak, alias("__vdso_" #name)))
  33. int __vdso_clock_gettime(clockid_t clock, struct timespec* t) {
  34. if (shim_clock_gettime)
  35. return (*shim_clock_gettime)(clock, t);
  36. return -ENOSYS;
  37. }
  38. EXPORT_WEAK_SYMBOL(clock_gettime);
  39. int __vdso_gettimeofday(struct timeval* tv, struct timezone* tz) {
  40. if (shim_gettimeofday)
  41. return (*shim_gettimeofday)(tv, tz);
  42. return -ENOSYS;
  43. }
  44. EXPORT_WEAK_SYMBOL(gettimeofday);
  45. time_t __vdso_time(time_t* t) {
  46. if (shim_time)
  47. return (*shim_time)(t);
  48. return -ENOSYS;
  49. }
  50. EXPORT_WEAK_SYMBOL(time);
  51. long __vdso_getcpu(unsigned* cpu, struct getcpu_cache* unused) {
  52. if (shim_getcpu)
  53. return (*shim_getcpu)(cpu, unused);
  54. return -ENOSYS;
  55. }
  56. EXPORT_WEAK_SYMBOL(getcpu);