9 #define RTL_TLSF_DEBUG 1 11 #define DEBUG_TLSF_ALLOC (1<<0) 12 #define DEBUG_TLSF_FREE (1<<1) 13 #define DEBUG_TLSF_TRACE (1<<20) 16 # define _DBG(x, mask, fmt, ...) do{ if (mask & x) printf("%s: " fmt "\n", __FUNCTION__, __VA_ARGS__); } while(0) 18 # define _DBG(x, mask, fmt, ...) do { } while(0) 21 #define TLSF_POOL_MIN_SIZE 1*1014*1024 28 tlsf_inf->
pool2 = NULL;
32 fprintf(stderr,
"error: requested tlsf pool size (0x%lx) too small\n", (
unsigned long) sz);
36 tlsf_inf->
pool = malloc(sz);
39 fprintf(stderr,
"error failed to allocate: 0x%lx bytes\n", (
unsigned long) sz);
56 free(tlsf_inf->
pool2);
64 luaL_error(L,
"memory allocation in TLSF trace mode");
68 void*
tlsf_alloc (
void *ud,
void *ptr,
size_t osize,
size_t nsize)
75 (
unsigned long) ptr, (
unsigned long) osize, (
unsigned long) nsize);
83 (
unsigned long) ptr, (
unsigned long) osize, (
unsigned long) nsize);
90 if(tlsf_inf->
pool2 != NULL)
91 luaL_error(tlsf_inf->
L,
"tlsf_rtt_incmem: region already increased, (increasing cur. only possible once)");
93 if((tlsf_inf->
pool2 = malloc(sz)) == NULL)
94 luaL_error(tlsf_inf->
L,
"tlsf_rtt_incmem: failed to increase memory by %d bytes. Out of mem.");
121 int argc, enable, ret;
147 int argc, enable, ret;
178 static const struct luaL_Reg
tlsf_f [] = {
187 luaL_register(L,
"tlsf",
tlsf_f);
LUA_API void() lua_pushstring(lua_State *L, const char *s)
LUA_API void() lua_pushinteger(lua_State *L, lua_Integer n)
static int tlsf_trace(lua_State *L)
static int tlsf_warn(lua_State *L)
static const struct luaL_Reg tlsf_f[]
LUA_API void() lua_pushlightuserdata(lua_State *L, void *p)
int tlsf_rtt_init_mp(struct lua_tlsf_info *tlsf_inf, size_t sz)
struct lua_tlsf_info * get_context_tlsf_info(lua_State *L)
LUA_API int() lua_toboolean(lua_State *L, int idx)
size_t rtl_get_used_size(void *mem_pool ATTRIBUTE_UNUSED)
size_t rtl_add_new_area(void *area, size_t area_size, void *mem_pool)
LUA_API void() lua_rawset(lua_State *L, int idx)
LUA_API void() lua_rawget(lua_State *L, int idx)
void rtl_free_ex(void *ptr, void *mem_pool)
void set_context_tlsf_info(struct lua_tlsf_info *tlsf_inf)
#define TLSF_POOL_MIN_SIZE
struct lua_State lua_State
LUA_API void() lua_pushboolean(lua_State *L, int b)
size_t rtl_init_memory_pool(size_t mem_pool_size, void *mem_pool)
size_t rtl_get_max_size(void *mem_pool ATTRIBUTE_UNUSED)
void * rtl_realloc_ex(void *ptr, size_t new_size, void *mem_pool)
static void tlsf_trace_hook(lua_State *L, lua_Debug *ar)
void tlsf_rtt_free_mp(struct lua_tlsf_info *tlsf_inf)
#define _DBG(x, mask, fmt,...)
LUA_API int() lua_gettop(lua_State *L)
int tlsf_rtt_incmem(struct lua_tlsf_info *tlsf_inf, size_t sz)
void register_tlsf_api(lua_State *L)
LUA_API void *() lua_touserdata(lua_State *L, int idx)
static int tlsf_stats(lua_State *L)
#define LUA_REGISTRYINDEX
void * tlsf_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
void rtl_destroy_memory_pool(void *mem_pool)