sysdep-vdso.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* vDSO common definition for Linux.
  2. Copyright (C) 2015-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef SYSDEP_VDSO_LINUX_H
  16. # define SYSDEP_VDSO_LINUX_H
  17. #define VDSO_SYMBOL(__name) __vdso_##__name
  18. #ifndef INTERNAL_VSYSCALL_CALL
  19. # define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \
  20. funcptr (args)
  21. #endif
  22. #if USE_VSYSCALL && defined HAVE_VSYSCALL
  23. # include <libc-vdso.h>
  24. # define INLINE_VSYSCALL(name, nr, args...) \
  25. ({ \
  26. __label__ out; \
  27. __label__ iserr; \
  28. INTERNAL_SYSCALL_DECL (sc_err); \
  29. long int sc_ret; \
  30. \
  31. __typeof (__vdso_##name) vdsop = __vdso_##name; \
  32. PTR_DEMANGLE (vdsop); \
  33. if (vdsop != NULL) \
  34. { \
  35. sc_ret = INTERNAL_VSYSCALL_CALL (vdsop, sc_err, nr, ##args); \
  36. if (!INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
  37. goto out; \
  38. if (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err) != ENOSYS) \
  39. goto iserr; \
  40. } \
  41. \
  42. sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, ##args); \
  43. if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
  44. { \
  45. iserr: \
  46. __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
  47. sc_ret = -1L; \
  48. } \
  49. out: \
  50. sc_ret; \
  51. })
  52. # define INTERNAL_VSYSCALL(name, err, nr, args...) \
  53. ({ \
  54. __label__ out; \
  55. long v_ret; \
  56. \
  57. __typeof (__vdso_##name) vdsop = __vdso_##name; \
  58. PTR_DEMANGLE (vdsop); \
  59. if (vdsop != NULL) \
  60. { \
  61. v_ret = INTERNAL_VSYSCALL_CALL (vdsop, err, nr, ##args); \
  62. if (!INTERNAL_SYSCALL_ERROR_P (v_ret, err) \
  63. || INTERNAL_SYSCALL_ERRNO (v_ret, err) != ENOSYS) \
  64. goto out; \
  65. } \
  66. v_ret = INTERNAL_SYSCALL (name, err, nr, ##args); \
  67. out: \
  68. v_ret; \
  69. })
  70. #else
  71. # define INLINE_VSYSCALL(name, nr, args...) \
  72. INLINE_SYSCALL (name, nr, ##args)
  73. # define INTERNAL_VSYSCALL(name, err, nr, args...) \
  74. INTERNAL_SYSCALL (name, err, nr, ##args)
  75. #endif /* USE_VSYSCALL && defined HAVE_VSYSCALL */
  76. #endif /* SYSDEP_VDSO_LINUX_H */