pt-cleanup.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <setjmp.h>
  17. #include <stdlib.h>
  18. #include "pthreadP.h"
  19. #include <jmpbuf-unwind.h>
  20. void
  21. /*does not apply due to hidden_proto(): attribute_protected*/
  22. __pthread_cleanup_upto (__jmp_buf target, char *targetframe)
  23. {
  24. struct pthread *self = THREAD_SELF;
  25. struct _pthread_cleanup_buffer *cbuf;
  26. /* Adjust all pointers used in comparisons, so that top of thread's
  27. stack is at the top of address space. Without that, things break
  28. if stack is allocated above the main stack. */
  29. uintptr_t adj = (uintptr_t) self->stackblock + self->stackblock_size;
  30. uintptr_t targetframe_adj = (uintptr_t) targetframe - adj;
  31. for (cbuf = THREAD_GETMEM (self, cleanup);
  32. cbuf != NULL && _JMPBUF_UNWINDS_ADJ (target, cbuf, adj);
  33. cbuf = cbuf->__prev)
  34. {
  35. #ifdef _STACK_GROWS_DOWN
  36. if ((uintptr_t) cbuf - adj <= targetframe_adj)
  37. {
  38. cbuf = NULL;
  39. break;
  40. }
  41. #elif defined _STACK_GROWS_UP
  42. if ((uintptr_t) cbuf - adj >= targetframe_adj)
  43. {
  44. cbuf = NULL;
  45. break;
  46. }
  47. #else
  48. # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
  49. #endif
  50. /* Call the cleanup code. */
  51. cbuf->__routine (cbuf->__arg);
  52. }
  53. THREAD_SETMEM (self, cleanup, cbuf);
  54. }
  55. hidden_def (__pthread_cleanup_upto)