Implement portable and overridable allocation of memory buffers

Fixes bug #48300 (Private mempools allocate foreign memory), bug #48354 (Portable alignment defines/include required for static allocation) and bug #47092 (Tag memory buffers like memp_memory_xxx and ram_heap with a macro so that attributes can be attached to their definitions)

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
This commit is contained in:
Dirk Ziegelmeier
2016-07-07 13:35:13 +02:00
parent 811b237bd7
commit b91e47b518
4 changed files with 18 additions and 4 deletions

View File

@@ -110,6 +110,20 @@ typedef uintptr_t mem_ptr_t;
#endif
#endif
/** Allocates a memory buffer of specified size that is of sufficient size to align
* its start address using LWIP_MEM_ALIGN.
* You can declare your own version here e.g. to enforce alignment without adding
* trailing padding bytes (see LWIP_MEM_ALIGN_BUFFER) or your own section placement
* requirements.
* e.g. if you use gcc and need 32 bit alignment:
* #define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4)))
* or more portable:
* #define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u32_t variable_name[(size + sizeof(u32_t) - 1) / sizeof(u32_t)]
*/
#ifndef LWIP_DECLARE_MEMORY_ALIGNED
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
#endif
#ifdef __cplusplus
extern "C" {
#endif

View File

@@ -90,8 +90,8 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX];
#else /* MEMP_MEM_MALLOC */
#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) u8_t memp_memory_ ## name ## _base \
[((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size))) + (MEM_ALIGNMENT-1)]; \
#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \
LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); \
\
static struct memp *memp_tab_ ## name; \
\