From d5bc59bb8181b947c46cdd95ccdc31a52db122b5 Mon Sep 17 00:00:00 2001 From: John Birrell Date: Mon, 15 Dec 1997 02:12:42 +0000 Subject: Fix recursion problem which occurs when a signal is received during a malloc. The signal handler creates a thread which requires a malloc... For now, the only thing to do is to block signals. When we move user pthreads to use the kernel threads, mutexes will be implemented in kernel space and then malloc can revert. --- lib/libc/stdlib/malloc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'lib/libc/stdlib/malloc.c') diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 4fd0fd0720f6..176dd40892d5 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: malloc.c,v 1.31 1997/08/27 12:04:33 phk Exp $ + * $Id: malloc.c,v 1.32 1997/08/31 05:59:39 phk Exp $ * */ @@ -51,8 +51,9 @@ # if defined(_THREAD_SAFE) # include # include "pthread_private.h" -# define THREAD_LOCK() pthread_mutex_lock(&malloc_lock) -# define THREAD_UNLOCK() pthread_mutex_unlock(&malloc_lock) +# define THREAD_STATUS int thread_lock_status; +# define THREAD_LOCK() _thread_kern_sig_block(&thread_lock_status); +# define THREAD_UNLOCK() _thread_kern_sig_unblock(thread_lock_status); static struct pthread_mutex _malloc_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t malloc_lock = &_malloc_lock; # endif @@ -157,6 +158,10 @@ struct pgfree { #define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask))) #define ptr2index(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo) +#ifndef THREAD_STATUS +#define THREAD_STATUS +#endif + #ifndef THREAD_LOCK #define THREAD_LOCK() #endif @@ -1052,6 +1057,7 @@ void * malloc(size_t size) { register void *r; + THREAD_STATUS malloc_func = " in malloc():"; THREAD_LOCK(); @@ -1077,6 +1083,8 @@ malloc(size_t size) void free(void *ptr) { + THREAD_STATUS + malloc_func = " in free():"; THREAD_LOCK(); if (malloc_active++) { @@ -1094,6 +1102,7 @@ free(void *ptr) void * realloc(void *ptr, size_t size) { + THREAD_STATUS register void *r; malloc_func = " in realloc():"; -- cgit v1.2.3