From dc2bdc2a21886791451239fd5e31fe8f75deb1ef Mon Sep 17 00:00:00 2001 From: David Girault Date: Mon, 29 May 2017 11:41:11 +0200 Subject: [PATCH] memp: allow initialization of pool memory if not in standard section --- src/core/memp.c | 8 ++++++++ src/include/lwip/opt.h | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/core/memp.c b/src/core/memp.c index 799ed51b..09c84f5c 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -239,6 +239,14 @@ memp_init_pool(const struct memp_desc *desc) *desc->tab = NULL; memp = (struct memp*)LWIP_MEM_ALIGN(desc->base); +#if MEMP_MEM_INIT + /* force memset on pool memory */ + memset(memp, 0, (size_t)desc->num * (MEMP_SIZE + desc->size +#if MEMP_OVERFLOW_CHECK + + MEMP_SANITY_REGION_AFTER_ALIGNED +#endif + )); +#endif /* create a linked list of memp elements */ for (i = 0; i < desc->num; ++i) { memp->next = *desc->tab; diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 8ee4f3b7..db2322b6 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -248,6 +248,15 @@ #define MEMP_MEM_MALLOC 0 #endif +/** + * MEMP_MEM_INIT==1: Force use of memset to initialize pool memory. + * Useful if pool are moved in uninitialized section of memory. This will ensure + * default values in pcbs struct are well initialized in all conditions. + */ +#if !defined MEMP_MEM_INIT || defined __DOXYGEN__ +#define MEMP_MEM_INIT 0 +#endif + /** * MEM_ALIGNMENT: should be set to the alignment of the CPU * 4 byte alignment -> \#define MEM_ALIGNMENT 4