pt-longjmp.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* ABI compatibility for 'longjmp' and 'siglongjmp' symbols in libpthread ABI.
  2. X86 version.
  3. Copyright (C) 1918-2019 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  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
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <pthreadP.h>
  17. #include <jmp_buf-ssp.h>
  18. #ifdef __x86_64__
  19. # define SHADOW_STACK_POINTER_SIZE 8
  20. #else
  21. # define SHADOW_STACK_POINTER_SIZE 4
  22. #endif
  23. /* Assert that the priv field in struct pthread_unwind_buf has space
  24. to store shadow stack pointer. */
  25. _Static_assert ((offsetof (struct pthread_unwind_buf, priv)
  26. <= SHADOW_STACK_POINTER_OFFSET)
  27. && ((offsetof (struct pthread_unwind_buf, priv)
  28. + sizeof (((struct pthread_unwind_buf *) 0)->priv))
  29. >= (SHADOW_STACK_POINTER_OFFSET
  30. + SHADOW_STACK_POINTER_SIZE)),
  31. "Shadow stack pointer is not within private storage "
  32. "of pthread_unwind_buf.");
  33. #include <shlib-compat.h>
  34. /* libpthread once had its own longjmp (and siglongjmp alias), though there
  35. was no apparent reason for it. There is no use in having a separate
  36. symbol in libpthread, but the historical ABI requires it. For static
  37. linking, there is no need to provide anything here--the libc version
  38. will be linked in. For shared library ABI compatibility, there must be
  39. longjmp and siglongjmp symbols in libpthread.so.
  40. With an IFUNC resolver, it would be possible to avoid the indirection,
  41. but the IFUNC resolver might run before the __libc_longjmp symbol has
  42. been relocated, in which case the IFUNC resolver would not be able to
  43. provide the correct address. */
  44. #if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_22)
  45. static void __attribute__ ((noreturn, used))
  46. longjmp_compat (jmp_buf env, int val)
  47. {
  48. /* NB: We call __libc_siglongjmp, instead of __libc_longjmp, since
  49. __libc_longjmp is a private interface for cancellation which
  50. doesn't restore shadow stack register. */
  51. __libc_siglongjmp (env, val);
  52. }
  53. strong_alias (longjmp_compat, longjmp_alias)
  54. compat_symbol (libpthread, longjmp_alias, longjmp, GLIBC_2_0);
  55. strong_alias (longjmp_alias, siglongjmp_alias)
  56. compat_symbol (libpthread, siglongjmp_alias, siglongjmp, GLIBC_2_0);
  57. #endif