code: 9ferno

Download patch

ref: 83d9d3003e108230c4cb8d4bef5e2e1e927c1053
parent: d8c61f908588654efc97a1c33f31e400607285bd
author: joe9 <joe9mail@gmail.com>
date: Thu Jul 15 11:11:04 EDT 2021

change memory pointers to uintptr

--- a/emu/port/alloc.c
+++ b/emu/port/alloc.c
@@ -20,19 +20,19 @@
 {
 	char*	name;
 	int	pnum;
-	ulong	maxsize;
+	uintptr	maxsize;
 	int	quanta;
 	int	chunk;
 	int	monitor;
-	ulong	ressize;	/* restricted size */
-	ulong	cursize;
-	ulong	arenasize;
-	ulong	hw;
+	uintptr	ressize;	/* restricted size */
+	uintptr	cursize;
+	uintptr	arenasize;
+	uintptr	hw;
 	Lock	l;
 	Bhdr*	root;
 	Bhdr*	chain;
-	ulong	nalloc;
-	ulong	nfree;
+	uintptr	nalloc;
+	uintptr	nfree;
 	int	nbrk;
 	int	lastfree;
 	void	(*move)(void*, void*);
@@ -45,6 +45,8 @@
 	when pointer size = 8 bytes, then 63 = 2^q -1
 		for 4 bytes, 31
 	TODO make this a macro?
+	for allocpc and reallocpc, 2 * 8 = 16 bytes get added
+	so, minimum size = 2*4 + 2*8 + 5*8 = 64, using 127 to satisfy 2^q -1
  */
 struct
 {
@@ -54,9 +56,9 @@
 } table = {
 	3,
 	{
-		{ "main",  0, 	32*1024*1024, 63,  512*1024, 0, 31*1024*1024 },
-		{ "heap",  1, 	32*1024*1024, 63,  512*1024, 0, 31*1024*1024 },
-		{ "image", 2,   64*1024*1024+256, 63, 4*1024*1024, 1, 63*1024*1024 },
+		{ "main",  0, 	32*1024*1024, 127,  512*1024, 0, 31*1024*1024 },
+		{ "heap",  1, 	32*1024*1024, 127,  512*1024, 0, 31*1024*1024 },
+		{ "image", 2,   64*1024*1024+256, 127, 4*1024*1024, 1, 63*1024*1024 },
 	}
 };
 
@@ -66,31 +68,14 @@
 
 static void _auditmemloc(char *, void *);
 void (*auditmemloc)(char *, void *) = _auditmemloc;
-static void _poolfault(void *, char *, ulong);
-void (*poolfault)(void *, char *, ulong) = _poolfault;
+static void _poolfault(void *, char *, uintptr);
+void (*poolfault)(void *, char *, uintptr) = _poolfault;
 
-/*	non tracing
- *
 enum {
-	Npadlong	= 0,
-	MallocOffset = 0,
-	ReallocOffset = 0
-};
- *
- */
-
-/* tracing */
-enum {
-	Npadlong	= 2,
-	MallocOffset = 0,
-	ReallocOffset = 1
-};
-
-enum {
 	Monitor = 1
 };
 
-void	(*memmonitor)(int, uintptr, void *, ulong) = nil;
+void	(*memmonitor)(int, uintptr, void *, uintptr) = nil;
 #define	MM(v,pc,base,size)	if(!Monitor || memmonitor==nil){} else memmonitor((v),(pc),(base),(size))
 
 #define CKLEAK	0
@@ -285,11 +270,11 @@
 }
 
 static void*
-dopoolalloc(Pool *p, ulong asize, uintptr pc)
+dopoolalloc(Pool *p, uintptr asize, uintptr pc)
 {
 	Bhdr *q, *t;
-	int alloc, ldr, ns, frag;
-	int osize, size;
+	intptr alloc, ldr, ns, frag;
+	intptr osize, size;
 
 	if(asize >= 1024*1024*1024)	/* for sanity and to avoid overflow */
 		return nil;
@@ -370,8 +355,8 @@
 			}
 
 			unlock(&p->l);
-			print("arena %s too large: size %d maxsize %lud ressize %lud"
-				" cursize %lud arenasize %lud\n",
+			print("arena %s too large: size %zd maxsize %zud ressize %zud"
+				" cursize %zud arenasize %zud\n",
 				 p->name, size, p->maxsize, p->ressize,
 				 p->cursize, p->arenasize);
 			return nil;
@@ -390,14 +375,13 @@
 #ifdef __NetBSD__
 	/* Align allocations to 16 bytes */
 	{
-		const size_t off = __builtin_offsetof(struct Bhdr, u.data)
-					+ Npadlong*sizeof(ulong);
+		const size_t off = __builtin_offsetof(struct Bhdr, u.data);
 		struct assert_align {
 			unsigned int align_ok : (off % 8 == 0) ? 1 : -1;
 		};
 
-		const ulong align = (off - 1) % 16;
-		t = (Bhdr *)(((ulong)t + align) & ~align);
+		const uintptr align = (off - 1) % 16;
+		t = (Bhdr *)(((uintptr)t + align) & ~align);
 	}
 #else
 	/* Double alignment */
@@ -451,7 +435,7 @@
 }
 
 void *
-poolalloc(Pool *p, ulong asize)
+poolalloc(Pool *p, uintptr asize)
 {
 	Prog *prog;
 
@@ -498,11 +482,11 @@
 }
 
 void *
-poolrealloc(Pool *p, void *v, ulong size)
+poolrealloc(Pool *p, void *v, uintptr size)
 {
 	Bhdr *b;
 	void *nv;
-	int osize;
+	intptr osize;
 
 	if(size >= 1024*1024*1024)	/* for sanity and to avoid overflow */
 		return nil;
@@ -527,11 +511,11 @@
 	return nv;
 }
 
-ulong
+uintptr
 poolmsize(Pool *p, void *v)
 {
 	Bhdr *b;
-	ulong size;
+	uintptr size;
 
 	if(v == nil)
 		return 0;
@@ -542,11 +526,11 @@
 	return size;
 }
 
-static ulong
+static uintptr
 poolmax(Pool *p)
 {
 	Bhdr *t;
-	ulong size;
+	uintptr size;
 
 	lock(&p->l);
 	size = p->maxsize - p->cursize;
@@ -563,11 +547,11 @@
 	return size;
 }
 
-ulong
+uintptr
 poolmaxsize(void)
 {
 	int i;
-	ulong total;
+	uintptr total;
 
 	total = 0;
 	for(i = 0; i < nelem(table.pool); i++)
@@ -585,7 +569,7 @@
 	signed_off = offset;
 	for(i = 0; i < table.n; i++) {
 		p = &table.pool[i];
-		n += snprint(va+n, count-n, "%11lud %11lud %11lud %11lud %11lud %11d %11lud %s\n",
+		n += snprint(va+n, count-n, "%11zud %11zud %11zud %11zud %11zud %11d %11zud %s\n",
 			p->cursize,
 			p->maxsize,
 			p->hw,
@@ -610,7 +594,7 @@
 }
 
 void*
-smalloc(size_t size)
+smalloc(uintptr size)
 {
 	void *v;
 
@@ -630,18 +614,15 @@
 }
 
 void*
-kmalloc(size_t size)
+kmalloc(uintptr size)
 {
 	void *v;
 
-	v = dopoolalloc(mainmem, size+Npadlong*sizeof(uintptr), getcallerpc(&size));
+	v = dopoolalloc(mainmem, size, getcallerpc(&size));
 	if(v != nil){
 		ML(v, size, getcallerpc(&size));
-		if(Npadlong){
-			v = (uintptr*)v+Npadlong;
-			setmalloctag(v, getcallerpc(&size));
-			setrealloctag(v, 0);
-		}
+		setmalloctag(v, getcallerpc(&size));
+		setrealloctag(v, 0);
 		memset(v, 0, size);
 		MM(0, getcallerpc(&size), v, size);
 	}
@@ -648,21 +629,17 @@
 	return v;
 }
 
-
-
+/* this function signature is tied to the system's libc.h */
 void*
-malloc(size_t size)
+malloc(ulong size)
 {
 	void *v;
 
-	v = poolalloc(mainmem, size+Npadlong*sizeof(uintptr));
+	v = poolalloc(mainmem, size);
 	if(v != nil){
 		ML(v, size, getcallerpc(&size));
-		if(Npadlong){
-			v = (uintptr*)v+Npadlong;
-			setmalloctag(v, getcallerpc(&size));
-			setrealloctag(v, 0);
-		}
+		setmalloctag(v, getcallerpc(&size));
+		setrealloctag(v, 0);
 		memset(v, 0, size);
 		MM(0, getcallerpc(&size), v, size);
 	} else 
@@ -670,19 +647,17 @@
 	return v;
 }
 
+/* this function signature is tied to the system's libc.h */
 void*
 mallocz(ulong size, int clr)
 {
 	void *v;
 
-	v = poolalloc(mainmem, size+Npadlong*sizeof(uintptr));
+	v = poolalloc(mainmem, size);
 	if(v != nil){
 		ML(v, size, getcallerpc(&size));
-		if(Npadlong){
-			v = (uintptr*)v+Npadlong;
-			setmalloctag(v, getcallerpc(&size));
-			setrealloctag(v, 0);
-		}
+		setmalloctag(v, getcallerpc(&size));
+		setrealloctag(v, 0);
 		if(clr)
 			memset(v, 0, size);
 		MM(0, getcallerpc(&size), v, size);
@@ -697,31 +672,25 @@
 	Bhdr *b;
 
 	if(v != nil) {
-		if(Npadlong)
-			v = (uintptr*)v-Npadlong;
 		D2B(b, v);
 		ML(v, 0, 0);
-		MM(1<<8|0, getcallerpc(&v), ((uintptr*)v+Npadlong), b->size);
+		MM(1<<8|0, getcallerpc(&v), (uintptr*)v, b->size);
 		poolfree(mainmem, v);
 	}
 }
 
+/* this function signature is tied to the system's libc.h */
 void*
-realloc(void *v, size_t size)
+realloc(void *v, ulong size)
 {
 	void *nv;
 
 	if(size == 0)
 		return malloc(size);	/* temporary change until realloc calls can be checked */
-	if(v != nil)
-		v = (uintptr*)v-Npadlong;
-	if(Npadlong!=0 && size!=0)
-		size += Npadlong*sizeof(uintptr);
 	nv = poolrealloc(mainmem, v, size);
 	ML(v, 0, 0);
 	ML(nv, size, getcallerpc(&v));
 	if(nv != nil) {
-		nv = (uintptr*)nv+Npadlong;
 		setrealloctag(nv, getcallerpc(&v));
 		if(v == nil)
 			setmalloctag(v, getcallerpc(&v));
@@ -733,45 +702,45 @@
 void
 setmalloctag(void *v, uintptr pc)
 {
-	uintptr *u;
+	Bhdr *b;
 
-	USED(v);
-	USED(pc);
-	if(Npadlong <= MallocOffset || v == nil)
-		return;
-	u = v;
-	u[-Npadlong+MallocOffset] = pc;
+	if(v != nil){
+		D2B(b, v);
+		b->allocpc = pc;
+	}
 }
 
 uintptr
 getmalloctag(void *v)
 {
-	USED(v);
-	if(Npadlong <= MallocOffset)
-		return ~0;
-	return ((uintptr*)v)[-Npadlong+MallocOffset];
+	Bhdr *b;
+
+	if(v == nil)
+		abort();
+	D2B(b, v);
+	return b->allocpc;
 }
 
 void
 setrealloctag(void *v, uintptr pc)
 {
-	uintptr *u;
+	Bhdr *b;
 
-	USED(v);
-	USED(pc);
-	if(Npadlong <= ReallocOffset || v == nil)
-		return;
-	u = v;
-	u[-Npadlong+ReallocOffset] = pc;
+	if(v != nil){
+		D2B(b, v);
+		b->reallocpc = pc;
+	}
 }
 
 uintptr
 getrealloctag(void *v)
 {
-	USED(v);
-	if(Npadlong <= ReallocOffset)
-		return ((uintptr*)v)[-Npadlong+ReallocOffset];
-	return ~0;
+	Bhdr *b;
+
+	if(v == nil)
+		abort();
+	D2B(b, v);
+	return b->reallocpc;
 }
 
 ulong
@@ -779,16 +748,16 @@
 {
 	if(v == nil)
 		return 0;
-	return poolmsize(mainmem, (uintptr*)v-Npadlong)-Npadlong*sizeof(uintptr);
+	return poolmsize(mainmem, v);
 }
 
+/* this function signature is tied to the system's libc.h */
 void*
-calloc(size_t n, size_t szelem)
+calloc(ulong n, ulong szelem)
 {
 	return malloc(n*szelem);
 }
 
-/*
 void
 pooldump(Pool *p)
 {
@@ -802,17 +771,17 @@
 	limit = B2LIMIT(b);
 
 	while(base != nil) {
-		print("\tbase #%.8lux ptr #%.8lux", base, ptr);
+		print("\tbase #%.8p ptr #%.8p", base, ptr);
 		if(ptr->magic == MAGIC_A || ptr->magic == MAGIC_I)
-			print("\tA%.5d\n", ptr->size);
+			print("\tA%.5d pc 0x%p\n", ptr->size, getmalloctag(ptr));
 		else if(ptr->magic == MAGIC_E)
-			print("\tE\tL#%.8lux\tS#%.8lux\n", ptr->clink, ptr->csize);
+			print("\tE\tL#%.8p\tS#%.8lx\n", ptr->clink, ptr->csize);
 		else
-			print("\tF%.5d\tL#%.8lux\tR#%.8lux\tF#%.8lux\tP#%.8lux\tT#%.8lux\n",
+			print("\tF%.5d\tL#%.8p\tR#%.8p\tF#%.8p\tP#%.8p\tT#%.8p\n",
 				ptr->size, ptr->left, ptr->right, ptr->fwd, ptr->prev, ptr->parent);
 		ptr = B2NB(ptr);
 		if(ptr >= limit) {
-			print("link to #%.8lux\n", base->clink);
+			print("link to #%.8p\n", base->clink);
 			base = base->clink;
 			if(base == nil)
 				break;
@@ -821,7 +790,6 @@
 		}
 	}
 }
-*/
 
 void
 poolsetcompact(Pool *p, void (*move)(void*, void*))
@@ -882,7 +850,7 @@
 }
 
 static void
-_poolfault(void *v, char *msg, ulong c)
+_poolfault(void *v, char *msg, uintptr c)
 {
 	auditmemloc(msg, v);
 	panic("%s %lux (from %lux/%lux)", msg, v, getcallerpc(&v), c);
--- a/emu/port/fns.h
+++ b/emu/port/fns.h
@@ -210,7 +210,7 @@
 void		ospause(void);
 void		osyield(void);
 void		osreboot(char*, char**);
-ulong	poolmaxsize(void);
+uintptr	poolmaxsize(void);
 Pool*	poolmk(char*, int, int, int);
 void		hnputv(void*, vlong);
 void		hnputl(void*, ulong);
@@ -218,8 +218,8 @@
 vlong		nhgetv(void*);
 ulong		nhgetl(void*);
 ushort		nhgets(void*);
-void*	smalloc(size_t);
-void*	kmalloc(size_t);
+void*	smalloc(uintptr);
+void*	kmalloc(uintptr);
 
 /* Namespace Emulation */
 int		kbind(char*, char*, int);
--- a/include/kern.h
+++ b/include/kern.h
@@ -89,15 +89,15 @@
  * malloc
  */
 extern	void*	malloc(ulong);
-extern	void*	mallocz(ulong, int);
+extern	void*	mallocz(uintptr, int);
 extern	void	free(void*);
-extern	ulong	msize(void*);
+extern	uintptr	msize(void*);
 extern	void*	calloc(ulong, ulong);
 extern	void*	realloc(void*, ulong);
-extern	void		setmalloctag(void*, ulong);
-extern	void		setrealloctag(void*, ulong);
-extern	ulong	getmalloctag(void*);
-extern	ulong	getrealloctag(void*);
+extern	void		setmalloctag(void*, uintptr);
+extern	void		setrealloctag(void*, uintptr);
+extern	uintptr	getmalloctag(void*);
+extern	uintptr	getrealloctag(void*);
 extern	void*	malloctopoolblock(void*);
 
 /*
--- a/include/pool.h
+++ b/include/pool.h
@@ -18,6 +18,8 @@
 {
 	u32	magic;
 	uintptr	size;
+	intptr	allocpc;
+	intptr	reallocpc;
 	union {
 		uchar data[1];
 		struct {
@@ -52,20 +54,20 @@
 
 #define B2LIMIT(b)	((Bhdr*)((uchar*)b + b->csize))
 
-#define BHDRSIZE	((u32)(((Bhdr*)0)->u.data)+sizeof(Btail))
+#define BHDRSIZE	((uintptr)(((Bhdr*)0)->u.data)+sizeof(Btail))
 
-extern	void	(*poolfault)(void *, char *, ulong);
+extern	void	(*poolfault)(void *, char *, uintptr);
 extern	void	poolinit(void);
-extern	void*	poolalloc(Pool*, ulong);
+extern	void*	poolalloc(Pool*, uintptr);
 extern	void	poolfree(Pool*, void*);
 extern	Bhdr*	poolchain(Pool*);
 extern	int	poolcompact(Pool*);
 extern	void	poolimmutable(void*);
-extern	ulong	poolmsize(Pool*, void*);
+extern	uintptr	poolmsize(Pool*, void*);
 extern	void	poolmutable(void*);
 extern	char*	poolname(Pool*);
 extern	int	poolread(char*, int, uintptr);
-extern	void*	poolrealloc(Pool*, void*, ulong);
+extern	void*	poolrealloc(Pool*, void*, uintptr);
 extern	int	poolsetsize(char*, int);
 extern	void	poolsetcompact(Pool*, void (*)(void*, void*));
 extern	char*	poolaudit(char*(*)(int, Bhdr *));
--- a/os/port/alloc.c
+++ b/os/port/alloc.c
@@ -17,18 +17,18 @@
 {
 	char*	name;
 	int	pnum;
-	ulong	maxsize;
+	uintptr	maxsize;
 	int	quanta;
 	int	chunk;
-	ulong	ressize;
-	ulong	cursize;
-	ulong	arenasize;
-	ulong	hw;
+	uintptr	ressize;
+	uintptr	cursize;
+	uintptr	arenasize;
+	uintptr	hw;
 	Lock	l;
 	Bhdr*	root;
 	Bhdr*	chain;
-	ulong	nalloc;
-	ulong	nfree;
+	uintptr	nalloc;
+	uintptr	nfree;
 	int	nbrk;
 	int	lastfree;
 	int	warn;
@@ -40,6 +40,8 @@
 	when pointer size = 8 bytes, then 63 = 2^q -1
 		for 4 bytes, 31
 	TODO make this a macro?
+	for allocpc and reallocpc, 2 * 8 = 16 bytes get added
+	so, minimum size = 2*4 + 2*8 + 5*8 = 64, using 127 to satisfy 2^q -1
  */
 static
 struct
@@ -50,9 +52,9 @@
 } table = {
 	3,
 	{
-		{ "main",  0,	 4*1024*1024, 63,  128*1024, 15*256*1024 },
-		{ "heap",  1,	16*1024*1024, 63,  128*1024, 15*1024*1024 },
-		{ "image", 2,	 8*1024*1024, 63, 300*1024, 15*512*1024 },
+		{ "main",  0, 	32*1024*1024, 127,  512*1024, 0, 31*1024*1024 },
+		{ "heap",  1, 	32*1024*1024, 127,  512*1024, 0, 31*1024*1024 },
+		{ "image", 2,   64*1024*1024+256, 127, 4*1024*1024, 1, 63*1024*1024 },
 	}
 };
 
@@ -62,26 +64,9 @@
 
 static void _auditmemloc(char *, void *);
 void (*auditmemloc)(char *, void *) = _auditmemloc;
-static void _poolfault(void *, char *, ulong);
-void (*poolfault)(void *, char *, ulong) = _poolfault;
+static void _poolfault(void *, char *, uintptr);
+void (*poolfault)(void *, char *, uintptr) = _poolfault;
 
-/*	non tracing
- *
-enum {
-	Npadlong	= 0,
-	MallocOffset = 0,
-	ReallocOffset = 0
-};
- *
- */
-
-/* tracing */
-enum {
-	Npadlong	= 2,
-	MallocOffset = 0,
-	ReallocOffset = 1
-};
-
 int
 memusehigh(void)
 {
@@ -262,11 +247,11 @@
 }
 
 void*
-poolalloc(Pool *p, ulong asize)
+poolalloc(Pool *p, uintptr asize)
 {
 	Bhdr *q, *t;
-	int alloc, ldr, ns, frag;
-	int osize, size;
+	intptr alloc, ldr, ns, frag;
+	intptr osize, size;
 	Prog *prog;
 
 	// if(asize >= 1024*1024*1024)	/* for sanity and to avoid overflow */
@@ -352,7 +337,7 @@
 				return nil;
 			p->warn = 1;
 			if (p != mainmem || ns > 512)
-				print("arena too large: %s size %d cursize %lud arenasize %lud maxsize %lud, alloc = %d\n", p->name, osize, p->cursize, p->arenasize, p->maxsize, alloc);
+				print("arena too large: %s size %zd cursize %zud arenasize %zud maxsize %zud, alloc = %zd\n", p->name, osize, p->cursize, p->arenasize, p->maxsize, alloc);
 			return nil;
 		}
 		alloc = ns+ldr+ldr;
@@ -453,14 +438,14 @@
 }
 
 void *
-poolrealloc(Pool *p, void *v, ulong size)
+poolrealloc(Pool *p, void *v, uintptr size)
 {
 	Bhdr *b;
 	void *nv;
-	int osize;
+	intptr osize;
 
-	if(size >= 1024*1024*1024)	/* for sanity and to avoid overflow */
-		return nil;
+	//if(size >= 1024*1024*1024)	/* for sanity and to avoid overflow */
+	//	return nil;
 	if(size == 0){
 		poolfree(p, v);
 		return nil;
@@ -482,11 +467,11 @@
 	return nv;
 }
 
-ulong
+uintptr
 poolmsize(Pool *p, void *v)
 {
 	Bhdr *b;
-	ulong size;
+	uintptr size;
 
 	if(v == nil)
 		return 0;
@@ -497,11 +482,11 @@
 	return size;
 }
 
-static ulong
+static uintptr
 poolmax(Pool *p)
 {
 	Bhdr *t;
-	ulong size;
+	uintptr size;
 
 	ilock(&p->l);
 	size = p->maxsize - p->cursize;
@@ -528,7 +513,7 @@
 	signed_off = offset;
 	for(i = 0; i < table.n; i++) {
 		p = &table.pool[i];
-		n += snprint(va+n, count-n, "%11lud %11lud %11lud %11lud %11lud %11d %11lud %s\n",
+		n += snprint(va+n, count-n, "%11zud %11zud %11zud %11zud %11zud %11d %11zud %s\n",
 			p->cursize,
 			p->maxsize,
 			p->hw,
@@ -552,18 +537,16 @@
 	return n;
 }
 
+/* this function signature is tied to the system's libc.h */
 void*
 malloc(ulong size)
 {
 	void *v;
 
-	v = poolalloc(mainmem, size+Npadlong*sizeof(uintptr));
+	v = poolalloc(mainmem, size);
 	if(v != nil){
-		if(Npadlong){
-			v = (uintptr*)v+Npadlong;
-			setmalloctag(v, getcallerpc(&size));
-			setrealloctag(v, 0);
-		}
+		setmalloctag(v, getcallerpc(&size));
+		setrealloctag(v, 0);
 		memset(v, 0, size);
 	}
 	return v;
@@ -570,21 +553,18 @@
 }
 
 void*
-smalloc(ulong size)
+smalloc(uintptr size)
 {
 	void *v;
 
 	for(;;) {
-		v = poolalloc(mainmem, size+Npadlong*sizeof(uintptr));
+		v = poolalloc(mainmem, size);
 		if(v != nil)
 			break;
 		tsleep(&up->sleep, return0, 0, 100);
 	}
-	if(Npadlong){
-		v = (uintptr*)v+Npadlong;
-		setmalloctag(v, getcallerpc(&size));
-		setrealloctag(v, 0);
-	}
+	setmalloctag(v, getcallerpc(&size));
+	setrealloctag(v, 0);
 	memset(v, 0, size);
 	return v;
 }
@@ -594,13 +574,10 @@
 {
 	void *v;
 
-	v = poolalloc(mainmem, size+Npadlong*sizeof(uintptr));
+	v = poolalloc(mainmem, size);
 	if(v != nil){
-		if(Npadlong){
-			v = (uintptr*)v+Npadlong;
-			setmalloctag(v, getcallerpc(&size));
-			setrealloctag(v, 0);
-		}
+		setmalloctag(v, getcallerpc(&size));
+		setrealloctag(v, 0);
 		if(clr)
 			memset(v, 0, size);
 	}
@@ -611,7 +588,7 @@
  * need more testing
  */
 void*
-mallocalign(u32 size, u32 align, s32 offset, u32 span)
+mallocalign(uintptr size, u32 align, s32 offset, u32 span)
 {
 	void *v;
 	uintptr a;;
@@ -634,13 +611,12 @@
 	Bhdr *b;
 
 	if(v != nil) {
-		if(Npadlong)
-			v = (uintptr*)v-Npadlong;
 		D2B(b, v);
 		poolfree(mainmem, v);
 	}
 }
 
+/* this function signature is tied to emu which is tied to the system's libc.h */
 void*
 realloc(void *v, ulong size)
 {
@@ -648,13 +624,9 @@
 
 	if(size == 0)
 		return malloc(size);	/* temporary change until realloc calls can be checked */
-	if(v != nil)
-		v = (uintptr*)v-Npadlong;
-	if(Npadlong!=0 && size!=0)
-		size += Npadlong*sizeof(uintptr);
 	nv = poolrealloc(mainmem, v, size);
 	if(nv != nil) {
-		nv = (uintptr*)nv+Npadlong;
+		nv = (uintptr*)nv;
 		setrealloctag(nv, getcallerpc(&v));
 		if(v == nil)
 			setmalloctag(v, getcallerpc(&v));
@@ -665,45 +637,45 @@
 void
 setmalloctag(void *v, uintptr pc)
 {
-	uintptr *u;
+	Bhdr *b;
 
-	USED(v);
-	USED(pc);
-	if(Npadlong <= MallocOffset || v == nil)
-		return;
-	u = v;
-	u[-Npadlong+MallocOffset] = pc;
+	if(v != nil){
+		D2B(b, v);
+		b->allocpc = pc;
+	}
 }
 
 uintptr
 getmalloctag(void *v)
 {
-	USED(v);
-	if(Npadlong <= MallocOffset)
+	Bhdr *b;
+
+	if(v == nil)
 		return ~0;
-	return ((uintptr*)v)[-Npadlong+MallocOffset];
+	D2B(b, v);
+	return b->allocpc;
 }
 
 void
 setrealloctag(void *v, uintptr pc)
 {
-	ulong *u;
+	Bhdr *b;
 
-	USED(v);
-	USED(pc);
-	if(Npadlong <= ReallocOffset || v == nil)
-		return;
-	u = v;
-	u[-Npadlong+ReallocOffset] = pc;
+	if(v != nil){
+		D2B(b, v);
+		b->reallocpc = pc;
+	}
 }
 
 uintptr
 getrealloctag(void *v)
 {
-	USED(v);
-	if(Npadlong <= ReallocOffset)
-		return ((uintptr*)v)[-Npadlong+ReallocOffset];
-	return ~0;
+	Bhdr *b;
+
+	if(v == nil)
+		return ~0;
+	D2B(b, v);
+	return b->reallocpc;
 }
 
 ulong
@@ -711,9 +683,10 @@
 {
 	if(v == nil)
 		return 0;
-	return poolmsize(mainmem, (uintptr*)v-Npadlong)-Npadlong*sizeof(uintptr);
+	return poolmsize(mainmem, v);
 }
 
+/* this function signature is tied to emu which is tied to the system's libc.h */
 void*
 calloc(ulong n, ulong szelem)
 {
@@ -805,7 +778,7 @@
 }
 
 void
-poolsize(Pool *p, u64 max, int contig)
+poolsize(Pool *p, uintptr max, int contig)
 {
 	void *x;
 
@@ -828,7 +801,7 @@
 }
 
 static void
-_poolfault(void *v, char *msg, ulong c)
+_poolfault(void *v, char *msg, uintptr c)
 {
 	setpanic();
 	auditmemloc(msg, v);
--- a/os/port/portfns.h
+++ b/os/port/portfns.h
@@ -152,7 +152,7 @@
 extern void	machbreakclear(ulong addr, Instr i);
 extern ulong	machnextaddr(Ureg *ur);
 void*		malloc(ulong);
-void*		mallocalign(u32, u32, s32, u32);
+void*		mallocalign(uintptr, u32, s32, u32);
 void*		mallocz(ulong, int);
 Block*		mem2bl(uchar*, int);
 void		memmapdump(void);
@@ -270,7 +270,7 @@
 void		setrealloctag(void*, uintptr);
 char*		skipslash(char*);
 void		sleep(Rendez*, int(*)(void*), void*);
-void*		smalloc(ulong);
+void*		smalloc(uintptr);
 int		splhi(void);
 int		spllo(void);
 void		splx(int);