lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-devel] Purpose of memory alignment check


From: Simon Goldschmidt
Subject: Re: [lwip-devel] Purpose of memory alignment check
Date: Tue, 13 Mar 2012 13:01:33 +0100

"Boštjan Meglič" <address@hidden> wrote:
> In the lwip code src/api/sockets.c, line 117, what is the use of the 
> following macro? Why should the name be aligned?
> #define IS_SOCK_ADDR_ALIGNED(name)      ((((mem_ptr_t)(name)) % 4) == 0)

Because 'struct sockaddr' is only used as a 'base class' for the socket API: 
you'll never instantiate a 'struct sockaddr': instead, you'll declare your 
address variables as 'struct sockaddr_in' (or 'struct sockaddr_in6' ofr IPv6) 
and cast them to 'struct sockaddr*' when passing to socket functions.

The problem here is that 'struct sockaddr' consists of u8_t members only, while 
'struct sockaddr_in' includes u32_t members. On most platforms, this results in 
'struct sockaddr' having no alignment requirement while 'struct sockaddr_in' 
has an alignment requirement of 4. That's why we check that the address is 
aligned.

There are however some platforms (like Intel, for example) which can access 
unaligned pointers, so this might work for you...

> On our system (Texas Instruments DSP 5509) the code fails *sometimes* on 
> [..]
> My question is, could there be a problem later on if I remove the memory 
> alignment check?

I can't help you there, since I don't know that platform.

Simon
-- 
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                          
        
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a



reply via email to

[Prev in Thread] Current Thread [Next in Thread]