00001 /*----------------------------------------------------------------------- 00002 * This file is used to manage heaps 00003 * 00004 * Created April 2, 2008 by Jim Patchell 00005 * 00006 -------------------------------------------------------------------------*/ 00007 00008 /* Copyright (c) 2004, Joerg Wunsch 00009 All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are met: 00013 00014 * Redistributions of source code must retain the above copyright 00015 notice, this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright 00017 notice, this list of conditions and the following disclaimer in 00018 the documentation and/or other materials provided with the 00019 distribution. 00020 * Neither the name of the copyright holders nor the names of 00021 contributors may be used to endorse or promote products derived 00022 from this software without specific prior written permission. 00023 00024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00027 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00028 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00029 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00030 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00031 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00032 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00033 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 POSSIBILITY OF SUCH DAMAGE. 00035 */ 00036 00037 /* $Id: stdlib_private.h,v 1.2 2005/09/13 13:29:54 joerg_wunsch Exp $ */ 00038 00039 #ifndef HEAPMANAGER__H 00040 #define HEAPMANAGER__H 00041 00042 #include <inttypes.h> 00043 #include <stdlib.h> 00044 00051 00052 #include "task.h" 00053 00054 00055 struct __freelist { 00056 size_t sz; 00057 struct __freelist *nx; 00058 }; 00059 00060 #define STACK_POINTER() ((char *)SP) 00061 00062 00063 extern char *__brkval; /* first location not yet allocated */ 00064 extern struct __freelist *__flp; /* freelist pointer (head of freelist) */ 00065 extern size_t __malloc_margin; /* user-changeable before the first malloc() */ 00066 extern char *__malloc_heap_start; 00067 extern char *__malloc_heap_end; 00068 00069 extern char __heap_start; 00070 extern char __heap_end; 00071 00072 typedef struct { 00073 char *Start; 00074 char *End; 00075 char *BrkVal; 00076 size_t Margin; 00077 struct __freelist *__flp; 00078 ECB *Blocker; 00079 }HEAP_BLOCK; 00080 00081 extern HEAP_BLOCK *HeapInit(char *start, char *end); 00082 extern void *HeapAlloc(HEAP_BLOCK *pHB,size_t len); 00083 extern void HeapFree(HEAP_BLOCK *pHB, void *p); 00084 extern size_t HeapFreeSpace(HEAP_BLOCK *pHB); 00085 00088 #endif