From 569378eb1a3be23cdb45ac5d39e354683a7748f8 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Mon, 8 May 2017 10:10:22 +0200 Subject: [PATCH] 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 --- common.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 */ \ -- 2.40.0