Back to index

glibc  2.9
ptcleanup.c
Go to the documentation of this file.
00001 /* Linuxthreads - a simple clone()-based implementation of Posix        */
00002 /* threads for Linux.                                                   */
00003 /* Copyright (C) 1998 Xavier Leroy (Xavier.Leroy@inria.fr)             */
00004 /*                                                                      */
00005 /* This program is free software; you can redistribute it and/or        */
00006 /* modify it under the terms of the GNU Library General Public License  */
00007 /* as published by the Free Software Foundation; either version 2       */
00008 /* of the License, or (at your option) any later version.               */
00009 /*                                                                      */
00010 /* This program is distributed in the hope that it will be useful,      */
00011 /* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
00012 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        */
00013 /* GNU Library General Public License for more details.                 */
00014 
00015 /* Redefine siglongjmp and longjmp so that they interact correctly
00016    with cleanup handlers */
00017 
00018 #include <setjmp.h>
00019 #include "pthread.h"
00020 #include "internals.h"
00021 #include <sysdep.h>
00022 #include <jmpbuf-unwind.h>
00023 
00024 static inline uintptr_t
00025 demangle_ptr (uintptr_t x)
00026 {
00027 #ifdef PTR_DEMANGLE
00028   PTR_DEMANGLE (x);
00029 #endif
00030   return x;
00031 }
00032 
00033 void __pthread_cleanup_upto (__jmp_buf target, char *targetframe)
00034 {
00035   pthread_descr self = thread_self();
00036   struct _pthread_cleanup_buffer * c;
00037 
00038   for (c = THREAD_GETMEM(self, p_cleanup);
00039        c != NULL && _JMPBUF_UNWINDS(target, c, demangle_ptr);
00040        c = c->__prev)
00041     {
00042 #if _STACK_GROWS_DOWN
00043       if ((char *) c <= targetframe)
00044        {
00045          c = NULL;
00046          break;
00047        }
00048 #elif _STACK_GROWS_UP
00049       if ((char *) c >= targetframe)
00050        {
00051          c = NULL;
00052          break;
00053        }
00054 #else
00055 # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
00056 #endif
00057       c->__routine(c->__arg);
00058     }
00059   THREAD_SETMEM(self, p_cleanup, c);
00060   if (THREAD_GETMEM(self, p_in_sighandler)
00061       && _JMPBUF_UNWINDS(target, THREAD_GETMEM(self, p_in_sighandler),
00062                       demangle_ptr))
00063     THREAD_SETMEM(self, p_in_sighandler, NULL);
00064 }