summaryrefslogtreecommitdiff
path: root/usr/src/lib/libmapmalloc
diff options
context:
space:
mode:
authorstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
committerstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
commit7c478bd95313f5f23a4c958a745db2134aa03244 (patch)
treec871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/lib/libmapmalloc
downloadillumos-joyent-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz
OpenSolaris Launch
Diffstat (limited to 'usr/src/lib/libmapmalloc')
-rw-r--r--usr/src/lib/libmapmalloc/Makefile96
-rw-r--r--usr/src/lib/libmapmalloc/Makefile.com74
-rw-r--r--usr/src/lib/libmapmalloc/amd64/Makefile40
-rw-r--r--usr/src/lib/libmapmalloc/common/calloc.c54
-rw-r--r--usr/src/lib/libmapmalloc/common/llib-lmapmalloc34
-rw-r--r--usr/src/lib/libmapmalloc/common/malloc_debug.c63
-rw-r--r--usr/src/lib/libmapmalloc/common/mallopt.c53
-rw-r--r--usr/src/lib/libmapmalloc/common/textmem.c282
-rw-r--r--usr/src/lib/libmapmalloc/common/valloc.c55
-rw-r--r--usr/src/lib/libmapmalloc/i386/Makefile39
-rw-r--r--usr/src/lib/libmapmalloc/sparc/Makefile39
-rw-r--r--usr/src/lib/libmapmalloc/sparcv9/Makefile42
-rw-r--r--usr/src/lib/libmapmalloc/spec/Makefile29
-rw-r--r--usr/src/lib/libmapmalloc/spec/Makefile.targ33
-rw-r--r--usr/src/lib/libmapmalloc/spec/amd64/Makefile49
-rw-r--r--usr/src/lib/libmapmalloc/spec/i386/Makefile49
-rw-r--r--usr/src/lib/libmapmalloc/spec/mapmalloc.spec85
-rw-r--r--usr/src/lib/libmapmalloc/spec/sparc/Makefile49
-rw-r--r--usr/src/lib/libmapmalloc/spec/sparcv9/Makefile50
-rw-r--r--usr/src/lib/libmapmalloc/spec/versions52
20 files changed, 1267 insertions, 0 deletions
diff --git a/usr/src/lib/libmapmalloc/Makefile b/usr/src/lib/libmapmalloc/Makefile
new file mode 100644
index 0000000000..393a0b81bc
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/Makefile
@@ -0,0 +1,96 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989,1998-1999 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# lib/libmapmalloc/Makefile
+#
+
+include ../../Makefile.master
+include ../Makefile.lib
+
+SUBDIRS= spec .WAIT $(MACH) $(BUILD64) $(MACH64)
+
+all := TARGET= all
+clean := TARGET= clean
+clobber := TARGET= clobber
+delete := TARGET= delete
+install := TARGET= install
+lint := TARGET= lint
+_msg := TARGET= _msg
+package := TARGET= package
+
+_msg := TARGET= _msg
+
+LIBRARY= libmapmalloc.a
+TEXT_DOMAIN= SUNW_OST_OSLIB
+XGETFLAGS= -a
+POFILE= $(LIBRARY:.a=.po)
+POFILES= generic.po
+
+SED= sed
+GREP= grep
+CP= cp
+
+.KEEP_STATE:
+
+all clean clobber delete install lint package: $(SUBDIRS)
+
+# definitions for install_h target
+HDRS=
+ROOTHDRDIR= $(ROOT)/usr/include
+ROOTHDRS= $(HDRS:%=$(ROOTHDRDIR)/%)
+CHECKHDRS= $(HDRS:%.h=%.check)
+
+# install rule for install_h target
+$(ROOTHDRDIR)/%: %
+ $(INS.file)
+
+install_h: $(ROOTHDRS)
+
+check: $(CHECKHDRS)
+
+$(MACH) $(MACH64) spec: FRC
+ @cd $@; pwd; $(MAKE) $(TARGET)
+
+_msg: $(MSGDOMAIN) $(POFILE)
+ $(RM) $(MSGDOMAIN)/$(POFILE)
+ $(CP) $(POFILE) $(MSGDOMAIN)
+
+$(POFILE): $(POFILES)
+ $(RM) $@
+ $(CAT) $(POFILES) > $@
+
+$(POFILES):
+ $(RM) messages.po
+ $(XGETTEXT) $(XGETFLAGS) *.[ch]* */*.[ch]*
+ $(SED) -e '/^# msg/d' -e '/^domain/d' messages.po > $@
+ $(RM) messages.po
+
+$(MSGDOMAIN):
+ $(INS.dir)
+
+FRC:
+
diff --git a/usr/src/lib/libmapmalloc/Makefile.com b/usr/src/lib/libmapmalloc/Makefile.com
new file mode 100644
index 0000000000..a7e8467914
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/Makefile.com
@@ -0,0 +1,74 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# lib/libmapmalloc/Makefile.com
+#
+
+LIBRARY= libmapmalloc.a
+VERS= .1
+
+OBJECTS= \
+ calloc.o \
+ malloc_debug.o \
+ mallopt.o \
+ textmem.o \
+ valloc.o
+
+# include library definitions
+include ../../Makefile.lib
+
+MAPFILE= $(MAPDIR)/mapfile
+SRCS= $(OBJECTS:%.o=../common/%.c)
+
+LIBS = $(DYNLIB) $(LINTLIB)
+
+LINTSRC= $(LINTLIB:%.ln=%)
+
+CFLAGS += $(CCVERBOSE)
+CPPFLAGS += -D_REENTRANT
+DYNFLAGS += -M$(MAPFILE) $(ZINTERPOSE)
+LDLIBS += -lc
+
+.KEEP_STATE:
+
+lint: lintcheck
+
+$(DYNLIB): $(MAPFILE)
+
+$(MAPFILE):
+ @cd $(MAPDIR); $(MAKE) mapfile
+
+# include library targets
+include ../../Makefile.targ
+
+pics/%.o: ../common/%.c
+ $(COMPILE.c) -o $@ $<
+ $(POST_PROCESS_O)
+
+# install rule for lint library target
+$(ROOTLINTDIR)/%: ../common/%
+ $(INS.file)
diff --git a/usr/src/lib/libmapmalloc/amd64/Makefile b/usr/src/lib/libmapmalloc/amd64/Makefile
new file mode 100644
index 0000000000..5f23f3b9a7
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/amd64/Makefile
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+MAPDIR= ../spec/amd64
+
+include ../Makefile.com
+include ../../Makefile.lib.64
+
+LIBS = $(DYNLIB) $(LINTLIB)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+install: all $(ROOTLIBS64) $(ROOTLINKS64)
diff --git a/usr/src/lib/libmapmalloc/common/calloc.c b/usr/src/lib/libmapmalloc/common/calloc.c
new file mode 100644
index 0000000000..762d03d2b8
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/common/calloc.c
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+/*
+ * calloc - allocate and clear memory block
+ */
+
+void *
+calloc(size_t num, size_t size)
+{
+ void *mp;
+
+ num *= size;
+ mp = malloc(num);
+ if (mp == NULL)
+ return (NULL);
+ (void) memset(mp, 0, num);
+ return (mp);
+}
+
+/*ARGSUSED*/
+void
+cfree(void *p, size_t num, size_t size)
+{
+ free(p);
+}
diff --git a/usr/src/lib/libmapmalloc/common/llib-lmapmalloc b/usr/src/lib/libmapmalloc/common/llib-lmapmalloc
new file mode 100644
index 0000000000..ca5bba911e
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/common/llib-lmapmalloc
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/* LINTLIBRARY */
+/* PROTOLIB1 */
+
+#include <malloc.h>
+
+void cfree(void *p, size_t num, size_t size);
diff --git a/usr/src/lib/libmapmalloc/common/malloc_debug.c b/usr/src/lib/libmapmalloc/common/malloc_debug.c
new file mode 100644
index 0000000000..c8b7e602ef
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/common/malloc_debug.c
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 1991, Sun Microsytems, Inc.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*LINTLIBRARY*/
+#include <sys/types.h>
+
+
+/*
+ * malloc_debug(level) - empty routine
+ */
+
+/*ARGSUSED*/
+int
+malloc_debug(int level)
+{
+ return (1);
+}
+
+
+/*
+ * malloc_verify() - empty routine
+ */
+
+int
+malloc_verify(void)
+{
+ return (1);
+}
+
+
+/*
+ * mallocmap() - empty routine
+ */
+
+void
+mallocmap(void)
+{
+ ;
+}
diff --git a/usr/src/lib/libmapmalloc/common/mallopt.c b/usr/src/lib/libmapmalloc/common/mallopt.c
new file mode 100644
index 0000000000..c6e24c9963
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/common/mallopt.c
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*LINTLIBRARY*/
+#include <sys/types.h>
+#include <malloc.h>
+
+struct mallinfo __mallinfo;
+
+/*
+ * mallopt -- Do nothing
+ */
+/*ARGSUSED*/
+int
+mallopt(int cmd, int value)
+{
+ return (0);
+}
+
+
+/*
+ * mallinfo -- Do nothing
+ */
+struct mallinfo
+mallinfo(void)
+{
+ return (__mallinfo);
+}
diff --git a/usr/src/lib/libmapmalloc/common/textmem.c b/usr/src/lib/libmapmalloc/common/textmem.c
new file mode 100644
index 0000000000..eed2ca0478
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/common/textmem.c
@@ -0,0 +1,282 @@
+/*
+ * 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.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * 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.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI" /* SVR4/MNLS 1.1.2.1 */
+
+/*LINTLIBRARY*/
+
+#include <sys/types.h>
+
+
+/*
+ * Simplified version of malloc(), free() and realloc(), to be linked with
+ * utilities that use [s]brk() and do not define their own version of the
+ * routines.
+ *
+ * The algorithm used to get extra memory space by mmap'ing /dev/zero. This
+ * breaks if the application closes the open descriptor, so now it uses
+ * mmap's MAP_ANON feature.
+ *
+ * Each call to mmap() creates a page. The pages are linked in a list.
+ * Each page is divided in blocks. There is at least one block in a page.
+ * New memory chunks are allocated on a first-fit basis.
+ * Freed blocks are joined in larger blocks. Free pages are unmapped.
+ */
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <thread.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 */
+ struct page *page; /* Backwards reference to page */
+ int status;
+ struct block *next;
+ void *memstart[1];
+};
+
+struct page {
+ size_t size; /* Total page size (incl. header) */
+ struct page *next;
+ struct block block[1];
+};
+
+#define FREE 0
+#define BUSY 1
+
+#define HDR_BLOCK (sizeof (struct block) - sizeof (void *))
+#define HDR_PAGE (sizeof (struct page) - sizeof (void *))
+#define MINSZ sizeof (double)
+
+/* for convenience */
+#ifndef NULL
+#define NULL (0)
+#endif
+
+struct page *memstart;
+static int pagesize;
+static void defrag(struct page *);
+static void split(struct block *, size_t);
+static void *malloc_unlocked(size_t);
+static size_t align(size_t, int);
+
+void *
+malloc(size_t size)
+{
+ void *retval;
+ (void) mutex_lock(&lock);
+ retval = malloc_unlocked(size);
+ (void) mutex_unlock(&lock);
+ return (retval);
+}
+
+
+static void *
+malloc_unlocked(size_t size)
+{
+ struct block *block;
+ struct page *page;
+
+ if (pagesize == 0)
+ pagesize = (int)sysconf(_SC_PAGESIZE);
+
+ size = align(size, MINSZ);
+
+ /*
+ * Try to locate necessary space
+ */
+ for (page = memstart; page; page = page->next) {
+ for (block = page->block; block; block = block->next) {
+ if (block->status == FREE && block->size >= size)
+ goto found;
+ }
+ }
+found:
+
+ /*
+ * Need to allocate a new page
+ */
+ if (!page) {
+ size_t totsize = size + HDR_PAGE;
+ size_t totpage = align(totsize, pagesize);
+
+ if ((page = (struct page *)mmap(0, totpage,
+ PROT_READ|PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0))
+ == MAP_FAILED)
+ return (0);
+
+ page->next = memstart;
+ memstart = page;
+ page->size = totpage;
+ block = page->block;
+ block->next = 0;
+ block->status = FREE;
+ block->size = totpage - HDR_PAGE;
+ block->page = page;
+ }
+
+ split(block, size);
+
+ block->status = BUSY;
+ return (&block->memstart);
+}
+
+void *
+realloc(void *ptr, size_t size)
+{
+ struct block *block;
+ size_t osize;
+ void *newptr;
+
+ (void) mutex_lock(&lock);
+ if (ptr == NULL) {
+ newptr = malloc_unlocked(size);
+ (void) mutex_unlock(&lock);
+ return (newptr);
+ }
+ block = (struct block *)((char *)ptr - HDR_BLOCK);
+ size = align(size, MINSZ);
+ osize = block->size;
+
+ /*
+ * Join block with next one if it is free
+ */
+ if (block->next && block->next->status == FREE) {
+ block->size += block->next->size + HDR_BLOCK;
+ block->next = block->next->next;
+ }
+
+ if (size <= block->size) {
+ split(block, size);
+ (void) mutex_unlock(&lock);
+ return (ptr);
+ }
+
+ newptr = malloc_unlocked(size);
+ (void) memcpy(newptr, ptr, osize);
+ block->status = FREE;
+ defrag(block->page);
+ (void) mutex_unlock(&lock);
+ return (newptr);
+}
+
+void
+free(void *ptr)
+{
+ struct block *block;
+
+ (void) mutex_lock(&lock);
+ if (ptr == NULL) {
+ (void) mutex_unlock(&lock);
+ return;
+ }
+ block = (struct block *)((char *)ptr - HDR_BLOCK);
+ block->status = FREE;
+
+ defrag(block->page);
+ (void) mutex_unlock(&lock);
+}
+
+/*
+ * Align size on an appropriate boundary
+ */
+static size_t
+align(size_t size, int bound)
+{
+ if (size < bound)
+ return ((size_t)bound);
+ else
+ return (size + bound - 1 - (size + bound - 1) % bound);
+}
+
+static void
+split(struct block *block, size_t size)
+{
+ if (block->size > size + sizeof (struct block)) {
+ struct block *newblock;
+ newblock = (struct block *)((char *)block + HDR_BLOCK + size);
+ newblock->next = block->next;
+ block->next = newblock;
+ newblock->status = FREE;
+ newblock->page = block->page;
+ newblock->size = block->size - size - HDR_BLOCK;
+ block->size = size;
+ }
+}
+
+/*
+ * Defragmentation
+ */
+static void
+defrag(struct page *page)
+{
+ struct block *block;
+
+ for (block = page->block; block; block = block->next) {
+ struct block *block2;
+
+ if (block->status == BUSY)
+ continue;
+ for (block2 = block->next; block2 && block2->status == FREE;
+ block2 = block2->next) {
+ block->next = block2->next;
+ block->size += block2->size + HDR_BLOCK;
+ }
+ }
+
+ /*
+ * Free page
+ */
+ if (page->block->size == page->size - HDR_PAGE) {
+ if (page == memstart)
+ memstart = page->next;
+ else {
+ struct page *page2;
+ for (page2 = memstart; page2->next;
+ page2 = page2->next) {
+ if (page2->next == page) {
+ page2->next = page->next;
+ break;
+ }
+ }
+ }
+ (void) munmap((caddr_t)page, page->size);
+ }
+}
diff --git a/usr/src/lib/libmapmalloc/common/valloc.c b/usr/src/lib/libmapmalloc/common/valloc.c
new file mode 100644
index 0000000000..2b4a443738
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/common/valloc.c
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 1991-1997, Sun Microsytems, Inc.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*LINTLIBRARY*/
+#include <sys/types.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/*
+ * valloc(size) - do nothing
+ */
+
+/*ARGSUSED*/
+void *
+valloc(size_t size)
+{
+ return (0);
+}
+
+
+/*
+ * memalign(align,nbytes) - do nothing
+ */
+
+/*ARGSUSED*/
+void *
+memalign(size_t align, size_t nbytes)
+{
+ errno = EINVAL;
+ return (NULL);
+}
diff --git a/usr/src/lib/libmapmalloc/i386/Makefile b/usr/src/lib/libmapmalloc/i386/Makefile
new file mode 100644
index 0000000000..d2ad6e3445
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/i386/Makefile
@@ -0,0 +1,39 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1997-1999 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# lib/libmapmalloc/i386/Makefile
+#
+
+MAPDIR= ../spec/i386
+
+include ../Makefile.com
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT)
diff --git a/usr/src/lib/libmapmalloc/sparc/Makefile b/usr/src/lib/libmapmalloc/sparc/Makefile
new file mode 100644
index 0000000000..7f5240bb86
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/sparc/Makefile
@@ -0,0 +1,39 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1997-1999 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# lib/libmapmalloc/sparc/Makefile
+#
+
+MAPDIR= ../spec/sparc
+
+include ../Makefile.com
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT)
diff --git a/usr/src/lib/libmapmalloc/sparcv9/Makefile b/usr/src/lib/libmapmalloc/sparcv9/Makefile
new file mode 100644
index 0000000000..eb031f8aa6
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/sparcv9/Makefile
@@ -0,0 +1,42 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1997-1999 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# lib/libmapmalolloc/sparcv9/Makefile
+#
+
+MAPDIR= ../spec/sparcv9
+
+include ../Makefile.com
+include ../../Makefile.lib.64
+
+LIBS = $(DYNLIB) $(LINTLIB)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+install: all $(ROOTLIBS64) $(ROOTLINKS64)
diff --git a/usr/src/lib/libmapmalloc/spec/Makefile b/usr/src/lib/libmapmalloc/spec/Makefile
new file mode 100644
index 0000000000..199af00347
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/spec/Makefile
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1998-1999 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# lib/libmapmalloc/spec/Makefile
+
+include $(SRC)/lib/Makefile.spec.arch
diff --git a/usr/src/lib/libmapmalloc/spec/Makefile.targ b/usr/src/lib/libmapmalloc/spec/Makefile.targ
new file mode 100644
index 0000000000..856510644c
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/spec/Makefile.targ
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1998-1999 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# lib/libmapmalloc/spec/Makefile.targ
+
+LIBRARY = libmapmalloc.a
+VERS = .1
+
+OBJECTS = mapmalloc.o
+
diff --git a/usr/src/lib/libmapmalloc/spec/amd64/Makefile b/usr/src/lib/libmapmalloc/spec/amd64/Makefile
new file mode 100644
index 0000000000..47aa59af67
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/spec/amd64/Makefile
@@ -0,0 +1,49 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+.KEEP_STATE:
+
+include ../Makefile.targ
+
+# Add arch specific objects here
+OBJECTS +=
+
+include $(SRC)/lib/Makefile.lib
+include $(SRC)/lib/Makefile.lib.64
+
+# Uncomment the following if the linker complains
+#amd64_C_PICFLAGS = -K PIC
+
+include $(SRC)/lib/Makefile.spec
+
+# We set ABILLIBC here because libmapmalloc is built before libc
+# and we most avoid ABILLIBC= -lc -z defs from Makefile.spec
+# (-z defs can cause build failures at this point)
+ABILLIBC= -lc
+
+install: $(ROOTABILIB64)
diff --git a/usr/src/lib/libmapmalloc/spec/i386/Makefile b/usr/src/lib/libmapmalloc/spec/i386/Makefile
new file mode 100644
index 0000000000..e5cf096471
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/spec/i386/Makefile
@@ -0,0 +1,49 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1998-2003 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# lib/libmapmalloc/spec/i386/Makefile
+
+.KEEP_STATE:
+
+include ../Makefile.targ
+
+# Add arch specific objects here
+OBJECTS +=
+
+include $(SRC)/lib/Makefile.lib
+
+# Uncomment the following if the linker complains
+#i386_C_PICFLAGS = -K PIC
+
+include $(SRC)/lib/Makefile.spec
+
+# We set ABILLIBC here because libmapmalloc is built before libc
+# and we most avoid ABILLIBC= -lc -z defs from Makefile.spec
+# (-z defs can cause build failures at this point)
+ABILLIBC= -lc
+
+install: $(ROOTABILIB)
diff --git a/usr/src/lib/libmapmalloc/spec/mapmalloc.spec b/usr/src/lib/libmapmalloc/spec/mapmalloc.spec
new file mode 100644
index 0000000000..fe433cd09c
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/spec/mapmalloc.spec
@@ -0,0 +1,85 @@
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# lib/libmapmalloc/spec/mapmalloc.spec
+
+function mallopt
+include <stdlib.h>, <malloc.h>
+declaration int mallopt(int cmd, int value )
+version SUNW_0.7
+errno ENOMEM EAGAIN
+exception $return != 0
+binding nodirect
+end
+
+function mallinfo
+include <stdlib.h>, <malloc.h>
+declaration struct mallinfo mallinfo(void )
+version SUNW_0.7
+errno ENOMEM EAGAIN
+binding nodirect
+end
+
+function malloc extends libc/spec/gen.spec malloc
+version SUNW_0.7
+binding nodirect
+end
+
+function calloc extends libc/spec/gen.spec calloc
+version SUNW_0.7
+binding nodirect
+end
+
+function free extends libc/spec/gen.spec free
+version SUNW_0.7
+binding nodirect
+end
+
+function memalign extends libc/spec/gen.spec memalign
+version SUNW_0.7
+binding nodirect
+end
+
+function realloc extends libc/spec/gen.spec realloc
+version SUNW_0.7
+binding nodirect
+end
+
+function valloc extends libc/spec/gen.spec valloc
+version SUNW_0.7
+binding nodirect
+end
+
+function cfree extends libc/spec/gen.spec cfree
+version SUNW_0.7
+binding nodirect
+end
+
+# required by sbcp.
+function __mallinfo
+version SUNWprivate_1.1
+binding nodirect
+end
diff --git a/usr/src/lib/libmapmalloc/spec/sparc/Makefile b/usr/src/lib/libmapmalloc/spec/sparc/Makefile
new file mode 100644
index 0000000000..3ed6f4b565
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/spec/sparc/Makefile
@@ -0,0 +1,49 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1998-2003 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# lib/libaio/spec/sparc/Makefile
+
+.KEEP_STATE:
+
+include ../Makefile.targ
+
+# Add arch specific objects here
+OBJECTS +=
+
+include $(SRC)/lib/Makefile.lib
+
+# Uncomment the following if the linker complains
+#sparc_C_PICFLAGS = -K PIC
+
+include $(SRC)/lib/Makefile.spec
+
+# We set ABILLIBC here because libmapmalloc is built before libc
+# and we most avoid ABILLIBC= -lc -z defs from Makefile.spec
+# (-z defs can cause build failures at this point)
+ABILLIBC= -lc
+
+install: $(ROOTABILIB)
diff --git a/usr/src/lib/libmapmalloc/spec/sparcv9/Makefile b/usr/src/lib/libmapmalloc/spec/sparcv9/Makefile
new file mode 100644
index 0000000000..ecf35cd331
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/spec/sparcv9/Makefile
@@ -0,0 +1,50 @@
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1998-2003 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# lib/libaio/spec/sparcv9/Makefile
+
+.KEEP_STATE:
+
+include ../Makefile.targ
+
+# Add arch specific objects here
+OBJECTS +=
+
+include $(SRC)/lib/Makefile.lib
+include $(SRC)/lib/Makefile.lib.64
+
+# Uncomment the following if the linker complains
+#sparcv9_C_PICFLAGS = -K PIC
+
+include $(SRC)/lib/Makefile.spec
+
+# We set ABILLIBC here because libmapmalloc is built before libc
+# and we most avoid ABILLIBC= -lc -z defs from Makefile.spec
+# (-z defs can cause build failures at this point)
+ABILLIBC= -lc
+
+install: $(ROOTABILIB64)
diff --git a/usr/src/lib/libmapmalloc/spec/versions b/usr/src/lib/libmapmalloc/spec/versions
new file mode 100644
index 0000000000..2fed5f1c60
--- /dev/null
+++ b/usr/src/lib/libmapmalloc/spec/versions
@@ -0,0 +1,52 @@
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# 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.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# Note: Even though the SUNW_1.1 version now contains no symbols
+# beyond what was present at Solaris 2.3, the SUNW_1.1 version MUST be
+# present. This is because applications built on 2.6 Beta
+# (when it did contain symbols explicitly) may depend on it.
+#
+
+sparc {
+ SUNW_1.1: {SUNW_0.7};
+ SUNW_0.7;
+ SUNWprivate_1.1;
+}
+sparcv9 {
+ SUNW_1.1: {SUNW_0.7};
+ SUNW_0.7;
+ SUNWprivate_1.1;
+}
+i386 {
+ SUNW_1.1: {SUNW_0.7};
+ SUNW_0.7;
+ SUNWprivate_1.1;
+}
+amd64 {
+ SUNW_1.1: {SUNW_0.7};
+ SUNW_0.7;
+ SUNWprivate_1.1;
+}