diff options
author | jasone <jasone@FreeBSD.org> | 1999-07-05 00:35:19 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 1999-07-05 00:35:19 +0000 |
commit | 6f85900affc95409ce87ebfce319b6f0a911a95c (patch) | |
tree | 55bd23172185419206e51b736aeb4824ee2c7666 /lib/libpthread/thread/thr_gc.c | |
parent | a84623740cbcddc83d3ae0e49ad184b469302d78 (diff) | |
download | FreeBSD-src-6f85900affc95409ce87ebfce319b6f0a911a95c.zip FreeBSD-src-6f85900affc95409ce87ebfce319b6f0a911a95c.tar.gz |
Use growable stacks for thread stacks that are the default stack size.
Cache discarded default thread stacks for use in subsequent thread creations.
Create a red zone at the end of each stack (including the initial thread
stack), with the hope of causing a segfault if a stack overflows.
To activate these modifications, add -D_PTHREAD_GSTACK to CFLAGS in
src/lib/libc_r/Makefile. Since the modifications depend on the VM_STACK
kernel option, I'm not sure how to safely use growable stacks by default.
Testing, as well as algorithmic and stylistic comments are welcome.
Diffstat (limited to 'lib/libpthread/thread/thr_gc.c')
-rw-r--r-- | lib/libpthread/thread/thr_gc.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/libpthread/thread/thr_gc.c b/lib/libpthread/thread/thr_gc.c index e29e29b..a8e05ea 100644 --- a/lib/libpthread/thread/thr_gc.c +++ b/lib/libpthread/thread/thr_gc.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_gc.c,v 1.3 1999/03/23 05:07:55 jb Exp $ + * $Id: uthread_gc.c,v 1.4 1999/06/20 08:28:25 jb Exp $ * * Garbage collector thread. Frees memory allocated for dead threads. * @@ -38,6 +38,10 @@ #include <time.h> #include <unistd.h> #include <sys/types.h> +#ifdef _PTHREAD_GSTACK +#include <sys/types.h> +#include <sys/mman.h> +#endif #include <pthread.h> #include "pthread_private.h" @@ -132,11 +136,23 @@ _thread_gc(pthread_addr_t arg) */ if (pthread->attr.stackaddr_attr == NULL && pthread->stack != NULL) { +#ifdef _PTHREAD_GSTACK + if (pthread->attr.stacksize_attr == PTHREAD_STACK_DEFAULT) { + /* Default-size stack. Cache it: */ + struct stack * spare_stack = (pthread->stack + PTHREAD_STACK_DEFAULT + - sizeof(struct stack)); + SLIST_INSERT_HEAD(&_stackq, spare_stack, qe); + } else { + /* Non-standard stack size. free() it outside the locks: */ + p_stack = pthread->stack; + } +#else /* * Point to the stack that must * be freed outside the locks: */ p_stack = pthread->stack; +#endif } /* @@ -156,12 +172,24 @@ _thread_gc(pthread_addr_t arg) */ if (pthread->attr.stackaddr_attr == NULL && pthread->stack != NULL) { +#ifdef _PTHREAD_GSTACK + if (pthread->attr.stacksize_attr == PTHREAD_STACK_DEFAULT) { + /* Default-size stack. Cache it: */ + struct stack * spare_stack = (pthread->stack + PTHREAD_STACK_DEFAULT + - sizeof(struct stack)); + SLIST_INSERT_HEAD(&_stackq, spare_stack, qe); + } else { + /* Non-standard stack size. free() it outside the locks: */ + p_stack = pthread->stack; + } +#else /* * Point to the stack that must * be freed outside the locks: */ p_stack = pthread->stack; - +#endif + /* * NULL the stack pointer now * that the memory has been freed: |