Browse Source

back out previous patch.. there are still some vax/m68k issues

OPENBSD_3_3
marc 22 years ago
parent
commit
2b7dd8d384
2 changed files with 53 additions and 14 deletions
  1. +9
    -1
      src/lib/libc/stdlib/abort.c
  2. +44
    -13
      src/lib/libc/stdlib/malloc.c

+ 9
- 1
src/lib/libc/stdlib/abort.c View File

@ -32,7 +32,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: abort.c,v 1.9 2002/11/03 20:36:43 marc Exp $";
static char *rcsid = "$OpenBSD: abort.c,v 1.10 2002/11/03 23:58:39 marc Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <signal.h> #include <signal.h>
@ -55,7 +55,11 @@ abort()
* any errors -- X311J doesn't allow abort to return anyway. * any errors -- X311J doesn't allow abort to return anyway.
*/ */
sigdelset(&mask, SIGABRT); sigdelset(&mask, SIGABRT);
#ifdef _THREAD_SAFE
(void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); (void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
#else /* _THREAD_SAFE */
(void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
#endif /* _THREAD_SAFE */
/* /*
* POSIX requires we flush stdio buffers on abort * POSIX requires we flush stdio buffers on abort
@ -76,7 +80,11 @@ abort()
* it again, only harder. * it again, only harder.
*/ */
(void)signal(SIGABRT, SIG_DFL); (void)signal(SIGABRT, SIG_DFL);
#ifdef _THREAD_SAFE
(void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); (void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
#else /* _THREAD_SAFE */
(void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
#endif /* _THREAD_SAFE */
(void)kill(getpid(), SIGABRT); (void)kill(getpid(), SIGABRT);
exit(1); exit(1);
} }

+ 44
- 13
src/lib/libc/stdlib/malloc.c View File

@ -8,7 +8,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: malloc.c,v 1.49 2002/11/03 20:36:43 marc Exp $";
static char rcsid[] = "$OpenBSD: malloc.c,v 1.50 2002/11/03 23:58:39 marc Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
/* /*
@ -48,8 +48,6 @@ static char rcsid[] = "$OpenBSD: malloc.c,v 1.49 2002/11/03 20:36:43 marc Exp $"
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include "thread_private.h"
/* /*
* The basic parameters you can tweak. * The basic parameters you can tweak.
* *
@ -69,6 +67,39 @@ static char rcsid[] = "$OpenBSD: malloc.c,v 1.49 2002/11/03 20:36:43 marc Exp $"
# define malloc_pageshift 13U # define malloc_pageshift 13U
#endif /* __OpenBSD__ */ #endif /* __OpenBSD__ */
#ifdef _THREAD_SAFE
# include "thread_private.h"
# if 0
/* kernel threads */
# include <pthread.h>
static pthread_mutex_t malloc_lock;
# define THREAD_LOCK() pthread_mutex_lock(&malloc_lock)
# define THREAD_UNLOCK() pthread_mutex_unlock(&malloc_lock)
# define THREAD_LOCK_INIT() pthread_mutex_init(&malloc_lock, 0);
# else
/* user threads */
# include "spinlock.h"
static spinlock_t malloc_lock = _SPINLOCK_INITIALIZER;
# define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&malloc_lock)
# define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&malloc_lock)
# define THREAD_LOCK_INIT()
/*
* Malloc can't use the wrapped write() if it fails very early, so
* we use the unwrapped syscall _thread_sys_write()
*/
# define write _thread_sys_write
ssize_t write(int, const void *, size_t);
# undef malloc
# undef realloc
# undef free
# endif
#else
/* no threads */
# define THREAD_LOCK()
# define THREAD_UNLOCK()
# define THREAD_LOCK_INIT()
#endif
/* /*
* No user serviceable parts behind this point. * No user serviceable parts behind this point.
* *
@ -463,7 +494,7 @@ malloc_init ()
int i, j; int i, j;
int save_errno = errno; int save_errno = errno;
_MALLOC_LOCK_INIT();
THREAD_LOCK_INIT();
INIT_MMAP(); INIT_MMAP();
@ -1213,17 +1244,17 @@ malloc(size_t size)
register void *r; register void *r;
malloc_func = " in malloc():"; malloc_func = " in malloc():";
_MALLOC_LOCK();
THREAD_LOCK();
if (malloc_active++) { if (malloc_active++) {
wrtwarning("recursive call.\n"); wrtwarning("recursive call.\n");
malloc_active--; malloc_active--;
_MALLOC_UNLOCK();
THREAD_UNLOCK();
return (0); return (0);
} }
r = imalloc(size); r = imalloc(size);
UTRACE(0, size, r); UTRACE(0, size, r);
malloc_active--; malloc_active--;
_MALLOC_UNLOCK();
THREAD_UNLOCK();
if (malloc_xmalloc && !r) if (malloc_xmalloc && !r)
wrterror("out of memory.\n"); wrterror("out of memory.\n");
return (r); return (r);
@ -1233,17 +1264,17 @@ void
free(void *ptr) free(void *ptr)
{ {
malloc_func = " in free():"; malloc_func = " in free():";
_MALLOC_LOCK();
THREAD_LOCK();
if (malloc_active++) { if (malloc_active++) {
wrtwarning("recursive call.\n"); wrtwarning("recursive call.\n");
malloc_active--; malloc_active--;
_MALLOC_UNLOCK();
THREAD_UNLOCK();
return; return;
} }
ifree(ptr); ifree(ptr);
UTRACE(ptr, 0, 0); UTRACE(ptr, 0, 0);
malloc_active--; malloc_active--;
_MALLOC_UNLOCK();
THREAD_UNLOCK();
return; return;
} }
@ -1253,11 +1284,11 @@ realloc(void *ptr, size_t size)
register void *r; register void *r;
malloc_func = " in realloc():"; malloc_func = " in realloc():";
_MALLOC_LOCK();
THREAD_LOCK();
if (malloc_active++) { if (malloc_active++) {
wrtwarning("recursive call.\n"); wrtwarning("recursive call.\n");
malloc_active--; malloc_active--;
_MALLOC_UNLOCK();
THREAD_UNLOCK();
return (0); return (0);
} }
if (!ptr) { if (!ptr) {
@ -1267,7 +1298,7 @@ realloc(void *ptr, size_t size)
} }
UTRACE(ptr, size, r); UTRACE(ptr, size, r);
malloc_active--; malloc_active--;
_MALLOC_UNLOCK();
THREAD_UNLOCK();
if (malloc_xmalloc && !r) if (malloc_xmalloc && !r)
wrterror("out of memory.\n"); wrterror("out of memory.\n");
return (r); return (r);


Loading…
Cancel
Save