[Freeswitch-dev] Freeswitch on ARM, Memory alignment issues

Michael Jerris mike at jerris.com
Tue Jan 18 20:54:53 MSK 2011


take a look at swith_types.h 645-710.  This is what you would need to do cross platform to align stuff.  I am surprised the first way isn't aligned already, the first proposed change wont be cross platform, the second, if that works, should be fine (as long as you free it later of course) but I am unsure if that will actually work cross platform.  The trick here is to figure out how to fix it once for all platforms.

Mike


On Jan 18, 2011, at 12:35 PM, M D wrote:

> Summary:
> Has anyone looked at/actively looking at the 32-bit boundary memory
> alignment requirement for the ARM architecture?
> 
> Detail:
> I am running freeswitch on an ARM platform (dockstar based on Marvell
> Kirkwood). I have compiled and tested both freeswitch-1.0.6 and
> freeswitch-head(1,2), and found that stun lookups were failing with a
> "Timeout" error. Debugging the issue points to memory alignment issues
> specific to the ARM architecture. Basically, due to the fact that the
> uint8_t array "buf", is not aligned at a 32-bit memory boundary, the
> stun lookup packet sent to the stun server was malformed. Web searches
> confirm that a symptom of misaligned access on ARM is an apparent
> memory corruption.
> 
> This can be fixed by forcing alignment of specific variables to 32-bit
> boundary. As an example, in the switch_stun_lookup function of file
> src/switch_stun.c , we currently have
> 
> {
> 	switch_sockaddr_t *local_addr = NULL, *remote_addr = NULL,
> *from_addr = NULL;
> 	switch_socket_t *sock = NULL;
> 	uint8_t buf[260] = { 0 };
> 	....
> }
> 
> If I change it to
> {
> 	switch_sockaddr_t *local_addr = NULL, *remote_addr = NULL,
> *from_addr = NULL;
> 	switch_socket_t *sock = NULL;
> 	uint8_t buf[260] __attribute__ (aligned(4)) = { 0 };
> 	....
> }
> 
> or
> {
> 	switch_sockaddr_t *local_addr = NULL, *remote_addr = NULL,
> *from_addr = NULL;
> 	switch_socket_t *sock = NULL;
> 	uint8_t *buf;
> 	buf = (uint8_t*) malloc(sizeof(uint8_t)*260);
> 	....
> }
> 
> the stun lookup packet sent is correct.freeswitch is also able to parse
> the recvd packet and correctly determines the external IP.
> 
> Random crashes coupled with looking at the code in switch_rtp suggests
> that the memory alignment issue may not be limited to this function or
> even this file. Has anyone looked at ARM memory alignment issues for
> freeswitch in general?
> 
> cheers,
> -m
> 
> (1) Current head leads to the situation where call gets
> connected but there is no-audio. I have not had the chance to
> debug this, but suspect this could be due to the "eat rtp .... " patch
> combined with ARM memory alignment issues.
> 
> (2) The tested (audio working, some issues) git version is
> commit 715d250e171a94736b19019ac742f739899ad997
> Author: Mathieu Parent <math.parent at gmail.com>
> Date:   Wed Dec 15 21:29:52 2010 +0100
> 
> _______________________________________________
> FreeSWITCH-dev mailing list
> FreeSWITCH-dev at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev
> http://www.freeswitch.org




More information about the FreeSWITCH-dev mailing list