From 698837e7150af19ff6a3f0bf2144dffc81202a55 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Mon, 9 Mar 2020 08:02:22 -0700 Subject: 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. --- sys/src/ape/lib/ap/plan9/malloc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'sys/src/ape/lib/ap/plan9') diff --git a/sys/src/ape/lib/ap/plan9/malloc.c b/sys/src/ape/lib/ap/plan9/malloc.c index 2bfa176fc..4f828a033 100644 --- a/sys/src/ape/lib/ap/plan9/malloc.c +++ b/sys/src/ape/lib/ap/plan9/malloc.c @@ -11,13 +11,22 @@ enum 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]; }; -- cgit v1.2.3