code: purgatorio

Download patch

ref: 8294be6e7c9032e3c472018b53154d5b4faec00c
parent: d09cf07a82cf4ffb846a31d0384e774b4c4661e1
author: henesy <devnull@localhost>
date: Sat Feb 29 19:23:23 EST 2020

merge bea7f0cc7c9cdd883340c80697abc0be028bf944

--- a/emu/port/alloc.c
+++ b/emu/port/alloc.c
@@ -75,11 +75,7 @@
 
 /* tracing */
 enum {
-#ifdef __NetBSD__
-	Npadlong	= 4,	/* XXX: preserve 16-byte alignment */
-#else
 	Npadlong	= 2,
-#endif
 	MallocOffset = 0,
 	ReallocOffset = 1
 };
@@ -383,9 +379,22 @@
 		unlock(&p->l);
 		return nil;
 	}
+#ifdef __NetBSD__
+	/* Align allocations to 16 bytes */
+	{
+		const size_t off = __builtin_offsetof(struct Bhdr, u.data)
+					+ Npadlong*sizeof(ulong);
+		struct assert_align {
+			unsigned int align_ok : (off % 8 == 0) ? 1 : -1;
+		};
+
+		const ulong align = (off - 1) % 16;
+		t = (Bhdr *)(((ulong)t + align) & ~align);
+	}
+#else
 	/* Double alignment */
 	t = (Bhdr *)(((ulong)t + 7) & ~7);
-
+#endif
 	if(p->chain != nil && (char*)t-(char*)B2LIMIT(p->chain)-ldr == 0){
 		/* can merge chains */
 		if(0)print("merging chains %p and %p in %s\n", p->chain, t, p->name);