6418491 solaris 10 runtime prevents sigbus signal to correctly get passed to the handler
--- a/usr/src/lib/libc/port/gen/malloc.c Tue Jun 13 10:16:49 2006 -0700
+++ b/usr/src/lib/libc/port/gen/malloc.c Tue Jun 13 10:19:16 2006 -0700
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -29,7 +29,6 @@
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
-
/*
* Memory management: malloc(), realloc(), free().
*
@@ -69,15 +68,14 @@
* Some abusers of the system (notably java1.2) acquire __malloc_lock
* in order to prevent threads from holding it while they are being
* suspended via thr_suspend() or thr_suspend_allmutators().
- * The new scheme of acquiring it via lmutex_lock() solves the same
- * problem but causes these old programs to malfunction (acquiring
- * a lock by both mutex_lock() and lmutex_lock() leads to fatal
- * inconsistencies). Therefore, we leave __malloc_lock as an external
- * variable to satisfy these old programs, but we define a new lock,
- * private to libc, to do the real locking: libc_malloc_lock
+ * This never worked when alternate malloc() libraries were used
+ * because they don't use __malloc_lock for their locking strategy.
+ * We leave __malloc_lock as an external variable to satisfy these
+ * old programs, but we define a new lock, private to libc, to do the
+ * real locking: libc_malloc_lock. This puts libc's malloc() package
+ * on the same footing as all other malloc packages.
*/
mutex_t __malloc_lock = DEFAULTMUTEX;
-
mutex_t libc_malloc_lock = DEFAULTMUTEX;
static TREE *Root, /* root of the free tree */
@@ -100,6 +98,21 @@
static int freeidx; /* index of free blocks in flist % FREESIZE */
/*
+ * Interfaces used only by atfork_init() functions.
+ */
+void
+malloc_locks(void)
+{
+ (void) _private_mutex_lock(&libc_malloc_lock);
+}
+
+void
+malloc_unlocks(void)
+{
+ (void) _private_mutex_unlock(&libc_malloc_lock);
+}
+
+/*
* Allocation of small blocks
*/
static TREE *List[MINSIZE/WORDSIZE-1]; /* lists of small blocks */
@@ -156,9 +169,9 @@
return (NULL);
}
assert_no_libc_locks_held();
- lmutex_lock(&libc_malloc_lock);
+ (void) _private_mutex_lock(&libc_malloc_lock);
ret = _malloc_unlocked(size);
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (ret);
}
@@ -307,10 +320,10 @@
}
/* pointer to the block */
- lmutex_lock(&libc_malloc_lock);
+ (void) _private_mutex_lock(&libc_malloc_lock);
if (old == NULL) {
new = _malloc_unlocked(size);
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (new);
}
@@ -325,7 +338,7 @@
/* if the block was freed, data has been destroyed. */
if (!ISBIT0(ts)) {
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (NULL);
}
@@ -333,7 +346,7 @@
CLRBITS01(SIZE(tp));
if (size == SIZE(tp)) {
SIZE(tp) = ts;
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (old);
}
@@ -343,7 +356,7 @@
if (size == 0) {
SETOLD01(SIZE(tp), ts);
_free_unlocked(old);
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (NULL);
} else {
goto call_malloc;
@@ -392,7 +405,7 @@
/* the previous block may be free */
SETOLD01(SIZE(tp), ts);
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (old);
}
@@ -405,7 +418,7 @@
ts = size;
MEMCOPY(new, old, ts);
_free_unlocked(old);
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (new);
}
@@ -430,7 +443,7 @@
if (SIZE(tp) < MINSIZE) {
if (size < SIZE(tp)) { /* case 1. */
SETOLD01(SIZE(tp), ts);
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (old);
} else if (size < MINSIZE) { /* case 2. */
size = MINSIZE;
@@ -455,7 +468,7 @@
goto chop_big;
}
SETOLD01(SIZE(tp), ts);
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (NULL);
}
@@ -841,9 +854,9 @@
free(void *old)
{
assert_no_libc_locks_held();
- lmutex_lock(&libc_malloc_lock);
+ (void) _private_mutex_lock(&libc_malloc_lock);
_free_unlocked(old);
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
}
--- a/usr/src/lib/libc/port/gen/memalign.c Tue Jun 13 10:16:49 2006 -0700
+++ b/usr/src/lib/libc/port/gen/memalign.c Tue Jun 13 10:19:16 2006 -0700
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -29,7 +29,6 @@
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
-
#pragma weak memalign = _memalign
#include "synonyms.h"
@@ -117,7 +116,7 @@
/* malloc sets errno */
return (NULL);
}
- lmutex_lock(&libc_malloc_lock);
+ (void) _private_mutex_lock(&libc_malloc_lock);
/*
* get size of the entire block (overhead and all)
@@ -178,6 +177,6 @@
SIZE(blk) = frag_size | BIT0;
_free_unlocked(DATA(blk));
}
- lmutex_unlock(&libc_malloc_lock);
+ (void) _private_mutex_unlock(&libc_malloc_lock);
return (DATA(aligned_blk));
}
--- a/usr/src/lib/libc/port/gen/sh_locks.c Tue Jun 13 10:16:49 2006 -0700
+++ b/usr/src/lib/libc/port/gen/sh_locks.c Tue Jun 13 10:19:16 2006 -0700
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -49,16 +49,21 @@
extern void stdio_locks(void);
extern void stdio_unlocks(void);
+extern void malloc_locks(void);
+extern void malloc_unlocks(void);
+
static void
libc_prepare_atfork(void)
{
atexit_locks();
stdio_locks();
+ malloc_locks();
}
static void
libc_child_atfork(void)
{
+ malloc_unlocks();
stdio_unlocks();
atexit_unlocks();
}
@@ -66,6 +71,7 @@
static void
libc_parent_atfork(void)
{
+ malloc_unlocks();
stdio_unlocks();
atexit_unlocks();
}