From f0d13fdd5d5f11847ce6d5b148e167e7999e075e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 9 Nov 2006 08:07:43 +0000 Subject: backport from upstream: 2001-04-11 Ulrich Drepper * cancel.c (_pthread_cleanup_push): Catch invalid __prev buffer and remove it. (_pthread_cleanup_push_defer): Likewise. --- libpthread/linuxthreads.old/cancel.c | 12 ++++++++++++ libpthread/linuxthreads.old/internals.h | 1 + 2 files changed, 13 insertions(+) diff --git a/libpthread/linuxthreads.old/cancel.c b/libpthread/linuxthreads.old/cancel.c index f354c2a38..25b098dd5 100644 --- a/libpthread/linuxthreads.old/cancel.c +++ b/libpthread/linuxthreads.old/cancel.c @@ -26,6 +26,14 @@ extern void __rpc_thread_destroy(void); #endif +#ifdef _STACK_GROWS_DOWN +# define FRAME_LEFT(frame, other) ((char *) frame >= (char *) other) +#elif _STACK_GROWS_UP +# define FRAME_LEFT(frame, other) ((char *) frame <= (char *) other) +#else +# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP" +#endif + int pthread_setcancelstate(int state, int * oldstate) { @@ -128,6 +136,8 @@ void _pthread_cleanup_push(struct _pthread_cleanup_buffer * buffer, buffer->__routine = routine; buffer->__arg = arg; buffer->__prev = THREAD_GETMEM(self, p_cleanup); + if (buffer->__prev != NULL && FRAME_LEFT (buffer, buffer->__prev)) + buffer->__prev = NULL; THREAD_SETMEM(self, p_cleanup, buffer); } @@ -147,6 +157,8 @@ void _pthread_cleanup_push_defer(struct _pthread_cleanup_buffer * buffer, buffer->__arg = arg; buffer->__canceltype = THREAD_GETMEM(self, p_canceltype); buffer->__prev = THREAD_GETMEM(self, p_cleanup); + if (buffer->__prev != NULL && FRAME_LEFT (buffer, buffer->__prev)) + buffer->__prev = NULL; THREAD_SETMEM(self, p_canceltype, PTHREAD_CANCEL_DEFERRED); THREAD_SETMEM(self, p_cleanup, buffer); } diff --git a/libpthread/linuxthreads.old/internals.h b/libpthread/linuxthreads.old/internals.h index f1d5db16b..bd4d8ae13 100644 --- a/libpthread/linuxthreads.old/internals.h +++ b/libpthread/linuxthreads.old/internals.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include "pt-machine.h" -- cgit v1.2.3