/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* 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
* 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 */
/*
* 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.
*
* 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 <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <thread.h>
#include <pthread.h>
#include <synch.h>
#include <string.h>
struct block {
int status;
};
struct page {
};
#define FREE 0
#define MINSZ sizeof (double)
/* for convenience */
#ifndef NULL
#define NULL (0)
#endif
static int pagesize;
static void *malloc_unlocked(size_t);
void *
{
void *retval;
(void) mutex_lock(&lock);
(void) mutex_unlock(&lock);
return (retval);
}
static void *
{
if (pagesize == 0)
/*
* Try to locate necessary space
*/
goto found;
}
}
/*
* Need to allocate a new page
*/
if (!page) {
== MAP_FAILED)
return (0);
}
}
void *
{
void *newptr;
if (size == 0) {
return ((void *)0x00000001);
}
(void) mutex_lock(&lock);
if (ptr <= (void *)0x00000001) {
(void) mutex_unlock(&lock);
return (newptr);
}
/*
* Join block with next one if it is free
*/
}
(void) mutex_unlock(&lock);
return (ptr);
}
(void) mutex_unlock(&lock);
return (newptr);
}
void
{
(void) mutex_lock(&lock);
if (ptr <= (void *)0x00000001) {
(void) mutex_unlock(&lock);
return;
}
(void) mutex_unlock(&lock);
}
/*
* Align size on an appropriate boundary
*/
static size_t
{
else
}
static void
{
}
}
/*
* Defragmentation
*/
static void
{
continue;
}
}
/*
* Free page
*/
else {
break;
}
}
}
}
}
static void
{
(void) mutex_lock(&lock);
}
static void
{
(void) mutex_unlock(&lock);
}
#pragma init(malloc_init)
static void
malloc_init(void)
{
}