summaryrefslogtreecommitdiff
path: root/usr/src/lib/libmalloc/common/malloc.c
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/common/malloc.c
parent84f43ade33b1b00348bdcdfaca9f71f6a0c786eb (diff)
downloadillumos-gate-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/common/malloc.c')
-rw-r--r--usr/src/lib/libmalloc/common/malloc.c31
1 files changed, 26 insertions, 5 deletions
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);
+}