summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzbb <zbb@FreeBSD.org>2015-02-24 12:57:03 +0000
committerzbb <zbb@FreeBSD.org>2015-02-24 12:57:03 +0000
commit6cc0e8d2a0b583db5707f811d4ebfbe1ad05e628 (patch)
tree0c8aff92f52d94da50d8d78d54137279d43bda0f
parent952715891bd9fb9d9a730ae9c0cc0a7b4618dfb0 (diff)
downloadFreeBSD-src-6cc0e8d2a0b583db5707f811d4ebfbe1ad05e628.zip
FreeBSD-src-6cc0e8d2a0b583db5707f811d4ebfbe1ad05e628.tar.gz
Change struct attribute to avoid aligned operations mismatch
Previous __alignment(4) allowed compiler to assume that operations are performed on aligned region. On ARM processor, this led to alignment fault as shown below: trapframe: 0xda9e5b10 FSR=00000001, FAR=a67b680e, spsr=60000113 r0 =00000000, r1 =00000068, r2 =0000007c, r3 =00000000 r4 =a67b6826, r5 =a67b680e, r6 =00000014, r7 =00000068 r8 =00000068, r9 =da9e5bd0, r10=00000011, r11=da9e5c10 r12=da9e5be0, ssp=da9e5b60, slr=a054f164, pc =a054f2cc <...> udp_input+0x264: ldmia r5, {r0-r3, r6} udp_input+0x268: stmia r12, {r0-r3, r6} This was due to instructions which do not support unaligned access, whereas for __alignment(2) compiler replaced ldmia/stmia with some logically equivalent memcpy operations. In fact, the assumption that 'struct ip' is always 4-byte aligned is definitely false, as we have no impact on data alignment of packet stream received. Another possible solution would be to explicitely perform memcpy() on objects of 'struct ip' type, which, however, would suffer from performance drop, and be merely a problem hiding. Please, note that this has nothing to do with ARM32_DISABLE_ALIGNMENT_FAULTS option, but is related strictly to compiler behaviour. Submitted by: Wojciech Macek <wma@semihalf.com> Reviewed by: glebius, ian Obtained from: Semihalf
-rw-r--r--sys/netinet/ip.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/sys/netinet/ip.h b/sys/netinet/ip.h
index 79afeb8..8487037 100644
--- a/sys/netinet/ip.h
+++ b/sys/netinet/ip.h
@@ -67,7 +67,7 @@ struct ip {
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
-} __packed __aligned(4);
+} __packed __aligned(2);
#define IP_MAXPACKET 65535 /* maximum packet size */
OpenPOWER on IntegriCloud