Fix missing backslash in last change.
[glibc.git] / linuxthreads / ptlongjmp.c
blob68b9235cb8f36df8b7024bdff288626095b62274
1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1998 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"
21 #include <stackinfo.h>
23 /* These functions are not declared anywhere since they shouldn't be
24 used at another place but here. */
25 extern void __libc_siglongjmp (sigjmp_buf env, int val)
26 __attribute__ ((noreturn));
27 extern void __libc_longjmp (sigjmp_buf env, int val)
28 __attribute__ ((noreturn));
31 static void pthread_cleanup_upto(__jmp_buf target)
33 pthread_descr self = thread_self();
34 struct _pthread_cleanup_buffer * c;
35 char *currentframe = CURRENT_STACK_FRAME;
37 for (c = THREAD_GETMEM(self, p_cleanup);
38 c != NULL && _JMPBUF_UNWINDS(target, c);
39 c = c->__prev)
41 #if _STACK_GROWS_DOWN
42 if ((char *) c <= currentframe)
44 c = NULL;
45 break;
47 #elif _STACK_GROWS_UP
48 if ((char *) c >= currentframe)
50 c = NULL;
51 break;
53 #else
54 # error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
55 #endif
56 c->__routine(c->__arg);
58 THREAD_SETMEM(self, p_cleanup, c);
59 if (THREAD_GETMEM(self, p_in_sighandler)
60 && _JMPBUF_UNWINDS(target, THREAD_GETMEM(self, p_in_sighandler)))
61 THREAD_SETMEM(self, p_in_sighandler, NULL);
64 void siglongjmp(sigjmp_buf env, int val)
66 pthread_cleanup_upto(env->__jmpbuf);
67 __libc_siglongjmp(env, val);
70 void longjmp(jmp_buf env, int val)
72 pthread_cleanup_upto(env->__jmpbuf);
73 __libc_longjmp(env, val);