sbrk.c (256281) | sbrk.c (269101) |
---|---|
1/*- 2 * Copyright (c) 1998 Michael Smith 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1998 Michael Smith 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: stable/10/lib/libstand/sbrk.c 136093 2004-10-03 15:58:20Z stefanf $"); | 28__FBSDID("$FreeBSD: stable/10/lib/libstand/sbrk.c 269101 2014-07-25 23:12:22Z ian $"); |
29 30/* 31 * Minimal sbrk() emulation required for malloc support. 32 */ 33 34#include <string.h> 35#include "stand.h" | 29 30/* 31 * Minimal sbrk() emulation required for malloc support. 32 */ 33 34#include <string.h> 35#include "stand.h" |
36#include "zalloc_defs.h" |
|
36 37static size_t maxheap, heapsize = 0; 38static void *heapbase; 39 40void 41setheap(void *base, void *top) 42{ | 37 38static size_t maxheap, heapsize = 0; 39static void *heapbase; 40 41void 42setheap(void *base, void *top) 43{ |
43 /* Align start address to 16 bytes for the malloc code. Sigh. */ 44 heapbase = (void *)(((uintptr_t)base + 15) & ~15); | 44 /* Align start address for the malloc code. Sigh. */ 45 heapbase = (void *)(((uintptr_t)base + MALLOCALIGN_MASK) & 46 ~MALLOCALIGN_MASK); |
45 maxheap = (char *)top - (char *)heapbase; 46} 47 48char * 49sbrk(int incr) 50{ 51 char *ret; 52 53 if ((heapsize + incr) <= maxheap) { 54 ret = (char *)heapbase + heapsize; 55 bzero(ret, incr); 56 heapsize += incr; 57 return(ret); 58 } 59 errno = ENOMEM; 60 return((char *)-1); 61} 62 | 47 maxheap = (char *)top - (char *)heapbase; 48} 49 50char * 51sbrk(int incr) 52{ 53 char *ret; 54 55 if ((heapsize + incr) <= maxheap) { 56 ret = (char *)heapbase + heapsize; 57 bzero(ret, incr); 58 heapsize += incr; 59 return(ret); 60 } 61 errno = ENOMEM; 62 return((char *)-1); 63} 64 |