/*
* 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 2008 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"
#include "lint.h"
#include "mallint.h"
#include "mtlib.h"
/* 4-byte "word" alignment is considered ok in LP64 */
/*
* memalign(align, nbytes)
*
* Description:
* Returns a block of specified size on a specified alignment boundary.
*
* Algorithm:
* Malloc enough to ensure that a block can be aligned correctly.
* Find the alignment point and return the fragments
* before and after the block.
*
* Errors:
* Returns NULL and sets errno as follows:
* [EINVAL]
* if nbytes = 0,
* or if alignment is misaligned,
* or if the heap has been detectably corrupted.
* [ENOMEM]
* if the requested memory could not be allocated.
*/
void *
{
TREE *p; /* Ptr returned from malloc() */
size_t x;
if (!primary_link_map) {
return (NULL);
}
/*
* check for valid size and alignment parameters
* MAX_ALIGN check prevents overflow in later calculation.
*/
return (NULL);
}
/*
* Malloc enough memory to guarantee that the result can be
* aligned correctly. The worst case is when malloc returns
* a block so close to the next alignment boundary that a
* fragment of minimum size cannot be created. In order to
* make sure we can handle this, we need to force the
* alignment to be at least as large as the minimum frag size
* (MINSIZE + WORDSIZE).
*/
/* check for size that could overflow calculations */
if (nbytes > MAX_MALLOC) {
return (NULL);
}
align <<= 1;
/* check for overflow */
return (NULL);
}
/* malloc sets errno */
return (NULL);
}
(void) mutex_lock(&libc_malloc_lock);
/*
* get size of the entire block (overhead and all)
*/
/*
* locate the proper alignment boundary within the block.
*/
x = (size_t)p;
if (x % align != 0)
/*
* Check out the space to the left of the alignment
* boundary, and split off a fragment if necessary.
*/
if (frag_size != 0) {
/*
* Create a fragment to the left of the aligned block.
*/
/*
* Not enough space. So make the split
* at the other end of the alignment unit.
* We know this yields enough space, because
* we forced align >= MINSIZE + WORDSIZE above.
*/
}
}
/*
* Is there a (sufficiently large) fragment to the
* right of the aligned block?
*/
/*
* split and free a fragment on the right
*/
}
(void) mutex_unlock(&libc_malloc_lock);
return (DATA(aligned_blk));
}