diff options
| author | Valery Ushakov <uwe@stderr.spb.ru> | 2019-12-31 21:09:15 +0000 |
|---|---|---|
| committer | Charles Forsyth <charles.forsyth@gmail.com> | 2019-12-31 21:09:15 +0000 |
| commit | 26b9beaea512d50692f7fe87e104f7401e0a3c32 (patch) | |
| tree | cd5a26edc29f7c63232da2149e3efd0657529c45 | |
| parent | 8c6479d1d73b82a8a0bb407f9a508cab2832a067 (diff) | |
| parent | 83732701fa28f6cae7c64b48a368f6d770e96be0 (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>
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | emu/port/alloc.c | 19 | ||||
| -rw-r--r-- | emu/port/kproc-pthreads.c | 6 |
3 files changed, 18 insertions, 11 deletions
@@ -54,6 +54,10 @@ y.debug # initial mk from makemk.sh /utils/mk/mk +# no binaries are committed for any of the netbsd ports +# can be deleted if wildcard from the comment below is enabled +/NetBSD/*/bin/ + # preserve the patterns from .hgignore, though perhaps all binaries # should be deleted and ignored with: # /[A-Z]*/*/bin/ 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); diff --git a/emu/port/kproc-pthreads.c b/emu/port/kproc-pthreads.c index c6caded6..a15a7cd3 100644 --- a/emu/port/kproc-pthreads.c +++ b/emu/port/kproc-pthreads.c @@ -122,12 +122,6 @@ kproc(char *name, void (*func)(void*), void *arg, int flags) panic("kproc: no memory"); os->self = 0; /* set by tramp */ sem_init(&os->sem, 0, 0); -#if defined(__NetBSD__) && defined(__powerpc__) - { /* XXX: Work around a problem on macppc with kernel semaphores. */ - int val; - sem_getvalue(&os->sem, &val); - } -#endif p->os = os; if(flags & KPDUPPG) { |
