00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _THREE_LEVELS_SEGREGATE_FIT_MALLOC_H_
00012 #define _THREE_LEVELS_SEGREGATE_FIT_MALLOC_H_
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define WITH_RTL_PREFIX
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #define MAX_FL_INDEX 24 // TLSF default MAX_FL_INDEX is 16 MBytes
00040
00041
00042
00043 #if defined(__KERNEL__) && !defined(__RTL__)
00044 #error "This modules can only be used in RTLinux or user space"
00045 #endif
00046
00047 #include <linux/types.h>
00048
00049 #define __u8 unsigned char
00050 #define __u16 unsigned short
00051 #define __u32 unsigned int
00052 #define __s8 char
00053 #define __s16 short
00054 #define __s32 int
00055
00056 #ifdef __RTL__
00057
00058
00059
00060 #include <rtl.h>
00061
00062 #define PRINT_MSG rtl_printf
00063 #define PRINT_DBG_C(message) rtl_printf(message)
00064 #define PRINT_DBG_D(message) rtl_printf("%i", message);
00065
00066 #define PRINT_DBG_H(message) rtl_printf("%x", (unsigned int) message);
00067
00068 #else
00069
00070
00071
00072 #include <stdlib.h>
00073 #include <stdio.h>
00074 #define PRINT_MSG printf
00075 #define PRINT_DBG_C(message) printf(message)
00076 #define PRINT_DBG_D(message) printf("%i", message);
00077 #define PRINT_DBG_F(message) printf("%f", message);
00078 #define PRINT_DBG_H(message) printf("%x", (unsigned int) message);
00079
00080 #endif
00081
00082 extern char *main_buffer;
00083
00084
00085
00086
00087
00088
00089
00090
00091 #define associate_buffer(ptr) main_buffer = (char *) ptr;
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 int init_memory_pool (int max_size,
00112 int max_sl_log2_index, char *block_ptr);
00113
00114 void destroy_memory_pool (char *block_ptr);
00115
00116
00117 #ifdef WITH_RTL_PREFIX
00118 #define rtl_malloc(size) rtl_malloc_ex (size, main_buffer)
00119 void *rtl_malloc_ex (size_t size, char *block_ptr);
00120 #else
00121 #define malloc(size) malloc_ex (size, main_buffer)
00122 void *malloc_ex (size_t size, char *block_ptr);
00123 #endif
00124
00125
00126 #ifdef WITH_RTL_PREFIX
00127 #define rtl_realloc(p, new_len) rtl_realloc_ex (p, new_len, main_buffer)
00128 void *rtl_realloc_ex (void *p, size_t new_len, char *block_ptr);
00129 #else
00130 #define realloc(p, new_len) realloc_ex (p, new_len, main_buffer)
00131 void *realloc_ex (void *p, size_t new_len, char *block_ptr);
00132 #endif
00133
00134
00135 #ifdef WITH_RTL_PREFIX
00136 #define rtl_calloc(nelem, elem_size) \
00137 rtl_calloc_ex (nelem, elem_size, main_buffer)
00138 void *rtl_calloc_ex (size_t nelem, size_t elem_size, char *block_ptr);
00139 #else
00140 #define calloc(nelem, elem_size) \
00141 calloc_ex (nelem, elem_size, main_buffer)
00142 void *calloc_ex (size_t nelem, size_t elem_size, char *block_ptr);
00143 #endif
00144
00145
00146
00147
00148
00149
00150
00151
00152 #ifdef WITH_RTL_PREFIX
00153 #define rtl_free(ptr) rtl_free_ex (ptr, main_buffer)
00154 void rtl_free_ex (void *ptr, char *block_ptr);
00155 #else
00156 #define free(ptr) free_ex (ptr, main_buffer)
00157 void free_ex (void *ptr, char *block_ptr);
00158 #endif
00159
00160 void free_blocks_status (char *block_ptr);
00161 void structure_status (char *block_ptr);
00162
00163 #endif // #ifndef _THREE_LEVELS_SEGREGATE_FIT_MALLOC_H_