longjmp.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Copyright (C) 1991, 92, 94, 95, 97, 98, 2000 Free Software Foundation, Inc.
  2. Copyright (C) 2001 Hewlett-Packard Australia
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU Library General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option) any
  6. later version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
  10. details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this program; if not, write to the Free Software Foundation, Inc.,
  13. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. Derived in part from the Linux-8086 C library, the GNU C Library, and several
  15. other sundry sources. Files within this library are copyright by their
  16. respective copyright holders.
  17. */
  18. #include <stddef.h>
  19. #include <setjmp.h>
  20. #include <signal.h>
  21. extern int __longjmp(char *env, int val);
  22. extern int __sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
  23. /* Set the signal mask to the one specified in ENV, and jump
  24. to the position specified in ENV, causing the setjmp
  25. call there to return VAL, or 1 if VAL is 0. */
  26. void __libc_siglongjmp (sigjmp_buf env, int val)
  27. {
  28. if (env[0].__mask_was_saved)
  29. /* Restore the saved signal mask. */
  30. (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask,
  31. (sigset_t *) NULL);
  32. /* Call the machine-dependent function to restore machine state. */
  33. __longjmp ((char *) env[0].__jmpbuf, val ?: 1);
  34. }
  35. __asm__(".weak longjmp; longjmp = __libc_siglongjmp");
  36. __asm__(".weak _longjmp; _longjmp = __libc_siglongjmp");
  37. __asm__(".weak siglongjmp; siglongjmp = __libc_siglongjmp");
  38. __asm__(".weak __sigprocmask; __sigprocmask = sigprocmask");