memp_malloc_pool_fn(const struct memp_desc *desc, const char* file, const int line) #endif { struct memp *memp; SYS_ARCH_DECL_PROTECT(old_level); SYS_ARCH_PROTECT(old_level); memp = *desc->tab; #if MEMP_OVERFLOW_CHECK == 1 memp_overflow_check_element_overflow(memp, desc); memp_overflow_check_element_underflow(memp, desc); #endif /* MEMP_OVERFLOW_CHECK */ if (memp != NULL) { *desc->tab = memp->next; #if MEMP_OVERFLOW_CHECK memp->next = NULL; memp->file = file; memp->line = line; #endif /* MEMP_OVERFLOW_CHECK */ LWIP_ASSERT("memp_malloc: memp properly aligned", ((mem_ptr_t)memp % MEM_ALIGNMENT) == 0); memp = (struct memp*)(void *)((u8_t*)memp + MEMP_SIZE); } SYS_ARCH_UNPROTECT(old_level); return memp; }
/** * Do an overflow check for all elements in every pool. * * @see memp_overflow_check_element for a description of the check */ static void memp_overflow_check_all(void) { u16_t i, j; struct memp *p; #if !MEMP_SEPARATE_POOLS p = (struct memp *)LWIP_MEM_ALIGN(memp_memory); #endif /* !MEMP_SEPARATE_POOLS */ for (i = 0; i < MEMP_MAX; ++i) { #if MEMP_SEPARATE_POOLS p = (struct memp *)(memp_bases[i]); #endif /* MEMP_SEPARATE_POOLS */ for (j = 0; j < memp_num[i]; ++j) { memp_overflow_check_element_overflow(p, i); p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED); } } #if !MEMP_SEPARATE_POOLS p = (struct memp *)LWIP_MEM_ALIGN(memp_memory); #endif /* !MEMP_SEPARATE_POOLS */ for (i = 0; i < MEMP_MAX; ++i) { #if MEMP_SEPARATE_POOLS p = (struct memp *)(memp_bases[i]); #endif /* MEMP_SEPARATE_POOLS */ for (j = 0; j < memp_num[i]; ++j) { memp_overflow_check_element_underflow(p, i); p = (struct memp*)((u8_t*)p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED); } } }
/** * Do an overflow check for all elements in every pool. * * @see memp_overflow_check_element for a description of the check */ static void memp_overflow_check_all(void) { uint16_t i, j; struct memp *p; p = (struct memp *)LWIP_MEM_ALIGN(memp_memory); for (i = 0; i < MEMP_MAX; ++i) { p = p; for (j = 0; j < memp_num[i]; ++j) { memp_overflow_check_element_overflow(p, i); p = (struct memp *)((u8_t *) p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED); } } p = (struct memp *)LWIP_MEM_ALIGN(memp_memory); for (i = 0; i < MEMP_MAX; ++i) { p = p; for (j = 0; j < memp_num[i]; ++j) { memp_overflow_check_element_underflow(p, i); p = (struct memp *)((u8_t *) p + MEMP_SIZE + memp_sizes[i] + MEMP_SANITY_REGION_AFTER_ALIGNED); } } }
do_memp_malloc_pool_fn(const struct memp_desc *desc, const char* file, const int line) #endif { struct memp *memp; SYS_ARCH_DECL_PROTECT(old_level); #if MEMP_MEM_MALLOC memp = (struct memp *)mem_malloc(MEMP_SIZE + MEMP_ALIGN_SIZE(desc->size)); SYS_ARCH_PROTECT(old_level); #else /* MEMP_MEM_MALLOC */ SYS_ARCH_PROTECT(old_level); memp = *desc->tab; #endif /* MEMP_MEM_MALLOC */ if (memp != NULL) { #if !MEMP_MEM_MALLOC #if MEMP_OVERFLOW_CHECK == 1 memp_overflow_check_element_overflow(memp, desc); memp_overflow_check_element_underflow(memp, desc); #endif /* MEMP_OVERFLOW_CHECK */ *desc->tab = memp->next; #if MEMP_OVERFLOW_CHECK memp->next = NULL; #endif /* MEMP_OVERFLOW_CHECK */ #endif /* !MEMP_MEM_MALLOC */ #if MEMP_OVERFLOW_CHECK memp->file = file; memp->line = line; #if MEMP_MEM_MALLOC memp_overflow_init_element(memp, desc); #endif /* MEMP_MEM_MALLOC */ #endif /* MEMP_OVERFLOW_CHECK */ LWIP_ASSERT("memp_malloc: memp properly aligned", ((mem_ptr_t)memp % MEM_ALIGNMENT) == 0); #if MEMP_STATS desc->stats->used++; if (desc->stats->used > desc->stats->max) { desc->stats->max = desc->stats->used; } #endif SYS_ARCH_UNPROTECT(old_level); /* cast through u8_t* to get rid of alignment warnings */ return ((u8_t*)memp + MEMP_SIZE); } else { LWIP_DEBUGF(MEMP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("memp_malloc: out of memory in pool %s\n", desc->desc)); #if MEMP_STATS desc->stats->err++; #endif } SYS_ARCH_UNPROTECT(old_level); return NULL; }
/** * Do an overflow check for all elements in every pool. * * @see memp_overflow_check_element for a description of the check */ static void memp_overflow_check_all(void) { u16_t i, j; struct memp *p; for (i = 0; i < MEMP_MAX; ++i) { p = (struct memp *)(size_t)(memp_pools[i]->base); for (j = 0; j < memp_pools[i]->num; ++j) { memp_overflow_check_element_overflow(p, memp_pools[i]); memp_overflow_check_element_underflow(p, memp_pools[i]); p = (struct memp*)(size_t)((u8_t*)p + MEMP_SIZE + memp_pools[i]->size + MEMP_SANITY_REGION_AFTER_ALIGNED); } } }
/** * Do an overflow check for all elements in every pool. * * @see memp_overflow_check_element for a description of the check */ static void memp_overflow_check_all(void) { u16_t i, j; struct memp *p; SYS_ARCH_DECL_PROTECT(old_level); SYS_ARCH_PROTECT(old_level); for (i = 0; i < MEMP_MAX; ++i) { p = (struct memp*)LWIP_MEM_ALIGN(memp_pools[i]->base); for (j = 0; j < memp_pools[i]->num; ++j) { memp_overflow_check_element_overflow(p, memp_pools[i]); memp_overflow_check_element_underflow(p, memp_pools[i]); p = LWIP_ALIGNMENT_CAST(struct memp*, ((u8_t*)p + MEMP_SIZE + memp_pools[i]->size + MEMP_SANITY_REGION_AFTER_ALIGNED)); } } SYS_ARCH_UNPROTECT(old_level); }