/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident "$Header: profbrk.c 1.1 89/04/17 $"

#include <sys/types.h>
#include <sys/mman.h>
#include "parallel.h"
#include "parc.h"

/*
 * profbrk(incr)
 *
 *	This is called by [g]monitor to allocate space for profiling
 *	buffers. The private heap area for parallel programs typically
 *	is NOT large enough to hold all the profile data structures.  
 *
 *	This function allocates this space out of the shared
 *	heap, then over-maps that region to ZFOD.
 *
 */

char *
_profbrk(incr)
int incr;
{
	char *bptr, *eptr;
	int pincr;

	/*
	 * Make sure the allocation starts on a page boundary, and that
	 * the allocated size is a page multiple.
	 */
	pincr = (int)PGRND(incr);
	bptr = PGRND(shsbrk(0));
	if (shbrk(bptr))
		return((char *)-1);
	/*
	 * allocate the space, and map over it with ZFOD
	 */
	if (shbrk(bptr + pincr))
		return((char *)-1);
	if (ZFOD_MMAP(bptr, pincr))
		return((char *)-1);
	return(bptr);
}
