changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: ape: fix malloc to deal with more than 4GB of memory on 64 bit systems

changeset 7225: ff0bb3db55f7
parent 7224: 31f1de7ff0d4
child 7226: c3a4ca2a4715
author: cinap_lenrek@felloff.net
date: Fri, 10 May 2019 12:10:02 +0200
files: sys/src/ape/lib/ap/plan9/malloc.c
description: ape: fix malloc to deal with more than 4GB of memory on 64 bit systems
     1.1--- a/sys/src/ape/lib/ap/plan9/malloc.c
     1.2+++ b/sys/src/ape/lib/ap/plan9/malloc.c
     1.3@@ -1,10 +1,9 @@
     1.4+#include <stdint.h>
     1.5 #include <stdlib.h>
     1.6 #include <string.h>
     1.7 
     1.8 #include <lock.h>
     1.9 
    1.10-typedef unsigned int	uint;
    1.11-
    1.12 enum
    1.13 {
    1.14 	MAGIC		= 0xbada110c,
    1.15@@ -38,7 +37,7 @@ extern	void	*sbrk(unsigned long);
    1.16 void*
    1.17 malloc(size_t size)
    1.18 {
    1.19-	uint next;
    1.20+	uintptr_t next;
    1.21 	int pow, n;
    1.22 	Bucket *bp, *nbp;
    1.23 
    1.24@@ -70,16 +69,16 @@ good:
    1.25 	if(pow < CUTOFF) {
    1.26 		n = (CUTOFF-pow)+2;
    1.27 		bp = sbrk(size*n);
    1.28-		if((int)bp < 0){
    1.29+		if(bp == (void*)-1){
    1.30 			unlock(&arena);
    1.31 			return nil;
    1.32 		}
    1.33 
    1.34-		next = (uint)bp+size;
    1.35+		next = (uintptr_t)bp+size;
    1.36 		nbp = (Bucket*)next;
    1.37 		arena.btab[pow] = nbp;
    1.38 		for(n -= 2; n; n--) {
    1.39-			next = (uint)nbp+size;
    1.40+			next = (uintptr_t)nbp+size;
    1.41 			nbp->next = (Bucket*)next;
    1.42 			nbp->size = pow;
    1.43 			nbp = nbp->next;
    1.44@@ -88,7 +87,7 @@ good:
    1.45 	}
    1.46 	else {
    1.47 		bp = sbrk(size);
    1.48-		if((int)bp < 0){
    1.49+		if(bp == (void*)-1){
    1.50 			unlock(&arena);
    1.51 			return nil;
    1.52 		}
    1.53@@ -110,7 +109,7 @@ free(void *ptr)
    1.54 		return;
    1.55 
    1.56 	/* Find the start of the structure */
    1.57-	bp = (Bucket*)((uint)ptr - datoff);
    1.58+	bp = (Bucket*)((uintptr_t)ptr - datoff);
    1.59 
    1.60 	if(bp->magic != MAGIC)
    1.61 		abort();
    1.62@@ -127,14 +126,14 @@ void*
    1.63 realloc(void *ptr, size_t n)
    1.64 {
    1.65 	void *new;
    1.66-	uint osize;
    1.67+	size_t osize;
    1.68 	Bucket *bp;
    1.69 
    1.70 	if(ptr == nil)
    1.71 		return malloc(n);
    1.72 
    1.73 	/* Find the start of the structure */
    1.74-	bp = (Bucket*)((uint)ptr - datoff);
    1.75+	bp = (Bucket*)((uintptr_t)ptr - datoff);
    1.76 
    1.77 	if(bp->magic != MAGIC)
    1.78 		abort();