[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Possible alignment bug in 1.4.0?
From: |
Mason |
Subject: |
Re: [lwip-users] Possible alignment bug in 1.4.0? |
Date: |
Tue, 06 Mar 2012 10:02:07 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Firefox/10.0.2 SeaMonkey/2.7.2 |
Krzysztof Wesołowski wrote:
> I have encountered some HardFaults in rcurrent 1.4.0 version, file
> etharp.c code, line 416.
>
> code (stripped from asserts):
> static err_t
> etharp_send_ip(struct netif *netif, struct pbuf *p, struct eth_addr
> *src, struct eth_addr *dst)
> {
> struct eth_hdr *ethhdr = (struct eth_hdr *)p->payload;
> ETHADDR32_COPY(ðhdr->dest, dst);
> ETHADDR16_COPY(ðhdr->src, src);
>
> ethhdr->type = PP_HTONS(ETHTYPE_IP);
> return netif->linkoutput(netif, p);
> }
>
> Assumes that ðhdr->dest is 32bit aligned, which is true only for
> ETH_PAD_SIZE==0.
Did you define your own ETHADDR32_COPY macro?
Or your own SMEMCPY macro?
(memcpy is required to work for any alignment.)
/** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
* or known to be 32-bit aligned within the protocol header. */
#ifndef ETHADDR32_COPY
#define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
#endif
/** MEMCPY-like macro to copy to/from struct eth_addr's that are no local
* variables and known to be 16-bit aligned within the protocol header. */
#ifndef ETHADDR16_COPY
#define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN)
#endif
/**
* SMEMCPY: override this with care! Some compilers (e.g. gcc) can inline a
* call to memcpy() if the length is known at compile time and is small.
*/
#ifndef SMEMCPY
#define SMEMCPY(dst,src,len) memcpy(dst,src,len)
#endif
In principle, you're right. If one defines ETH_PAD_SIZE to 2
to align the IP header to 32 bits, then the first field of the
Ethernet header (MAC dest) cannot be aligned to 32 bits.
--
Regards.