opt.h, mem.h, mem.c, memp.c, pbuf.c, ip_frag.c, vj.c: Fix bug #20162. Rename MEM_ALIGN in LWIP_MEM_ALIGN and MEM_ALIGN_SIZE in LWIP_MEM_ALIGN_SIZE to avoid some macro names collision with some OS macros.

This commit is contained in:
fbernon 2007-06-13 17:17:26 +00:00
parent 5f7831b3c8
commit bdbc96f453
8 changed files with 34 additions and 29 deletions

View File

@ -199,6 +199,11 @@ HISTORY
++ Bug fixes: ++ Bug fixes:
2007-06-13 Frédéric Bernon, Matthias Weisser
* opt.h, mem.h, mem.c, memp.c, pbuf.c, ip_frag.c, vj.c: Fix bug #20162. Rename
MEM_ALIGN in LWIP_MEM_ALIGN and MEM_ALIGN_SIZE in LWIP_MEM_ALIGN_SIZE to avoid
some macro names collision with some OS macros.
2007-06-11 Simon Goldschmidt 2007-06-11 Simon Goldschmidt
* udp.c: UDP Lite: corrected the use of chksum_len (based on RFC3828: if it's 0, * udp.c: UDP Lite: corrected the use of chksum_len (based on RFC3828: if it's 0,
create checksum over the complete packet. On RX, if it's < 8 (and not 0), create checksum over the complete packet. On RX, if it's < 8 (and not 0),

View File

@ -311,7 +311,7 @@ nullreturn:
#if IP_FRAG #if IP_FRAG
#if IP_FRAG_USES_STATIC_BUF #if IP_FRAG_USES_STATIC_BUF
static u8_t buf[MEM_ALIGN_SIZE(IP_FRAG_MAX_MTU)]; static u8_t buf[LWIP_MEM_ALIGN_SIZE(IP_FRAG_MAX_MTU)];
#endif /* IP_FRAG_USES_STATIC_BUF */ #endif /* IP_FRAG_USES_STATIC_BUF */
/** /**
@ -361,7 +361,7 @@ ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest)
return ERR_MEM; return ERR_MEM;
} }
rambuf->tot_len = rambuf->len = mtu; rambuf->tot_len = rambuf->len = mtu;
rambuf->payload = MEM_ALIGN((void *)buf); rambuf->payload = LWIP_MEM_ALIGN((void *)buf);
/* Copy the IP header in it */ /* Copy the IP header in it */
iphdr = rambuf->payload; iphdr = rambuf->payload;

View File

@ -66,9 +66,9 @@ struct mem {
#ifndef MIN_SIZE #ifndef MIN_SIZE
#define MIN_SIZE 12 #define MIN_SIZE 12
#endif /* MIN_SIZE */ #endif /* MIN_SIZE */
#define MIN_SIZE_ALIGNED MEM_ALIGN_SIZE(MIN_SIZE) #define MIN_SIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(MIN_SIZE)
#define SIZEOF_STRUCT_MEM MEM_ALIGN_SIZE(sizeof(struct mem)) #define SIZEOF_STRUCT_MEM LWIP_MEM_ALIGN_SIZE(sizeof(struct mem))
#define MEM_SIZE_ALIGNED MEM_ALIGN_SIZE(MEM_SIZE) #define MEM_SIZE_ALIGNED LWIP_MEM_ALIGN_SIZE(MEM_SIZE)
static struct mem *ram_end; static struct mem *ram_end;
/* 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 */
@ -136,7 +136,7 @@ mem_init(void)
/* align the heap */ /* align the heap */
memset(ram_heap, 0, sizeof(ram_heap)); memset(ram_heap, 0, sizeof(ram_heap));
ram = MEM_ALIGN(ram_heap); ram = LWIP_MEM_ALIGN(ram_heap);
/* initialize the start of the heap */ /* initialize the start of the heap */
mem = (struct mem *)ram; mem = (struct mem *)ram;
mem->next = MEM_SIZE_ALIGNED; mem->next = MEM_SIZE_ALIGNED;
@ -221,7 +221,7 @@ mem_realloc(void *rmem, mem_size_t newsize)
/* Expand the size of the allocated memory region so that we can /* Expand the size of the allocated memory region so that we can
adjust for alignment. */ adjust for alignment. */
newsize = MEM_ALIGN_SIZE(newsize); newsize = LWIP_MEM_ALIGN_SIZE(newsize);
if(newsize < MIN_SIZE_ALIGNED) { if(newsize < MIN_SIZE_ALIGNED) {
/* every data block must be at least MIN_SIZE_ALIGNED long */ /* every data block must be at least MIN_SIZE_ALIGNED long */
@ -334,7 +334,7 @@ mem_malloc(mem_size_t size)
/* Expand the size of the allocated memory region so that we can /* Expand the size of the allocated memory region so that we can
adjust for alignment. */ adjust for alignment. */
size = MEM_ALIGN_SIZE(size); size = LWIP_MEM_ALIGN_SIZE(size);
if(size < MIN_SIZE_ALIGNED) { if(size < MIN_SIZE_ALIGNED) {
/* every data block must be at least MIN_SIZE_ALIGNED long */ /* every data block must be at least MIN_SIZE_ALIGNED long */

View File

@ -71,7 +71,7 @@ static struct memp *memp_tab[MEMP_MAX];
#define MEMP_SANITY_REGION_BEFORE 16 #define MEMP_SANITY_REGION_BEFORE 16
#endif /* MEMP_SANITY_REGION_BEFORE*/ #endif /* MEMP_SANITY_REGION_BEFORE*/
#if MEMP_SANITY_REGION_BEFORE > 0 #if MEMP_SANITY_REGION_BEFORE > 0
#define MEMP_SANITY_REGION_BEFORE_ALIGNED MEM_ALIGN_SIZE(MEMP_SANITY_REGION_BEFORE) #define MEMP_SANITY_REGION_BEFORE_ALIGNED LWIP_MEM_ALIGN_SIZE(MEMP_SANITY_REGION_BEFORE)
#else #else
#define MEMP_SANITY_REGION_BEFORE_ALIGNED 0 #define MEMP_SANITY_REGION_BEFORE_ALIGNED 0
#endif /* MEMP_SANITY_REGION_BEFORE*/ #endif /* MEMP_SANITY_REGION_BEFORE*/
@ -79,14 +79,14 @@ static struct memp *memp_tab[MEMP_MAX];
#define MEMP_SANITY_REGION_AFTER 16 #define MEMP_SANITY_REGION_AFTER 16
#endif /* MEMP_SANITY_REGION_AFTER*/ #endif /* MEMP_SANITY_REGION_AFTER*/
#if MEMP_SANITY_REGION_AFTER > 0 #if MEMP_SANITY_REGION_AFTER > 0
#define MEMP_SANITY_REGION_AFTER_ALIGNED MEM_ALIGN_SIZE(MEMP_SANITY_REGION_AFTER) #define MEMP_SANITY_REGION_AFTER_ALIGNED LWIP_MEM_ALIGN_SIZE(MEMP_SANITY_REGION_AFTER)
#else #else
#define MEMP_SANITY_REGION_AFTER_ALIGNED 0 #define MEMP_SANITY_REGION_AFTER_ALIGNED 0
#endif /* MEMP_SANITY_REGION_AFTER*/ #endif /* MEMP_SANITY_REGION_AFTER*/
/* MEMP_SIZE: save space for struct memp and for sanity check */ /* MEMP_SIZE: save space for struct memp and for sanity check */
#define MEMP_SIZE (MEM_ALIGN_SIZE(sizeof(struct memp)) + MEMP_SANITY_REGION_BEFORE_ALIGNED) #define MEMP_SIZE (LWIP_MEM_ALIGN_SIZE(sizeof(struct memp)) + MEMP_SANITY_REGION_BEFORE_ALIGNED)
#define MEMP_ALIGN_SIZE(x) (MEM_ALIGN_SIZE(x) + MEMP_SANITY_REGION_AFTER_ALIGNED) #define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x) + MEMP_SANITY_REGION_AFTER_ALIGNED)
#else /* MEMP_OVERFLOW_CHECK */ #else /* MEMP_OVERFLOW_CHECK */
@ -95,7 +95,7 @@ static struct memp *memp_tab[MEMP_MAX];
* can save a little space and set MEMP_SIZE to 0. * can save a little space and set MEMP_SIZE to 0.
*/ */
#define MEMP_SIZE 0 #define MEMP_SIZE 0
#define MEMP_ALIGN_SIZE(x) (MEM_ALIGN_SIZE(x)) #define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x))
#endif /* MEMP_OVERFLOW_CHECK */ #endif /* MEMP_OVERFLOW_CHECK */
@ -217,7 +217,7 @@ memp_overflow_check_all(void)
u16_t i, j; u16_t i, j;
struct memp *p; struct memp *p;
p = MEM_ALIGN(memp_memory); p = LWIP_MEM_ALIGN(memp_memory);
for (i = 0; i < MEMP_MAX; ++i) { for (i = 0; i < MEMP_MAX; ++i) {
p = p; p = p;
for (j = 0; j < memp_num[i]; ++j) { for (j = 0; j < memp_num[i]; ++j) {
@ -236,7 +236,7 @@ memp_overflow_init(void)
struct memp *p; struct memp *p;
u8_t *m; u8_t *m;
p = MEM_ALIGN(memp_memory); p = LWIP_MEM_ALIGN(memp_memory);
for (i = 0; i < MEMP_MAX; ++i) { for (i = 0; i < MEMP_MAX; ++i) {
p = p; p = p;
for (j = 0; j < memp_num[i]; ++j) { for (j = 0; j < memp_num[i]; ++j) {
@ -271,7 +271,7 @@ memp_init(void)
} }
#endif /* MEMP_STATS */ #endif /* MEMP_STATS */
memp = MEM_ALIGN(memp_memory); memp = LWIP_MEM_ALIGN(memp_memory);
/* for every pool: */ /* for every pool: */
for (i = 0; i < MEMP_MAX; ++i) { for (i = 0; i < MEMP_MAX; ++i) {
memp_tab[i] = NULL; memp_tab[i] = NULL;

View File

@ -72,7 +72,7 @@
#include "lwip/sys.h" #include "lwip/sys.h"
#include "arch/perf.h" #include "arch/perf.h"
#define SIZEOF_STRUCT_PBUF MEM_ALIGN_SIZE(sizeof(struct pbuf)) #define SIZEOF_STRUCT_PBUF LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf))
/** /**
* Initializes the pbuf module. * Initializes the pbuf module.
@ -158,13 +158,13 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
p->next = NULL; p->next = NULL;
/* make the payload pointer point 'offset' bytes into pbuf data memory */ /* make the payload pointer point 'offset' bytes into pbuf data memory */
p->payload = MEM_ALIGN((void *)((u8_t *)p + (SIZEOF_STRUCT_PBUF + offset))); p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + (SIZEOF_STRUCT_PBUF + offset)));
LWIP_ASSERT("pbuf_alloc: pbuf p->payload properly aligned", LWIP_ASSERT("pbuf_alloc: pbuf p->payload properly aligned",
((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0); ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
/* the total length of the pbuf chain is the requested size */ /* the total length of the pbuf chain is the requested size */
p->tot_len = length; p->tot_len = length;
/* set the length of the first pbuf in the chain */ /* set the length of the first pbuf in the chain */
p->len = length > PBUF_POOL_BUFSIZE - MEM_ALIGN_SIZE(offset)? PBUF_POOL_BUFSIZE - MEM_ALIGN_SIZE(offset): length; p->len = length > PBUF_POOL_BUFSIZE - LWIP_MEM_ALIGN_SIZE(offset)? PBUF_POOL_BUFSIZE - LWIP_MEM_ALIGN_SIZE(offset): length;
LWIP_ASSERT("check p->payload + p->len does not overflow pbuf", LWIP_ASSERT("check p->payload + p->len does not overflow pbuf",
((u8_t*)p->payload + p->len <= ((u8_t*)p->payload + p->len <=
(u8_t*)p + SIZEOF_STRUCT_PBUF + PBUF_POOL_BUFSIZE)); (u8_t*)p + SIZEOF_STRUCT_PBUF + PBUF_POOL_BUFSIZE));
@ -213,12 +213,12 @@ pbuf_alloc(pbuf_layer l, u16_t length, pbuf_flag flag)
break; break;
case PBUF_RAM: case PBUF_RAM:
/* If pbuf is to be allocated in RAM, allocate memory for it. */ /* If pbuf is to be allocated in RAM, allocate memory for it. */
p = mem_malloc(MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF + offset) + MEM_ALIGN_SIZE(length)); p = mem_malloc(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF + offset) + LWIP_MEM_ALIGN_SIZE(length));
if (p == NULL) { if (p == NULL) {
return NULL; return NULL;
} }
/* Set up internal structure of the pbuf. */ /* Set up internal structure of the pbuf. */
p->payload = MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset)); p->payload = LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset));
p->len = p->tot_len = length; p->len = p->tot_len = length;
p->next = NULL; p->next = NULL;
p->flags = PBUF_FLAG_RAM; p->flags = PBUF_FLAG_RAM;

View File

@ -67,18 +67,18 @@ typedef u16_t mem_size_t;
#endif #endif
#else /* MEM_LIBC_MALLOC */ #else /* MEM_LIBC_MALLOC */
/* lwIP alternative malloc */ /* lwIP alternative malloc */
void mem_init(void); void mem_init(void);
void *mem_malloc(mem_size_t size); void *mem_malloc(mem_size_t size);
void mem_free(void *mem); void mem_free(void *mem);
void *mem_realloc(void *mem, mem_size_t size); void *mem_realloc(void *mem, mem_size_t size);
#endif /* MEM_LIBC_MALLOC */ #endif /* MEM_LIBC_MALLOC */
#ifndef MEM_ALIGN_SIZE #ifndef LWIP_MEM_ALIGN_SIZE
#define MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1)) #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))
#endif #endif
#ifndef MEM_ALIGN #ifndef LWIP_MEM_ALIGN
#define MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1))) #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -426,7 +426,7 @@ a lot of data that needs to be copied, this should be set high. */
#ifndef PBUF_POOL_BUFSIZE #ifndef PBUF_POOL_BUFSIZE
/* Default designed to accomodate single full size TCP frame in one PBUF */ /* Default designed to accomodate single full size TCP frame in one PBUF */
/* TCP_MSS + 40 for IP and TCP headers + physical layer headers */ /* TCP_MSS + 40 for IP and TCP headers + physical layer headers */
#define PBUF_POOL_BUFSIZE MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN) #define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN)
#endif #endif

View File

@ -586,7 +586,7 @@ int vj_uncompress_tcp(
} }
if(MEM_ALIGN(n0->payload) != n0->payload) { if(LWIP_MEM_ALIGN(n0->payload) != n0->payload) {
struct pbuf *np, *q; struct pbuf *np, *q;
u8_t *bufptr; u8_t *bufptr;