2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2011 Daniel Borkmann.
9 * Two Levels Segregate Fit memory allocator (TLSF), Version 2.4.6
10 * Written by Miguel Masmano Tello <mimastel@doctor.upv.es>
11 * Thanks to Ismael Ripoll for his suggestions and reviews
12 * Copyright (C) 2008, 2007, 2006, 2005, 2004
13 * This code is released using a dual license strategy: GPL/LGPL
14 * You can choose the licence that better fits your requirements.
15 * Released under the terms of the GNU General Public License Version 2.0
16 * Released under the terms of the GNU Lesser General Public License Version 2.1
22 #include <sys/types.h>
29 extern size_t init_memory_pool(size_t, void *);
30 extern size_t get_used_size(void *);
31 extern size_t get_max_size(void *);
32 extern void destroy_memory_pool(void *);
33 extern size_t add_new_area(void *, size_t, void *);
34 extern void *malloc_ex(size_t, void *);
35 extern void free_ex(void *, void *);
36 extern void *realloc_ex(void *, size_t, void *);
37 extern void *calloc_ex(size_t, size_t, void *);
39 extern void *tlsf_malloc(size_t size
);
40 extern void tlsf_free(void *ptr
);
41 extern void *tlsf_realloc(void *ptr
, size_t size
);
42 extern void *tlsf_calloc(size_t nelem
, size_t elem_size
);
44 static inline void *xtlsf_malloc(size_t size
)
47 if (unlikely(size
== 0))
48 panic("xtlsf_malloc: zero size!\n");
49 ptr
= tlsf_malloc(size
);
51 panic("xtlsf_malloc: out of mem!\n");
55 static inline void xtlsf_free(void *ptr
)
58 panic("xtlsf_free: freeing NULL ptr!\n");
62 static inline char *xtlsf_strdup(const char *str
)
66 len
= strlen(str
) + 1;
67 cp
= xtlsf_malloc(len
);
68 strlcpy(cp
, str
, len
);