diff options
author | raf <none@none> | 2007-03-20 19:30:49 -0700 |
---|---|---|
committer | raf <none@none> | 2007-03-20 19:30:49 -0700 |
commit | 1d53067866b073ea6710000ba4dd448441361988 (patch) | |
tree | fbac45aa59a72e34fdd5e5fccc91c5bb1d0f0df5 /usr/src/lib/libmapmalloc/common/textmem.c | |
parent | 84f43ade33b1b00348bdcdfaca9f71f6a0c786eb (diff) | |
download | illumos-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/libmapmalloc/common/textmem.c')
-rw-r--r-- | usr/src/lib/libmapmalloc/common/textmem.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/usr/src/lib/libmapmalloc/common/textmem.c b/usr/src/lib/libmapmalloc/common/textmem.c index eed2ca0478..6a3f04cb1e 100644 --- a/usr/src/lib/libmapmalloc/common/textmem.c +++ b/usr/src/lib/libmapmalloc/common/textmem.c @@ -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) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - /* - * Copyright (c) 1991-1997,2000-2001 by Sun Microsystems, Inc. - * All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + #pragma ident "%Z%%M% %I% %E% SMI" /* SVR4/MNLS 1.1.2.1 */ /*LINTLIBRARY*/ @@ -49,6 +48,7 @@ * New memory chunks are allocated on a first-fit basis. * Freed blocks are joined in larger blocks. Free pages are unmapped. */ +#include <c_synonyms.h> #include <stdlib.h> #include <sys/types.h> #include <sys/mman.h> @@ -56,13 +56,11 @@ #include <errno.h> #include <unistd.h> #include <thread.h> +#include <pthread.h> #include <synch.h> #include <string.h> - -#ifdef _REENTRANT static mutex_t lock = DEFAULTMUTEX; -#endif /* _REENTRANT */ struct block { size_t size; /* Space available for user */ @@ -280,3 +278,22 @@ defrag(struct page *page) (void) munmap((caddr_t)page, page->size); } } + +static void +malloc_prepare() +{ + (void) mutex_lock(&lock); +} + +static void +malloc_release() +{ + (void) mutex_unlock(&lock); +} + +#pragma init(malloc_init) +static void +malloc_init(void) +{ + (void) pthread_atfork(malloc_prepare, malloc_release, malloc_release); +} |