00001 #ifndef UFFS_MEM_H 00002 #define UFFS_MEM_H 00003 00004 #include "uffs/uffs_device.h" 00005 00006 #ifdef __cplusplus 00007 extern "C"{ 00008 #endif 00009 00010 #define HEAP_HASH_BIT 6 /* hash table bit */ 00011 #define HEAP_HASH_SIZE (1 << (HEAP_HASH_BIT - 1)) /* hash table size */ 00012 #define HEAP_HASH_MASK (HEAP_HASH_SIZE - 1) /* hash table mask */ 00013 #define GET_HASH_INDEX(p) ((((u32)(p)) >> 2) & HEAP_HASH_MASK) 00014 00015 /* memory alloc node */ 00016 typedef struct _heap_mm_node{ 00017 int task_id; /* who alloc this block? it's the caller's task id */ 00018 struct _heap_mm_node * next; /* point to next node */ 00019 void *p; /* point to allocated block */ 00020 int size; /* block size */ 00021 } HEAP_MM; 00022 00023 typedef HEAP_MM* HASHTBL; 00024 00025 00027 typedef struct uffs_memAllocatorSt { 00028 HASHTBL tbl[HEAP_HASH_SIZE]; 00029 void * (*malloc)(struct uffs_memAllocatorSt *mem, unsigned int size); 00030 void * (*realloc)(struct uffs_memAllocatorSt *mem, void *p, unsigned int size); 00031 void * (*calloc)(struct uffs_memAllocatorSt *mem, unsigned int num, unsigned int size); 00032 void (*free)(struct uffs_memAllocatorSt *mem, void *p); 00033 int count; 00034 int maxused; 00035 } uffs_memAllocator; 00036 00038 void uffs_InitHeapMemory(void *addr, int size); 00039 00040 URET uffs_initNativeMemAllocator(uffs_Device *dev); 00041 int uffs_releaseNativeMemAllocator(uffs_Device *dev); 00042 00043 #ifdef __cplusplus 00044 } 00045 #endif 00046 00047 00048 #endif 00049