From: Sebastien GODARD Date: Mon, 8 May 2017 08:10:22 +0000 (+0200) Subject: Fix #148: ARM: sadc crashes because of unaligned memory accesses X-Git-Tag: v11.5.6~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=569378e;p=sysstat Fix #148: ARM: sadc crashes because of unaligned memory accesses Use posix_memalign() with 16 bytes alignment request instead of realloc() to guarantee 16 byte alignment requested by several sysstat's structures. Note: 16 byte alignment is no longer needed by sysstat's structures. Yet removing the corresponding attributes (__attribute__ ((aligned (16)))) for example in rd_stats.h would imply a format change for sar/sadc binary data files. These attributes will be removed when work is done to make sa binary datafiles portable (see #135). Signed-off-by: Sebastien GODARD --- diff --git a/common.h b/common.h index 70736f7..aeacc9c 100644 --- a/common.h +++ b/common.h @@ -11,6 +11,7 @@ #include #include /* For __CPU_SETSIZE */ +#include #include #ifdef HAVE_SYS_SYSMACROS_H @@ -114,17 +115,22 @@ /* Allocate and init structure */ #define SREALLOC(S, TYPE, SIZE) do { \ - TYPE *_p_; \ - _p_ = S; \ + TYPE *_p_ = S; \ if (SIZE) { \ - if ((S = (TYPE *) realloc(S, (SIZE))) == NULL) { \ + void *_ptr = NULL; \ + int error = posix_memalign(&_ptr, 16, (SIZE)); \ + if (error || (_ptr == NULL)) { \ perror("realloc"); \ exit(4); \ } \ + S = (TYPE *)_ptr; \ /* If the ptr was null, then it's a malloc() */ \ if (!_p_) { \ memset(S, 0, (SIZE)); \ } \ + else { \ + memcpy(S, _p_, (SIZE)); \ + } \ } \ if (!S) { \ /* Should never happen */ \