summaryrefslogtreecommitdiff
path: root/usr/src/lib/libmalloc
diff options
context:
space:
mode:
authorraf <none@none>2007-03-20 19:30:49 -0700
committerraf <none@none>2007-03-20 19:30:49 -0700
commit1d53067866b073ea6710000ba4dd448441361988 (patch)
treefbac45aa59a72e34fdd5e5fccc91c5bb1d0f0df5 /usr/src/lib/libmalloc
parent84f43ade33b1b00348bdcdfaca9f71f6a0c786eb (diff)
downloadillumos-joyent-1d53067866b073ea6710000ba4dd448441361988.tar.gz
6533630 all malloc interposition libraries need to be made fork-safe
--HG-- rename : usr/src/lib/libmapmalloc/common/malloc_debug.c => deleted_files/usr/src/lib/libmapmalloc/common/malloc_debug.c
Diffstat (limited to 'usr/src/lib/libmalloc')
-rw-r--r--usr/src/lib/libmalloc/Makefile.com4
-rw-r--r--usr/src/lib/libmalloc/common/mallint.h27
-rw-r--r--usr/src/lib/libmalloc/common/malloc.c31
3 files changed, 35 insertions, 27 deletions
diff --git a/usr/src/lib/libmalloc/Makefile.com b/usr/src/lib/libmalloc/Makefile.com
index 4380a1d20b..a32dbd13e0 100644
--- a/usr/src/lib/libmalloc/Makefile.com
+++ b/usr/src/lib/libmalloc/Makefile.com
@@ -19,7 +19,7 @@
# CDDL HEADER END
#
#
-# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
@@ -42,7 +42,7 @@ LINTFLAGS += -erroff=E_BAD_PTR_CAST_ALIGN
LINTFLAGS64 += -erroff=E_BAD_PTR_CAST_ALIGN
CFLAGS += $(CCVERBOSE)
-CPPFLAGS += -D_REENTRANT
+CPPFLAGS += -I../../common/inc -D_REENTRANT
DYNFLAGS += $(ZINTERPOSE)
LDLIBS += -lc
diff --git a/usr/src/lib/libmalloc/common/mallint.h b/usr/src/lib/libmalloc/common/mallint.h
index 34b3810d8a..f2c0f2cfae 100644
--- a/usr/src/lib/libmalloc/common/mallint.h
+++ b/usr/src/lib/libmalloc/common/mallint.h
@@ -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,15 +18,15 @@
*
* CDDL HEADER END
*/
-/* Copyright (c) 1988 AT&T */
-/* All Rights Reserved */
-
/*
- * Copyright (c) 1997,2001 by Sun Microsystems, Inc.
- * All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
*/
+/* Copyright (c) 1988 AT&T */
+/* All Rights Reserved */
+
#ifndef _MALLINT_H
#define _MALLINT_H
@@ -198,18 +197,6 @@ struct holdblk {
#define CHECKQ
#endif
-#ifdef _REENTRANT
-
-#define mutex_lock(m) _mutex_lock(m)
-#define mutex_unlock(m) _mutex_unlock(m)
-
-#else
-
-#define mutex_lock(m)
-#define mutex_unlock(m)
-
-#endif /* _REENTRANT */
-
#ifdef __cplusplus
}
#endif
diff --git a/usr/src/lib/libmalloc/common/malloc.c b/usr/src/lib/libmalloc/common/malloc.c
index a1feccb36d..aa14755752 100644
--- a/usr/src/lib/libmalloc/common/malloc.c
+++ b/usr/src/lib/libmalloc/common/malloc.c
@@ -19,16 +19,17 @@
* CDDL HEADER END
*/
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
-/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
+#include <c_synonyms.h>
#include <sys/types.h>
#ifndef debug
@@ -41,6 +42,7 @@
#include "malloc.h"
#include "mallint.h"
#include <thread.h>
+#include <pthread.h>
#include <synch.h>
#include <unistd.h>
#include <limits.h>
@@ -1170,3 +1172,22 @@ cfree(void *p, size_t num, size_t size)
{
free(p);
}
+
+static void
+malloc_prepare()
+{
+ (void) mutex_lock(&mlock);
+}
+
+static void
+malloc_release()
+{
+ (void) mutex_unlock(&mlock);
+}
+
+#pragma init(malloc_init)
+static void
+malloc_init(void)
+{
+ (void) pthread_atfork(malloc_prepare, malloc_release, malloc_release);
+}