mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-29 00:32:51 +00:00
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:
parent
811b237bd7
commit
b91e47b518
@ -640,7 +640,7 @@ nullreturn:
|
|||||||
|
|
||||||
#if IP_FRAG
|
#if IP_FRAG
|
||||||
#if IP_FRAG_USES_STATIC_BUF
|
#if IP_FRAG_USES_STATIC_BUF
|
||||||
static u8_t buf[LWIP_MEM_ALIGN_SIZE(IP_FRAG_MAX_MTU + MEM_ALIGNMENT - 1)];
|
static LWIP_DECLARE_MEMORY_ALIGNED(buf, IP_FRAG_MAX_MTU);
|
||||||
#else /* IP_FRAG_USES_STATIC_BUF */
|
#else /* IP_FRAG_USES_STATIC_BUF */
|
||||||
|
|
||||||
#if !LWIP_NETIF_TX_SINGLE_PBUF
|
#if !LWIP_NETIF_TX_SINGLE_PBUF
|
||||||
|
@ -202,7 +202,7 @@ struct mem {
|
|||||||
* how that space is calculated). */
|
* how that space is calculated). */
|
||||||
#ifndef LWIP_RAM_HEAP_POINTER
|
#ifndef LWIP_RAM_HEAP_POINTER
|
||||||
/** the heap. we need one struct mem at the end and some room for alignment */
|
/** the heap. we need one struct mem at the end and some room for alignment */
|
||||||
u8_t ram_heap[MEM_SIZE_ALIGNED + (2U*SIZEOF_STRUCT_MEM) + MEM_ALIGNMENT];
|
LWIP_DECLARE_MEMORY_ALIGNED(ram_heap, MEM_SIZE_ALIGNED + (2U*SIZEOF_STRUCT_MEM));
|
||||||
#define LWIP_RAM_HEAP_POINTER ram_heap
|
#define LWIP_RAM_HEAP_POINTER ram_heap
|
||||||
#endif /* LWIP_RAM_HEAP_POINTER */
|
#endif /* LWIP_RAM_HEAP_POINTER */
|
||||||
|
|
||||||
|
@ -110,6 +110,20 @@ typedef uintptr_t mem_ptr_t;
|
|||||||
#endif
|
#endif
|
||||||
#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
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -90,8 +90,8 @@ extern const struct memp_desc* const memp_pools[MEMP_MAX];
|
|||||||
|
|
||||||
#else /* MEMP_MEM_MALLOC */
|
#else /* MEMP_MEM_MALLOC */
|
||||||
|
|
||||||
#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) u8_t memp_memory_ ## name ## _base \
|
#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \
|
||||||
[((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size))) + (MEM_ALIGNMENT-1)]; \
|
LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); \
|
||||||
\
|
\
|
||||||
static struct memp *memp_tab_ ## name; \
|
static struct memp *memp_tab_ ## name; \
|
||||||
\
|
\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user