From addb36ee488757125c43c02076006dba8c9e69bc Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 10 May 2019 12:10:02 +0200 Subject: [PATCH] ape: fix malloc to deal with more than 4GB of memory on 64 bit systems --- sys/src/ape/lib/ap/plan9/malloc.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sys/src/ape/lib/ap/plan9/malloc.c b/sys/src/ape/lib/ap/plan9/malloc.c index 07caf78d7..2bfa176fc 100644 --- a/sys/src/ape/lib/ap/plan9/malloc.c +++ b/sys/src/ape/lib/ap/plan9/malloc.c @@ -1,10 +1,9 @@ +#include #include #include #include -typedef unsigned int uint; - enum { MAGIC = 0xbada110c, @@ -38,7 +37,7 @@ extern void *sbrk(unsigned long); void* malloc(size_t size) { - uint next; + uintptr_t next; int pow, n; Bucket *bp, *nbp; @@ -70,16 +69,16 @@ good: if(pow < CUTOFF) { n = (CUTOFF-pow)+2; bp = sbrk(size*n); - if((int)bp < 0){ + if(bp == (void*)-1){ unlock(&arena); return nil; } - next = (uint)bp+size; + next = (uintptr_t)bp+size; nbp = (Bucket*)next; arena.btab[pow] = nbp; for(n -= 2; n; n--) { - next = (uint)nbp+size; + next = (uintptr_t)nbp+size; nbp->next = (Bucket*)next; nbp->size = pow; nbp = nbp->next; @@ -88,7 +87,7 @@ good: } else { bp = sbrk(size); - if((int)bp < 0){ + if(bp == (void*)-1){ unlock(&arena); return nil; } @@ -110,7 +109,7 @@ free(void *ptr) return; /* Find the start of the structure */ - bp = (Bucket*)((uint)ptr - datoff); + bp = (Bucket*)((uintptr_t)ptr - datoff); if(bp->magic != MAGIC) abort(); @@ -127,14 +126,14 @@ void* realloc(void *ptr, size_t n) { void *new; - uint osize; + size_t osize; Bucket *bp; if(ptr == nil) return malloc(n); /* Find the start of the structure */ - bp = (Bucket*)((uint)ptr - datoff); + bp = (Bucket*)((uintptr_t)ptr - datoff); if(bp->magic != MAGIC) abort();