summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Markelov <sergey@solidstatenetworks.com>2021-07-22 10:23:26 -0700
committerHans Kristian Rosbach <hk-github@circlestorm.org>2021-12-24 12:52:14 +0100
commitcdc8033a45ff2276676e434a0b22a4230a28071a (patch)
tree145e72e22ce569170f447909c0c6a67556306c63
parent5bbf9ef0dae79f912a5fcfca8eab32c8df02f592 (diff)
Fix hangs on macOS due to loading of misaligned addresses in chunkmemset_8.
-rw-r--r--chunkset_tpl.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/chunkset_tpl.h b/chunkset_tpl.h
index ff760fc..be52ee9 100644
--- a/chunkset_tpl.h
+++ b/chunkset_tpl.h
@@ -114,10 +114,10 @@ Z_INTERNAL uint8_t* CHUNKMEMSET(uint8_t *out, unsigned dist, unsigned len) {
chunk_t chunk;
unsigned sz = sizeof(chunk);
if (len < sz) {
- do {
+ while (len != 0) {
*out++ = *from++;
--len;
- } while (len != 0);
+ }
return out;
}
@@ -176,9 +176,24 @@ Z_INTERNAL uint8_t* CHUNKMEMSET(uint8_t *out, unsigned dist, unsigned len) {
}
Z_INTERNAL uint8_t* CHUNKMEMSET_SAFE(uint8_t *out, unsigned dist, unsigned len, unsigned left) {
+#if !defined(UNALIGNED64_OK)
+# if !defined(UNALIGNED_OK)
+ static const uint32_t align_mask = 7;
+# else
+ static const uint32_t align_mask = 3;
+# endif
+#endif
+
len = MIN(len, left);
+ uint8_t *from = out - dist;
+#if !defined(UNALIGNED64_OK)
+ while (((uintptr_t)out & align_mask) && (len > 0)) {
+ *out++ = *from++;
+ --len;
+ --left;
+ }
+#endif
if (left < (unsigned)(3 * sizeof(chunk_t))) {
- uint8_t *from = out - dist;
while (len > 0) {
*out++ = *from++;
--len;