/*
* 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
*/
/*
*/
/*
* The structure of the sbrk backend:
*
* +-----------+
* | sbrk_top |
* +-----------+
* | (vmem_sbrk_alloc(), vmem_free())
* |
* +-----------+
* | sbrk_heap |
* +-----------+
* | | ... | (vmem_alloc(), vmem_free())
* <other arenas>
*
* The sbrk_top arena holds all controlled memory. vmem_sbrk_alloc() handles
* allocations from it, including growing the heap when we run low.
*
* Growing the heap is complicated by the fact that we have to extend the
* sbrk_top arena (using _vmem_extend_alloc()), and that can fail. Since
* other threads may be actively allocating, we can't return the memory.
*
* Instead, we put it on a doubly-linked list, sbrk_fails, which we search
* before calling sbrk().
*/
#include <errno.h>
#include <limits.h>
#include <sys/sysmacros.h>
#include <unistd.h>
#include "vmem_base.h"
#include "misc.h"
typedef struct sbrk_fail {
} sbrk_fail_t;
NULL,
0
};
/*
* Try to extend src with [pos, pos + size).
*
* If it fails, add the block to the sbrk_fails list.
*/
static void *
int vmflags)
{
void *ret;
return (ret);
(void) mutex_lock(&sbrk_faillock);
(void) mutex_unlock(&sbrk_faillock);
return (NULL);
}
/*
* Try to add at least size bytes to src, using the sbrk_fails list
*/
static void *
{
(void) mutex_lock(&sbrk_faillock);
break;
}
}
(void) mutex_unlock(&sbrk_faillock);
if (fp != &sbrk_fails) {
vmflags));
}
/*
* nothing of the right size on the freelist
*/
return (NULL);
}
static void *
{
void *ret;
void *buf;
return (ret);
}
/*
* The allocation failed. We need to grow the heap.
*
* First, try to use any buffers which failed earlier.
*/
return (ret);
/*
* buf_size gets overwritten with the actual allocated size
*/
&buf_size);
if (buf != MAP_FAILED) {
return (ret);
}
}
/*
* Growing the heap failed. The vmem_alloc() above called umem_reap().
*/
return (NULL);
}
/*
* fork1() support
*/
void
vmem_sbrk_lockup(void)
{
(void) mutex_lock(&sbrk_faillock);
}
void
vmem_sbrk_release(void)
{
(void) mutex_unlock(&sbrk_faillock);
}
vmem_t *
{
if (issetugid()) {
heap_size = 0;
heap_size = 0;
}
if (heap_size <= real_pagesize) {
} else {
== -1) {
log_message("unable to set MAPSIZE_BSSBRK to "
"0x%p\n", heap_size);
}
}
/* validate vmem_sbrk_minalloc */
}
*a_out = vmem_alloc;
return (sbrk_heap);
}