1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-15 10:17:20 +00:00

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.
This commit is contained in:
John Birrell 1997-12-15 02:12:42 +00:00
parent 549a42942d
commit d5bc59bb81
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=31722

View File

@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * 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) # if defined(_THREAD_SAFE)
# include <pthread.h> # include <pthread.h>
# include "pthread_private.h" # include "pthread_private.h"
# define THREAD_LOCK() pthread_mutex_lock(&malloc_lock) # define THREAD_STATUS int thread_lock_status;
# define THREAD_UNLOCK() pthread_mutex_unlock(&malloc_lock) # 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 struct pthread_mutex _malloc_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t malloc_lock = &_malloc_lock; static pthread_mutex_t malloc_lock = &_malloc_lock;
# endif # endif
@ -157,6 +158,10 @@ struct pgfree {
#define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask))) #define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask)))
#define ptr2index(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo) #define ptr2index(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo)
#ifndef THREAD_STATUS
#define THREAD_STATUS
#endif
#ifndef THREAD_LOCK #ifndef THREAD_LOCK
#define THREAD_LOCK() #define THREAD_LOCK()
#endif #endif
@ -1052,6 +1057,7 @@ void *
malloc(size_t size) malloc(size_t size)
{ {
register void *r; register void *r;
THREAD_STATUS
malloc_func = " in malloc():"; malloc_func = " in malloc():";
THREAD_LOCK(); THREAD_LOCK();
@ -1077,6 +1083,8 @@ malloc(size_t size)
void void
free(void *ptr) free(void *ptr)
{ {
THREAD_STATUS
malloc_func = " in free():"; malloc_func = " in free():";
THREAD_LOCK(); THREAD_LOCK();
if (malloc_active++) { if (malloc_active++) {
@ -1094,6 +1102,7 @@ free(void *ptr)
void * void *
realloc(void *ptr, size_t size) realloc(void *ptr, size_t size)
{ {
THREAD_STATUS
register void *r; register void *r;
malloc_func = " in realloc():"; malloc_func = " in realloc():";