summaryrefslogtreecommitdiff
path: root/emu/port/alloc.c
diff options
context:
space:
mode:
authorValery Ushakov <uwe@stderr.spb.ru>2019-12-31 21:09:15 +0000
committerCharles Forsyth <charles.forsyth@gmail.com>2019-12-31 21:09:15 +0000
commit26b9beaea512d50692f7fe87e104f7401e0a3c32 (patch)
treecd5a26edc29f7c63232da2149e3efd0657529c45 /emu/port/alloc.c
parent8c6479d1d73b82a8a0bb407f9a508cab2832a067 (diff)
parent83732701fa28f6cae7c64b48a368f6d770e96be0 (diff)
Merged in nbuwe/inferno-os/bugfix/netbsd-aligned-alloc (pull request #2)
Ensure 16-byte aligned allocations on NetBSD Approved-by: Charles Forsyth <charles.forsyth@gmail.com>
Diffstat (limited to 'emu/port/alloc.c')
-rw-r--r--emu/port/alloc.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/emu/port/alloc.c b/emu/port/alloc.c
index 8b623de0..3cb45552 100644
--- a/emu/port/alloc.c
+++ b/emu/port/alloc.c
@@ -75,11 +75,7 @@ enum {
/* tracing */
enum {
-#ifdef __NetBSD__
- Npadlong = 4, /* XXX: preserve 16-byte alignment */
-#else
Npadlong = 2,
-#endif
MallocOffset = 0,
ReallocOffset = 1
};
@@ -383,9 +379,22 @@ dopoolalloc(Pool *p, ulong asize, ulong pc)
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);