longjmp.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* __libc_siglongjmp for x86.
  2. Copyright (C) 2018-2026 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. <https://www.gnu.org/licenses/>. */
  15. #define __libc_longjmp __redirect___libc_longjmp
  16. #include <setjmp/longjmp.c>
  17. #undef __libc_longjmp
  18. extern void __longjmp_cancel (__jmp_buf __env, int __val)
  19. __attribute__ ((__noreturn__)) attribute_hidden;
  20. /* Since __libc_longjmp is a private interface for cancellation
  21. implementation in libpthread, there is no need to restore shadow
  22. stack register. */
  23. void
  24. __libc_longjmp (sigjmp_buf env, int val)
  25. {
  26. /* Perform any cleanups needed by the frames being unwound. */
  27. _longjmp_unwind (env, val);
  28. if (env[0].__mask_was_saved)
  29. /* Restore the saved signal mask. */
  30. (void) __sigprocmask (SIG_SETMASK,
  31. (sigset_t *) &env[0].__saved_mask,
  32. (sigset_t *) NULL);
  33. /* Call the machine-dependent function to restore machine state
  34. without shadow stack. */
  35. __longjmp_cancel (env[0].__jmpbuf, val ?: 1);
  36. }