blok.c revision db397771158a0b9b33b5ab2dee8593e03ee5e994
/*
* 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
* 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 2001 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* UNIX shell
*/
#include "defs.h"
/*
* storage allocator
* (circular first fit strategy)
*/
#define BUSY 01
unsigned char *brkbegin;
unsigned char *setbrk();
void addblok(unsigned int);
#ifdef __STDC__
void *
#else
char *
#endif
{
if (stakbot == 0) {
addblok((unsigned)0);
}
for (;;)
{
int c = 0;
struct blk *q;
do
{
if (!busy(p))
{
if ((char *)q - (char *)p >= rbytes)
{
((char *)p + rbytes);
if (q > blokp)
return ((char *)(p + 1));
}
}
q = p;
} while (p > q || (c++) == 0);
}
}
void
{
if (stakbot == 0) {
}
unsigned char *rndstak;
pushstak(0);
}
/*
* brkend points to the first invalid address.
* make sure bloktop is valid.
*/
if (setbrk((unsigned)((unsigned char *)
(unsigned char *)-1)
}
if (setbrk((unsigned)((unsigned char *)
(unsigned char *)-1)
}
{
unsigned char *stakadr = (unsigned char *)
(bloktop + 2);
while (reqd-- > 0)
sp--;
}
}
}
void
void *ap;
{
struct blk *p;
{
#ifdef DEBUG
chkbptr(p);
#endif
--p;
}
}
#ifdef DEBUG
{
int exf = 0;
struct blk *q;
for (;;)
{
if (p+1 == ptr)
exf++;
abort(3);
if (p == bloktop)
break;
if (busy(p))
us += q - p;
else
un += q - p;
if (p >= q)
abort(4);
p = q;
}
if (exf == 0)
abort(1);
}
chkmem()
{
struct blk *q;
for (;;) {
abort(3);
if (p == bloktop)
break;
if (busy(p))
us += q - p;
else
un += q - p;
if (p >= q)
abort(4);
p = q;
}
blank();
blank();
newline();
}
#endif
blklen(q)
char *q;
{
struct blk *p;
--pp;
return ((size_t)((long)p - (long)q));
}
/*
* This is a really hasty hack at putting realloc() in the shell, along
* with alloc() and free(). I really hate having to do things like this,
* hacking in something before I understand _why_ libcollate does any
* memory (re)allocation, let alone feel comfortable with this particular
* implementation of realloc, assuming it actually gets used by anything.
*
* I plan to revist this, for now this is just to get sh to compile so
* that xcu4 builds may be done and we get xcu4 on our desktops.
*
* Eric Brunner, 10/21/94
*
* Implemented a variation on the suggested fix in Trusted Solaris 2.5,
* then forward ported the fix into the mainline shell.
*
* 3/3/99
*/
#ifdef __STDC__
void *
void *pp;
#else
char *
char *pp;
#endif
{
char *q;
return ((char *)q);
return (pp);
} else { /* free excess */
return ((char *)q);
}
#ifdef undef
/*
* all of what follows is the _idea_ of what is going to be done
* getting the size of the block is a problem -- what follows
* is _not_ "real", since "sizeof" isn't going to tell me any
* thing usefull, probably have to travers the list to the next
* blk, then subtract ptr addrs ... and be careful not to leave
* holes.
*/
if (sizeof (p) < nbytes) { /* need to grow */
return ((char *)q);
} else if (sizeof (p) == nbytes) { /* do nothing */
return (pp);
} else { /* free excess */
return ((char *)q);
}
#endif
}