From aaf6948ae799c50cfd74343ae482fd2d16b3ce6b Mon Sep 17 00:00:00 2001 From: "Fabio M. Di Nitto" Date: Sun, 22 Mar 2009 18:35:06 +0000 Subject: [PATCH] Fix 64bit alignment issue in totempg git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1889 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/totempg.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/exec/totempg.c b/exec/totempg.c index a53f6f2e..1e372101 100644 --- a/exec/totempg.c +++ b/exec/totempg.c @@ -343,13 +343,30 @@ static inline void group_endian_convert ( { unsigned short *group_len; int i; + struct iovec iovec_aligned = { NULL, 0 }; + struct iovec *iovec_swab; - group_len = (unsigned short *)iovec->iov_base; + /* + * Align data structure for sparc and ia64 + */ + if ((size_t)iovec->iov_base % 4 != 0) { + iovec_aligned.iov_base = alloca(iovec->iov_len); + memcpy(iovec_aligned.iov_base, iovec->iov_base, iovec->iov_len); + iovec_aligned.iov_len = iovec->iov_len; + iovec_swab = &iovec_aligned; + } else { + iovec_swab = iovec; + } + + group_len = (unsigned short *)iovec_swab->iov_base; group_len[0] = swab16(group_len[0]); for (i = 1; i < group_len[0] + 1; i++) { group_len[i] = swab16(group_len[i]); } + if (iovec_swab == &iovec_aligned) { + memcpy(iovec->iov_base, iovec_aligned.iov_base, iovec->iov_len); + } } static inline int group_matches ( @@ -372,7 +389,8 @@ static inline int group_matches ( */ if ((size_t)iovec->iov_base % 4 != 0) { iovec_aligned.iov_base = alloca(iovec->iov_len); - memcpy(iovec_aligned.iov_base, iovec->iov_base, iovec->iov_len); iovec_aligned.iov_len = iovec->iov_len; + memcpy(iovec_aligned.iov_base, iovec->iov_base, iovec->iov_len); + iovec_aligned.iov_len = iovec->iov_len; iovec = &iovec_aligned; }