summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjb <jb@FreeBSD.org>1997-12-15 02:12:42 +0000
committerjb <jb@FreeBSD.org>1997-12-15 02:12:42 +0000
commitda6ab2349a36aff5f17c3d322976dace8fa64ac7 (patch)
tree3de40a6c786e111c2dcc3a33877c390b0ea917b3 /lib
parent06b61e24e4210f5d272e336e023d48f744c33676 (diff)
downloadFreeBSD-src-da6ab2349a36aff5f17c3d322976dace8fa64ac7.zip
FreeBSD-src-da6ab2349a36aff5f17c3d322976dace8fa64ac7.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdlib/malloc.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 4fd0fd0..176dd40 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 <pthread.h>
# 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():";
OpenPOWER on IntegriCloud