1 /* 2 Low Level Interface Library 3 Copyright 1983-2006 Green Hills Software,Inc. 4 5 * This program is the property of Green Hills Software, Inc, 6 * its contents are proprietary information and no part of it 7 * is to be disclosed to anyone except employees of Green Hills 8 * Software, Inc., or as agreed in writing signed by the President 9 * of Green Hills Software, Inc. 10 */ 11 /* ind_heap.c: Machine Independent low-level heap growth facilities. */ 12 13 #include "indos.h" 14 #include <string.h> /* for memset() */ 15 #include <stddef.h> /* for memset() */ 16 #include "ind_thrd.h" 17 18 #if defined(EMBEDDED) 19 /******************************************************************************/ 20 /* int brk (void *addr); */ 21 /* Extend the heap. Depending on the environment, this may just test for */ 22 /* valid memory at addr-1 (like under the ROM Monitor) or it may result in */ 23 /* process memory allocation (by a simulator process). Return 0 on success. */ 24 /* */ 25 /* Return -1 on an error and set errno = ENOMEM. */ 26 /* */ 27 /* brk() is no longer called, and is only here for programs that want to use */ 28 /* it directly and know what they are doing. If possible, use only sbrk(). */ 29 /******************************************************************************/ 30 #if 0 31 int brk (void *addr) 32 { 33 if (__ghs_syscall(SYSCALL_BRK, addr)) { 34 __gh_set_errno(ENOMEM); 35 return -1; 36 } 37 return 0; 38 } 39 #endif 40 41 /******************************************************************************/ 42 /* void *__ghs_heapseg_size (void); */ 43 /* */ 44 /* Return the size of the heap segment being managed by sbrk. */ 45 /* */ 46 /* __ghs_heapseg_size is normally only called during startup and only by */ 47 /* malloc(). */ 48 /******************************************************************************/ 49 50 #if 0 // CAFE GHS ORIG 51 size_t __ghs_heapseg_size(void) 52 { 53 extern char __ghsbegin_heap[], __ghsend_heap[]; 54 return (&__ghsend_heap[0] - &__ghsbegin_heap[0]); 55 } 56 #endif // CAFE GHS ORIG 57 58 /******************************************************************************/ 59 /* void *sbrk (size_t size); */ 60 /* Return a pointer to at least size bytes of contiguous read/write memory. */ 61 /* The memory returned by sbrk on different calls need not be contiguous */ 62 /* with each other (although they should be for compatibility with unix). */ 63 /* */ 64 /* Return -1 on an error and set errno = ENOMEM. */ 65 /* */ 66 /* sbrk is normally only called by malloc. */ 67 /* */ 68 /* WARNING: __ghs_alloc() relies on our contiguous algorithm and our */ 69 /* behavior for size==0, which returns the next-available pointer. */ 70 /******************************************************************************/ 71 72 #if 0 // CAFE GHS ORIG 73 void *sbrk (size_t size) 74 { 75 extern char __ghsbegin_heap[], __ghsend_heap[]; 76 static char *pt; 77 char *npt; 78 void *ret; 79 80 __ghsLock(); 81 if (pt == NULL) 82 pt = __ghsbegin_heap; 83 npt = pt + size; 84 if (__ghsbegin_heap <= npt && npt <= __ghsend_heap) 85 ret = ((pt = npt) - size); 86 else { 87 /* cast to short for v850e with 16bit data pointers. harmless elsewhere. */ 88 ret = (void *)(short)-1; 89 __gh_set_errno(ENOMEM); 90 } 91 __ghsUnlock(); 92 return ret; 93 } 94 #endif // CAFE GHS ORIG 95 96 #endif 97