git: 9front

Download patch

ref: 66c512248c5cda63b04e2c74e35d5711756b180f
parent: 5487c4119cec517c5cc6039eb1f6f670f4a7c846
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Mar 9 04:02:22 EDT 2020

fix alignment in ape malloc

We used to have a padding int in the structure
after the next pointer, to align it to 16 bytes.
On 64 bit architectures, the pointer was already
8 bits, so the padding misaligned things to 20
bytes.

This fixes it so that we're explcit about the
data alignment we want, instead of hoping that
the various sizes line up.

--- a/sys/src/ape/lib/ap/plan9/malloc.c
+++ b/sys/src/ape/lib/ap/plan9/malloc.c
@@ -11,13 +11,22 @@
 	CUTOFF		= 12,
 };
 
+#define NPAD(t, align) \
+	((sizeof(t) + align - 1) & ~(align - 1))
 typedef struct Bucket Bucket;
-struct Bucket
-{
+typedef struct Header Header;
+struct Header {
 	int	size;
 	int	magic;
 	Bucket	*next;
-	int	pad;
+};
+
+struct Bucket
+{
+	union {
+		Header;
+		char _pad[NPAD(Header, 16)];
+	};
 	char	data[1];
 };
 
--