setjmp.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2003-2004 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. This file is part of libunwind.
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files (the
  7. "Software"), to deal in the Software without restriction, including
  8. without limitation the rights to use, copy, modify, merge, publish,
  9. distribute, sublicense, and/or sell copies of the Software, and to
  10. permit persons to whom the Software is furnished to do so, subject to
  11. the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  21. #include <libunwind.h>
  22. #include <setjmp.h>
  23. #include "jmpbuf.h"
  24. /* Why use K&R syntax here? setjmp() is often a macro and that
  25. expands into a call to, say, __setjmp() and we need to define the
  26. libunwind-version of setjmp() with the name of the actual function.
  27. Using K&R syntax lets us keep the setjmp() macro while keeping the
  28. syntax valid... This trick works provided setjmp() doesn't do
  29. anything other than a function call. */
  30. int
  31. setjmp (env)
  32. jmp_buf env;
  33. {
  34. void **wp = (void **) env;
  35. /* this should work on most platforms, but may not be
  36. performance-optimal; check the code! */
  37. wp[JB_SP] = __builtin_frame_address (0);
  38. wp[JB_RP] = (void *) __builtin_return_address (0);
  39. return 0;
  40. }