70#ifndef LWIP_MEM_ILLEGAL_FREE
71#define LWIP_MEM_ILLEGAL_FREE(msg) LWIP_ASSERT(msg, 0)
74#define MEM_STATS_INC_LOCKED(x) SYS_ARCH_LOCKED(MEM_STATS_INC(x))
75#define MEM_STATS_INC_USED_LOCKED(x, y) SYS_ARCH_LOCKED(MEM_STATS_INC_USED(x, y))
76#define MEM_STATS_DEC_USED_LOCKED(x, y) SYS_ARCH_LOCKED(MEM_STATS_DEC_USED(x, y))
79#define MEM_SANITY_OFFSET MEM_SANITY_REGION_BEFORE_ALIGNED
80#define MEM_SANITY_OVERHEAD (MEM_SANITY_REGION_BEFORE_ALIGNED + MEM_SANITY_REGION_AFTER_ALIGNED)
82#define MEM_SANITY_OFFSET 0
83#define MEM_SANITY_OVERHEAD 0
86#if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK
97mem_overflow_check_raw(
void *
p,
size_t size,
const char *descr1,
const char *descr2)
99#if MEM_SANITY_REGION_AFTER_ALIGNED || MEM_SANITY_REGION_BEFORE_ALIGNED
103#if MEM_SANITY_REGION_AFTER_ALIGNED > 0
105 for (
k = 0;
k < MEM_SANITY_REGION_AFTER_ALIGNED;
k++) {
114#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0
115 m = (
u8_t *)
p - MEM_SANITY_REGION_BEFORE_ALIGNED;
116 for (
k = 0;
k < MEM_SANITY_REGION_BEFORE_ALIGNED;
k++) {
135mem_overflow_init_raw(
void *
p,
size_t size)
137#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0 || MEM_SANITY_REGION_AFTER_ALIGNED > 0
139#if MEM_SANITY_REGION_BEFORE_ALIGNED > 0
140 m = (
u8_t *)
p - MEM_SANITY_REGION_BEFORE_ALIGNED;
141 memset(
m, 0xcd, MEM_SANITY_REGION_BEFORE_ALIGNED);
143#if MEM_SANITY_REGION_AFTER_ALIGNED > 0
145 memset(
m, 0xcd, MEM_SANITY_REGION_AFTER_ALIGNED);
154#if MEM_LIBC_MALLOC || MEM_USE_POOLS
183#define mem_clib_free free
185#ifndef mem_clib_malloc
186#define mem_clib_malloc malloc
188#ifndef mem_clib_calloc
189#define mem_clib_calloc calloc
192#if LWIP_STATS && MEM_STATS
193#define MEM_LIBC_STATSHELPER_SIZE LWIP_MEM_ALIGN_SIZE(sizeof(mem_size_t))
195#define MEM_LIBC_STATSHELPER_SIZE 0
209 void *
ret = mem_clib_malloc(
size + MEM_LIBC_STATSHELPER_SIZE);
214#if LWIP_STATS && MEM_STATS
216 ret = (
u8_t *)
ret + MEM_LIBC_STATSHELPER_SIZE;
232#if LWIP_STATS && MEM_STATS
233 rmem = (
u8_t *)rmem - MEM_LIBC_STATSHELPER_SIZE;
258 for (poolnr = MEMP_POOL_FIRST; poolnr <= MEMP_POOL_LAST; poolnr = (
memp_t)(poolnr + 1)) {
265#if MEM_USE_POOLS_TRY_BIGGER_POOL
267 if (poolnr < MEMP_POOL_LAST) {
277 if (poolnr > MEMP_POOL_LAST) {
278 LWIP_ASSERT(
"mem_malloc(): no pool is that big!", 0);
288#if MEMP_OVERFLOW_CHECK || (LWIP_STATS && MEM_STATS)
293#if MEMP_OVERFLOW_CHECK
310 struct memp_malloc_helper *hmem;
317 hmem = (
struct memp_malloc_helper *)(
void *)((
u8_t *)rmem -
LWIP_MEM_ALIGN_SIZE(
sizeof(
struct memp_malloc_helper)));
324#if MEMP_OVERFLOW_CHECK
328 hmem->size <=
memp_pools[hmem->poolnr]->size);
330 for (
i = hmem->size;
i <
memp_pools[hmem->poolnr]->size;
i++) {
356#if MEM_OVERFLOW_CHECK
369#define MIN_SIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(MIN_SIZE)
370#define SIZEOF_STRUCT_MEM LWIP_MEM_ALIGN_SIZE(sizeof(struct mem))
371#define MEM_SIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(MEM_SIZE)
377#ifndef LWIP_RAM_HEAP_POINTER
380#define LWIP_RAM_HEAP_POINTER ram_heap
393#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
395static volatile u8_t mem_free_count;
398#define LWIP_MEM_FREE_DECL_PROTECT() SYS_ARCH_DECL_PROTECT(lev_free)
399#define LWIP_MEM_FREE_PROTECT() SYS_ARCH_PROTECT(lev_free)
400#define LWIP_MEM_FREE_UNPROTECT() SYS_ARCH_UNPROTECT(lev_free)
401#define LWIP_MEM_ALLOC_DECL_PROTECT() SYS_ARCH_DECL_PROTECT(lev_alloc)
402#define LWIP_MEM_ALLOC_PROTECT() SYS_ARCH_PROTECT(lev_alloc)
403#define LWIP_MEM_ALLOC_UNPROTECT() SYS_ARCH_UNPROTECT(lev_alloc)
404#define LWIP_MEM_LFREE_VOLATILE volatile
409#define LWIP_MEM_FREE_DECL_PROTECT()
410#define LWIP_MEM_FREE_PROTECT() sys_mutex_lock(&mem_mutex)
411#define LWIP_MEM_FREE_UNPROTECT() sys_mutex_unlock(&mem_mutex)
413#define LWIP_MEM_ALLOC_DECL_PROTECT()
414#define LWIP_MEM_ALLOC_PROTECT()
415#define LWIP_MEM_ALLOC_UNPROTECT()
416#define LWIP_MEM_LFREE_VOLATILE
424static void mem_sanity(
void);
425#define MEM_SANITY() mem_sanity()
430#if MEM_OVERFLOW_CHECK
435 mem->user_size = user_size;
436 mem_overflow_init_raw(
p, user_size);
443 mem_overflow_check_raw(
p,
mem->user_size,
"heap",
"");
446#define mem_overflow_init_element(mem, size)
447#define mem_overflow_check_element(mem)
500 if (pmem !=
mem && pmem->
used == 0) {
553 struct mem *nmem, *pmem;
559 ((
mem->
prev != rmem_idx) && (pmem->
next != rmem_idx)) ||
591 if (last_used == 0) {
638 if ((
u8_t *)mem < ram || (u8_t *)rmem + MIN_SIZE_ALIGNED > (
u8_t *)
ram_end) {
645#if MEM_OVERFLOW_CHECK
682#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
714#if MEM_OVERFLOW_CHECK
715 newsize += MEM_SANITY_REGION_BEFORE_ALIGNED + MEM_SANITY_REGION_AFTER_ALIGNED;
733#if MEM_OVERFLOW_CHECK
741 if (newsize >
size) {
745 if (newsize ==
size) {
754 if (mem2->
used == 0) {
811#if MEM_OVERFLOW_CHECK
815#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
835#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
836 u8_t local_mem_free_count = 0;
851#if MEM_OVERFLOW_CHECK
852 size += MEM_SANITY_REGION_BEFORE_ALIGNED + MEM_SANITY_REGION_AFTER_ALIGNED;
861#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
864 local_mem_free_count = 0;
873#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
878 if (mem_free_count != 0) {
881 local_mem_free_count = 1;
928#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
929mem_malloc_adjust_lfree:
935#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
940 if (mem_free_count != 0) {
943 goto mem_malloc_adjust_lfree;
953 LWIP_ASSERT(
"mem_malloc: allocated memory not above ram_end.",
955 LWIP_ASSERT(
"mem_malloc: allocated memory properly aligned.",
960#if MEM_OVERFLOW_CHECK
967#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
969 }
while (local_mem_free_count != 0);
980#if MEM_LIBC_MALLOC && (!LWIP_STATS || !MEM_STATS)
1004 if ((
size_t)(
mem_size_t)alloc_size != alloc_size) {
#define mem_free(ptr, bsize)
static struct mem *LWIP_MEM_LFREE_VOLATILE lfree
#define LWIP_MEM_ALLOC_DECL_PROTECT()
void * mem_calloc(mem_size_t count, mem_size_t size)
static sys_mutex_t mem_mutex
#define MEM_STATS_DEC_USED_LOCKED(x, y)
#define MEM_STATS_INC_LOCKED(x)
static struct mem * ptr_to_mem(mem_size_t ptr)
#define mem_overflow_check_element(mem)
#define LWIP_MEM_ALLOC_PROTECT()
#define LWIP_RAM_HEAP_POINTER
#define LWIP_MEM_FREE_DECL_PROTECT()
static int mem_link_valid(struct mem *mem)
static void plug_holes(struct mem *mem)
#define LWIP_MEM_ILLEGAL_FREE(msg)
#define MEM_SANITY_OVERHEAD
#define mem_overflow_init_element(mem, size)
#define LWIP_MEM_FREE_UNPROTECT()
#define MEM_STATS_INC_USED_LOCKED(x, y)
void * mem_trim(void *rmem, mem_size_t new_size)
#define LWIP_MEM_LFREE_VOLATILE
#define MEM_SANITY_OFFSET
#define SIZEOF_STRUCT_MEM
static struct mem * ram_end
void * mem_malloc(mem_size_t size_in)
static mem_size_t mem_to_ptr(void *mem)
#define LWIP_MEM_FREE_PROTECT()
#define LWIP_MEM_ALLOC_UNPROTECT()
#define LWIP_DEBUGF(debug, message)
#define LWIP_ASSERT(message, assertion)
GLuint GLuint GLsizei count
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size)
#define LWIP_UNUSED_ARG(x)
#define LWIP_MEM_ALIGN(addr)
#define LWIP_MEM_ALIGN_SIZE(size)
#define LWIP_DBG_LEVEL_SERIOUS
#define LWIP_DBG_LEVEL_SEVERE
err_t sys_mutex_new(sys_mutex_t *mutex)
void sys_mutex_lock(sys_mutex_t *mutex)
void sys_mutex_unlock(sys_mutex_t *mutex)
void * memp_malloc(memp_t type)
const struct memp_desc *const memp_pools[MEMP_MAX]
void memp_free(memp_t type, void *mem)
static const WCHAR desc[]
static unsigned __int64 next
#define MEM_STATS_AVAIL(x, y)
#define MEM_STATS_DEC_USED(x, y)
#define MEM_STATS_INC_USED(x, y)
const char * errstr(int errcode)