Hi,

pbuf_init() will not work unless pbuf_pool_memory[] is properly aligned.  
There's an ASSERT that it's aligned, but if it doesn't end
up aligned by random chance, you're screwed.  With my luck, I had ASSERTs 
turned off, and my CPU simulator corrupted the data
instead of taking an exception, so I was triply-screwed. :-) 

The fix is to add another (MEM_ALIGNMENT - 1) bytes to the pbuf_pool_memory[] 
size, then in pbuf_init() align the initial assignment
of pbuf_pool.  The assertion is no longer needed.  Since the diff below will 
probably get corrupted in the mail, I attached a
unified diff suitable for patch(1)'ing the current CVS HEAD revision.

Regards,
Curt McDowell
Broadcom Corp.

76c76,78
< static u8_t pbuf_pool_memory[(PBUF_POOL_SIZE * 
MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE + sizeof(struct pbuf)))];
---
> static u8_t pbuf_pool_memory[MEM_ALIGNMENT - 1 +
>                              PBUF_POOL_SIZE * 
> MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE +
>                                                              sizeof(struct 
> pbuf))];
103,104c105
<   pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0];
<   LWIP_ASSERT("pbuf_init: pool aligned", (mem_ptr_t)pbuf_pool % MEM_ALIGNMENT 
== 0);
---
>   pbuf_pool = (struct pbuf *)MEM_ALIGN(pbuf_pool_memory);
--- /home/csm/pbuf.c    Sun Feb 26 14:57:46 2006
+++ /home/csm/pbuf-new.c        Sun Feb 26 15:09:27 2006
@@ -73,7 +73,9 @@
 #include "lwip/sys.h"
 #include "arch/perf.h"
 
-static u8_t pbuf_pool_memory[(PBUF_POOL_SIZE * 
MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE + sizeof(struct pbuf)))];
+static u8_t pbuf_pool_memory[MEM_ALIGNMENT - 1 +
+                             PBUF_POOL_SIZE * MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE 
+
+                                                             sizeof(struct 
pbuf))];
 
 #if !SYS_LIGHTWEIGHT_PROT
 static volatile u8_t pbuf_pool_free_lock, pbuf_pool_alloc_lock;
@@ -100,8 +102,7 @@
   struct pbuf *p, *q = NULL;
   u16_t i;
 
-  pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0];
-  LWIP_ASSERT("pbuf_init: pool aligned", (mem_ptr_t)pbuf_pool % MEM_ALIGNMENT 
== 0);
+  pbuf_pool = (struct pbuf *)MEM_ALIGN(pbuf_pool_memory);
 
 #if PBUF_STATS
   lwip_stats.pbuf.avail = PBUF_POOL_SIZE;
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to