void-packages/srcpkgs/wrk/patches/zmalloc-arm-alignment.patch

52 lines
1.5 KiB
Diff

From fb6e30dad970865c6da254cc3ee62579e97805e5 Mon Sep 17 00:00:00 2001
From: Noel Cower <ncower@gmail.com>
Date: Mon, 19 Nov 2018 14:07:14 -0800
Subject: [PATCH] [PATCH] wrk: Fix zmalloc prefix alignment
Adjust zmalloc's prefix size so that whatever follows the prefix stays
8- or 16-byte aligned.
This mainly affects ARM systems where size_t is 4 bytes. That causes
data following the prefix to be misaligned by 4 bytes. The effect of
this is only noticeable when wrk performs an atomic increment on memory
allocated for its statistics. Since wrk uses uint64_t counters (8-byte
aligned), the counters end up being offset by 4 bytes. As a result, when
wrk uses a __sync_fetch_and_add on one of its counters, it raises
a SIGBUS.
This patch is based on <https://github.com/wg/wrk/pull/154>.
---
src/zmalloc.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/zmalloc.c b/src/zmalloc.c
index 094dd80..c4ca366 100644
--- a/src/zmalloc.c
+++ b/src/zmalloc.c
@@ -45,13 +45,20 @@ void zlibc_free(void *ptr) {
#include "zmalloc.h"
#include "atomicvar.h"
+#ifdef _LP64
+#define ALIGNMENT (16)
+#else
+#define ALIGNMENT (8)
+#endif
+#define ALIGN_SIZE(sz) (((sz) + (ALIGNMENT - 1)) & -ALIGNMENT)
+
#ifdef HAVE_MALLOC_SIZE
#define PREFIX_SIZE (0)
#else
#if defined(__sun) || defined(__sparc) || defined(__sparc__)
-#define PREFIX_SIZE (sizeof(long long))
+#define PREFIX_SIZE (ALIGN_SIZE(sizeof(long long)))
#else
-#define PREFIX_SIZE (sizeof(size_t))
+#define PREFIX_SIZE (ALIGN_SIZE(sizeof(size_t)))
#endif
#endif
--
2.19.1