71 #error MEM_USE_POOLS and MEMP_MEM_MALLOC cannot be used together 87 struct memp_malloc_helper *element;
91 for (poolnr = MEMP_POOL_FIRST; poolnr <= MEMP_POOL_LAST; poolnr = (
memp_t)(poolnr + 1)) {
92 #if MEM_USE_POOLS_TRY_BIGGER_POOL 97 if (required_size <=
memp_pools[poolnr]->size) {
101 if (poolnr > MEMP_POOL_LAST) {
102 LWIP_ASSERT(
"mem_malloc(): no pool is that big!", 0);
105 element = (
struct memp_malloc_helper*)
memp_malloc(poolnr);
106 if (element ==
NULL) {
109 #if MEM_USE_POOLS_TRY_BIGGER_POOL 111 if (poolnr < MEMP_POOL_LAST) {
120 element->poolnr = poolnr;
124 #if MEMP_OVERFLOW_CHECK 126 element->size = size;
142 struct memp_malloc_helper *hmem;
148 hmem = (
struct memp_malloc_helper*)(
void*)((
u8_t*)rmem -
LWIP_MEM_ALIGN_SIZE(
sizeof(
struct memp_malloc_helper)));
154 #if MEMP_OVERFLOW_CHECK 162 LWIP_ASSERT(
"MEM_USE_POOLS: mem overflow detected", data == 0xcd);
195 #define MIN_SIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(MIN_SIZE) 196 #define SIZEOF_STRUCT_MEM LWIP_MEM_ALIGN_SIZE(sizeof(struct mem)) 197 #define MEM_SIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(MEM_SIZE) 203 #ifndef LWIP_RAM_HEAP_POINTER 206 #define LWIP_RAM_HEAP_POINTER ram_heap 212 static struct mem *ram_end;
214 static struct mem *lfree;
221 #if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 223 static volatile u8_t mem_free_count;
226 #define LWIP_MEM_FREE_DECL_PROTECT() SYS_ARCH_DECL_PROTECT(lev_free) 227 #define LWIP_MEM_FREE_PROTECT() SYS_ARCH_PROTECT(lev_free) 228 #define LWIP_MEM_FREE_UNPROTECT() SYS_ARCH_UNPROTECT(lev_free) 229 #define LWIP_MEM_ALLOC_DECL_PROTECT() SYS_ARCH_DECL_PROTECT(lev_alloc) 230 #define LWIP_MEM_ALLOC_PROTECT() SYS_ARCH_PROTECT(lev_alloc) 231 #define LWIP_MEM_ALLOC_UNPROTECT() SYS_ARCH_UNPROTECT(lev_alloc) 236 #define LWIP_MEM_FREE_DECL_PROTECT() 237 #define LWIP_MEM_FREE_PROTECT() sys_mutex_lock(&mem_mutex) 238 #define LWIP_MEM_FREE_UNPROTECT() sys_mutex_unlock(&mem_mutex) 240 #define LWIP_MEM_ALLOC_DECL_PROTECT() 241 #define LWIP_MEM_ALLOC_PROTECT() 242 #define LWIP_MEM_ALLOC_UNPROTECT() 259 plug_holes(
struct mem *
mem)
271 nmem = (
struct mem *)(
void *)&ram[mem->
next];
272 if (mem != nmem && nmem->
used == 0 && (
u8_t *)nmem != (
u8_t *)ram_end) {
282 pmem = (
struct mem *)(
void *)&ram[mem->
prev];
283 if (pmem != mem && pmem->
used == 0) {
307 mem = (
struct mem *)(
void *)ram;
318 lfree = (
struct mem *)(
void *)ram;
375 #if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 431 LWIP_ASSERT(
"mem_trim can only shrink memory", newsize <= size);
432 if (newsize > size) {
436 if (newsize == size) {
444 mem2 = (
struct mem *)(
void *)&ram[mem->
next];
445 if (mem2->
used == 0) {
451 ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
453 lfree = (
struct mem *)(
void *)&ram[ptr2];
455 mem2 = (
struct mem *)(
void *)&ram[ptr2];
467 ((
struct mem *)(
void *)&ram[mem2->
next])->
prev = ptr2;
479 ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
480 mem2 = (
struct mem *)(
void *)&ram[ptr2];
489 ((
struct mem *)(
void *)&ram[mem2->
next])->
prev = ptr2;
500 #if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 521 #if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 522 u8_t local_mem_free_count = 0;
546 #if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 549 local_mem_free_count = 0;
556 ptr = ((
struct mem *)(
void *)&ram[ptr])->
next) {
557 mem = (
struct mem *)(
void *)&ram[ptr];
558 #if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 563 if (mem_free_count != 0) {
566 local_mem_free_count = 1;
589 mem2 = (
struct mem *)(
void *)&ram[ptr2];
598 ((
struct mem *)(
void *)&ram[mem2->
next])->
prev = ptr2;
612 #if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 613 mem_malloc_adjust_lfree:
616 struct mem *cur = lfree;
618 while (cur->
used && cur != ram_end) {
619 #if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 624 if (mem_free_count != 0) {
627 goto mem_malloc_adjust_lfree;
630 cur = (
struct mem *)(
void *)&ram[cur->
next];
633 LWIP_ASSERT(
"mem_malloc: !lfree->used", ((lfree == ram_end) || (!lfree->
used)));
637 LWIP_ASSERT(
"mem_malloc: allocated memory not above ram_end.",
639 LWIP_ASSERT(
"mem_malloc: allocated memory properly aligned.",
647 #if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 649 }
while (local_mem_free_count != 0);
677 memset(p, 0, (
size_t)count * (
size_t)size);
err_t sys_mutex_new(sys_mutex_t *mutex)
#define LWIP_DBG_LEVEL_SERIOUS
u8_t ram_heap[MEM_SIZE_ALIGNED+(2U *SIZEOF_STRUCT_MEM)+MEM_ALIGNMENT]
void mem_free(void *rmem)
#define LWIP_MEM_ALLOC_PROTECT()
#define LWIP_MEM_FREE_DECL_PROTECT()
#define LWIP_MEM_FREE_PROTECT()
#define SIZEOF_STRUCT_MEM
void sys_mutex_unlock(sys_mutex_t *mutex)
void sys_mutex_lock(sys_mutex_t *mutex)
void memp_free(memp_t type, void *mem)
#define MEM_STATS_AVAIL(x, y)
#define SYS_ARCH_DECL_PROTECT(lev)
void * mem_trim(void *rmem, mem_size_t newsize)
#define LWIP_MEM_ALLOC_DECL_PROTECT()
const struct memp_desc * memp_pools[MEMP_MAX]
void * mem_calloc(mem_size_t count, mem_size_t size)
#define LWIP_ASSERT(message, assertion)
#define LWIP_DBG_LEVEL_SEVERE
#define SYS_ARCH_PROTECT(lev)
#define LWIP_RAM_HEAP_POINTER
#define LWIP_MEM_ALIGN(addr)
#define SYS_ARCH_UNPROTECT(lev)
void * mem_malloc(mem_size_t size)
#define LWIP_MEM_ALIGN_SIZE(size)
#define MEM_STATS_INC_USED(x, y)
#define MEM_STATS_DEC_USED(x, y)
void * memp_malloc(memp_t type)
#define LWIP_MEM_ALLOC_UNPROTECT()
#define LWIP_DEBUGF(debug, message)
#define LWIP_MEM_FREE_UNPROTECT()
osSemaphoreId sys_mutex_t