setjmp.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright (C) 1991-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <setjmp.h>
  15. /* Save the current program position in ENV and return 0. */
  16. int
  17. inhibit_stack_protector
  18. #if defined BSD_SETJMP
  19. # undef setjmp
  20. # define savemask 1
  21. setjmp (jmp_buf env)
  22. #elif defined BSD__SETJMP
  23. # undef _setjmp
  24. # define savemask 0
  25. _setjmp (jmp_buf env)
  26. #else
  27. __sigsetjmp (jmp_buf env, int savemask)
  28. #endif
  29. {
  30. /* Save data registers D1 through D7. */
  31. asm volatile ("movem%.l %/d1-%/d7, %0"
  32. : : "m" (env[0].__jmpbuf[0].__dregs[0]));
  33. /* Save return address in place of register A0. */
  34. env[0].__jmpbuf[0].__aregs[0] = __builtin_return_address (0);
  35. /* Save address registers A1 through A5. */
  36. asm volatile ("movem%.l %/a1-%/a5, %0"
  37. : : "m" (env[0].__jmpbuf[0].__aregs[1]));
  38. /* Save caller's FP, not our own. */
  39. env[0].__jmpbuf[0].__fp = *(int **) __builtin_frame_address (0);
  40. /* Save caller's SP, not our own. */
  41. env[0].__jmpbuf[0].__sp = (int *) __builtin_frame_address (0) + 2;
  42. #if defined __HAVE_68881__ || defined __HAVE_FPU__
  43. /* Save floating-point (68881) registers FP0 through FP7. */
  44. asm volatile ("fmovem%.x %/fp0-%/fp7, %0"
  45. : : "m" (env[0].__jmpbuf[0].__fpregs[0]));
  46. #elif defined (__mcffpu__)
  47. asm volatile ("fmovem %/fp0-%/fp7, %0"
  48. : : "m" (env[0].__jmpbuf[0].__fpregs[0]));
  49. #endif
  50. #if IS_IN (rtld)
  51. /* In ld.so we never save the signal mask. */
  52. return 0;
  53. #else
  54. /* Save the signal mask if requested. */
  55. return __sigjmp_save (env, savemask);
  56. #endif
  57. }
  58. #if !defined BSD_SETJMP && !defined BSD__SETJMP
  59. libc_hidden_def (__sigsetjmp)
  60. #endif