diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libstand/stand.h | 6 | ||||
-rw-r--r-- | lib/libstand/zalloc.c | 8 | ||||
-rw-r--r-- | lib/libstand/zalloc_defs.h | 16 | ||||
-rw-r--r-- | lib/libstand/zalloc_malloc.c | 2 | ||||
-rw-r--r-- | lib/libstand/zalloc_mem.h | 6 | ||||
-rw-r--r-- | lib/libstand/zalloc_protos.h | 6 |
6 files changed, 15 insertions, 29 deletions
diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h index eae1605..db0490f 100644 --- a/lib/libstand/stand.h +++ b/lib/libstand/stand.h @@ -65,15 +65,13 @@ #include <sys/cdefs.h> #include <sys/stat.h> #include <sys/dirent.h> + +/* this header intentionally exports NULL from <string.h> */ #include <string.h> #define CHK(fmt, args...) printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args) #define PCHK(fmt, args...) {printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();} -#ifndef NULL -#define NULL 0 -#endif - /* Avoid unwanted userlandish components */ #define _KERNEL #include <sys/errno.h> diff --git a/lib/libstand/zalloc.c b/lib/libstand/zalloc.c index f726c2e..41aef0d 100644 --- a/lib/libstand/zalloc.c +++ b/lib/libstand/zalloc.c @@ -77,7 +77,7 @@ __FBSDID("$FreeBSD$"); */ void * -znalloc(MemPool *mp, iaddr_t bytes) +znalloc(MemPool *mp, uintptr_t bytes) { /* * align according to pool object size (can be 0). This is @@ -136,7 +136,7 @@ znalloc(MemPool *mp, iaddr_t bytes) */ void -zfree(MemPool *mp, void *ptr, iaddr_t bytes) +zfree(MemPool *mp, void *ptr, uintptr_t bytes) { /* * align according to pool object size (can be 0). This is @@ -153,7 +153,7 @@ zfree(MemPool *mp, void *ptr, iaddr_t bytes) if ((char *)ptr < (char *)mp->mp_Base || (char *)ptr + bytes > (char *)mp->mp_End || - ((iaddr_t)ptr & MEMNODE_SIZE_MASK) != 0) + ((uintptr_t)ptr & MEMNODE_SIZE_MASK) != 0) panic("zfree(%p,%ju): wild pointer", ptr, (uintmax_t)bytes); /* @@ -245,7 +245,7 @@ zfree(MemPool *mp, void *ptr, iaddr_t bytes) */ void -zextendPool(MemPool *mp, void *base, iaddr_t bytes) +zextendPool(MemPool *mp, void *base, uintptr_t bytes) { if (mp->mp_Size == 0) { mp->mp_Base = base; diff --git a/lib/libstand/zalloc_defs.h b/lib/libstand/zalloc_defs.h index 0f4f7e0..5331ee0 100644 --- a/lib/libstand/zalloc_defs.h +++ b/lib/libstand/zalloc_defs.h @@ -39,20 +39,11 @@ #define ZALLOCDEBUG #include <sys/stdint.h> -#include <string.h> #include "stand.h" - -typedef uintptr_t iaddr_t; /* unsigned int same size as pointer */ -typedef intptr_t saddr_t; /* signed int same size as pointer */ #include "zalloc_mem.h" -#define Prototype extern #define Library extern -#ifndef NULL -#define NULL ((void *)0) -#endif - /* * block extension for sbrk() */ @@ -61,8 +52,7 @@ typedef intptr_t saddr_t; /* signed int same size as pointer */ #define BLKEXTENDMASK (BLKEXTEND - 1) /* - * required malloc alignment. Use sizeof(long double) for architecture - * independance. + * required malloc alignment. Just hardwire to 16. * * Note: if we implement a more sophisticated realloc, we should ensure that * MALLOCALIGN is at least as large as MemNode. @@ -73,10 +63,8 @@ typedef struct Guard { size_t ga_Magic; /* must be at least 32 bits */ } Guard; -#define MATYPE long double -#define MALLOCALIGN ((sizeof(MATYPE) > sizeof(Guard)) ? sizeof(MATYPE) : sizeof(Guard)) +#define MALLOCALIGN 16 #define GAMAGIC 0x55FF44FD #define GAFREE 0x5F54F4DF #include "zalloc_protos.h" - diff --git a/lib/libstand/zalloc_malloc.c b/lib/libstand/zalloc_malloc.c index 5cd7bcb..b9a295f 100644 --- a/lib/libstand/zalloc_malloc.c +++ b/lib/libstand/zalloc_malloc.c @@ -126,7 +126,7 @@ Free(void *ptr, const char *file, int line) void * Calloc(size_t n1, size_t n2, const char *file, int line) { - iaddr_t bytes = (iaddr_t)n1 * (iaddr_t)n2; + uintptr_t bytes = (uintptr_t)n1 * (uintptr_t)n2; void *res; if ((res = Malloc(bytes, file, line)) != NULL) { diff --git a/lib/libstand/zalloc_mem.h b/lib/libstand/zalloc_mem.h index c872da1..f29c0d7 100644 --- a/lib/libstand/zalloc_mem.h +++ b/lib/libstand/zalloc_mem.h @@ -37,15 +37,15 @@ typedef struct MemNode { struct MemNode *mr_Next; - iaddr_t mr_Bytes; + uintptr_t mr_Bytes; } MemNode; typedef struct MemPool { void *mp_Base; void *mp_End; MemNode *mp_First; - iaddr_t mp_Size; - iaddr_t mp_Used; + uintptr_t mp_Size; + uintptr_t mp_Used; } MemPool; #define MEMNODE_SIZE_MASK ((sizeof(MemNode) <= 8) ? 7 : 15) diff --git a/lib/libstand/zalloc_protos.h b/lib/libstand/zalloc_protos.h index c90bd5a..53a40e4 100644 --- a/lib/libstand/zalloc_protos.h +++ b/lib/libstand/zalloc_protos.h @@ -29,7 +29,7 @@ * $FreeBSD$ */ -Library void *znalloc(struct MemPool *mpool, iaddr_t bytes); -Library void zfree(struct MemPool *mpool, void *ptr, iaddr_t bytes); -Library void zextendPool(MemPool *mp, void *base, iaddr_t bytes); +Library void *znalloc(struct MemPool *mpool, uintptr_t bytes); +Library void zfree(struct MemPool *mpool, void *ptr, uintptr_t bytes); +Library void zextendPool(MemPool *mp, void *base, uintptr_t bytes); Library void zallocstats(struct MemPool *mp); |