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

M D nospametor at gmail.com
Tue Jan 18 20:35:15 MSK 2011


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



More information about the FreeSWITCH-dev mailing list