(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / ptcleanup.c
blob9fde2555b1a6494c929bf952fca4ebecefecb98f
1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1998, 2004 Xavier Leroy (Xavier.Leroy@inria.fr) */
4 /* */
5 /* This program is free software; you can redistribute it and/or */
6 /* modify it under the terms of the GNU Library General Public License */
7 /* as published by the Free Software Foundation; either version 2 */
8 /* of the License, or (at your option) any later version. */
9 /* */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU Library General Public License for more details. */
15 /* Redefine siglongjmp and longjmp so that they interact correctly
16 with cleanup handlers */
18 #include <setjmp.h>
19 #include "pthread.h"
20 #include "internals.h"
22 void __pthread_cleanup_upto (__jmp_buf target, char *targetframe)
24 pthread_descr self = thread_self();
25 struct _pthread_cleanup_buffer * c;
27 for (c = THREAD_GETMEM(self, p_cleanup);
28 c != NULL && _JMPBUF_UNWINDS(target, c);
29 c = c->__prev)
31 #if _STACK_GROWS_DOWN
32 if ((char *) c <= targetframe)
34 c = NULL;
35 break;
37 #elif _STACK_GROWS_UP
38 if ((char *) c >= targetframe)
40 c = NULL;
41 break;
43 #else
44 # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
45 #endif
46 c->__routine(c->__arg);
48 THREAD_SETMEM(self, p_cleanup, c);
49 if (THREAD_GETMEM(self, p_in_sighandler)
50 && _JMPBUF_UNWINDS(target, THREAD_GETMEM(self, p_in_sighandler)))
51 THREAD_SETMEM(self, p_in_sighandler, NULL);