Backout the previous backing out.
This commit is contained in:
parent
2ca39ceddf
commit
07fd543922
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: malloc.c,v 1.29 2000/01/31 22:56:14 thorpej Exp $ */
|
||||
/* $NetBSD: malloc.c,v 1.30 2000/04/07 14:56:13 enami Exp $ */
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
@ -152,7 +152,7 @@ static size_t malloc_pagemask;
|
||||
#endif
|
||||
|
||||
#define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask)))
|
||||
#define ptr2idx(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo)
|
||||
#define ptr2idx(foo) (((size_t)(foo) >> malloc_pageshift)-malloc_origo)
|
||||
|
||||
#ifndef THREAD_LOCK
|
||||
#define THREAD_LOCK()
|
||||
@ -184,10 +184,10 @@ static int malloc_active;
|
||||
static unsigned malloc_cache = 16;
|
||||
|
||||
/* The offset from pagenumber to index into the page directory */
|
||||
static u_long malloc_origo;
|
||||
static size_t malloc_origo;
|
||||
|
||||
/* The last index in the page directory we care about */
|
||||
static u_long last_idx;
|
||||
static size_t last_idx;
|
||||
|
||||
/* Pointer to page directory. Allocated "as if with" malloc */
|
||||
static struct pginfo **page_dir;
|
||||
@ -253,12 +253,12 @@ static char *malloc_func;
|
||||
/* Macro for mmap */
|
||||
#define MMAP(size) \
|
||||
mmap(0, (size), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, \
|
||||
MMAP_FD, 0);
|
||||
MMAP_FD, (off_t)0);
|
||||
|
||||
/*
|
||||
* Necessary function declarations
|
||||
*/
|
||||
static int extend_pgdir(u_long idx);
|
||||
static int extend_pgdir(size_t idx);
|
||||
static void *imalloc(size_t size);
|
||||
static void ifree(void *ptr);
|
||||
static void *irealloc(void *ptr, size_t size);
|
||||
@ -294,11 +294,11 @@ wrtwarning(char *p)
|
||||
* Allocate a number of pages from the OS
|
||||
*/
|
||||
static void *
|
||||
map_pages(int pages)
|
||||
map_pages(size_t pages)
|
||||
{
|
||||
caddr_t result, tail;
|
||||
|
||||
result = (caddr_t)pageround((u_long)sbrk(0));
|
||||
result = (caddr_t)pageround((size_t)sbrk(0));
|
||||
tail = result + (pages << malloc_pageshift);
|
||||
|
||||
if (brk(tail)) {
|
||||
@ -321,15 +321,13 @@ map_pages(int pages)
|
||||
* Extend page directory
|
||||
*/
|
||||
static int
|
||||
extend_pgdir(u_long idx)
|
||||
extend_pgdir(size_t idx)
|
||||
{
|
||||
struct pginfo **new, **old;
|
||||
int i, oldlen;
|
||||
size_t newlen, oldlen;
|
||||
|
||||
/* Make it this many pages */
|
||||
i = idx * sizeof *page_dir;
|
||||
i /= malloc_pagesize;
|
||||
i += 2;
|
||||
newlen = pageround(idx * sizeof *page_dir) + malloc_pagesize;
|
||||
|
||||
/* remember the old mapping size */
|
||||
oldlen = malloc_ninfo * sizeof *page_dir;
|
||||
@ -350,16 +348,15 @@ extend_pgdir(u_long idx)
|
||||
*/
|
||||
|
||||
/* Get new pages */
|
||||
new = (struct pginfo**) MMAP(i * malloc_pagesize);
|
||||
new = (struct pginfo**) MMAP(newlen);
|
||||
if (new == (struct pginfo **)-1)
|
||||
return 0;
|
||||
|
||||
/* Copy the old stuff */
|
||||
memcpy(new, page_dir,
|
||||
malloc_ninfo * sizeof *page_dir);
|
||||
memcpy(new, page_dir, oldlen);
|
||||
|
||||
/* register the new size */
|
||||
malloc_ninfo = i * malloc_pagesize / sizeof *page_dir;
|
||||
malloc_ninfo = newlen / sizeof *page_dir;
|
||||
|
||||
/* swap the pointers */
|
||||
old = page_dir;
|
||||
@ -383,7 +380,7 @@ malloc_init (void)
|
||||
/*
|
||||
* Compute page-size related variables.
|
||||
*/
|
||||
malloc_pagesize = sysconf(_SC_PAGESIZE);
|
||||
malloc_pagesize = (size_t)sysconf(_SC_PAGESIZE);
|
||||
malloc_pagemask = malloc_pagesize - 1;
|
||||
for (malloc_pageshift = 0;
|
||||
(1UL << malloc_pageshift) != malloc_pagesize;
|
||||
@ -468,7 +465,7 @@ malloc_init (void)
|
||||
* We need a maximum of malloc_pageshift buckets, steal these from the
|
||||
* front of the page_directory;
|
||||
*/
|
||||
malloc_origo = ((u_long)pageround((u_long)sbrk(0))) >> malloc_pageshift;
|
||||
malloc_origo = pageround((size_t)sbrk(0)) >> malloc_pageshift;
|
||||
malloc_origo -= malloc_pageshift;
|
||||
|
||||
malloc_ninfo = malloc_pagesize / sizeof *page_dir;
|
||||
@ -499,7 +496,7 @@ malloc_pages(size_t size)
|
||||
void *p, *delay_free = 0;
|
||||
int i;
|
||||
struct pgfree *pf;
|
||||
u_long idx;
|
||||
size_t idx;
|
||||
|
||||
size = pageround(size);
|
||||
|
||||
@ -584,7 +581,8 @@ malloc_make_chunks(int bits)
|
||||
{
|
||||
struct pginfo *bp;
|
||||
void *pp;
|
||||
int i, k, l;
|
||||
int i, k;
|
||||
size_t l;
|
||||
|
||||
/* Allocate a new bucket */
|
||||
pp = malloc_pages(malloc_pagesize);
|
||||
@ -618,7 +616,7 @@ malloc_make_chunks(int bits)
|
||||
|
||||
/* Do a bunch at a time */
|
||||
for(;k-i >= MALLOC_BITS; i += MALLOC_BITS)
|
||||
bp->bits[i / MALLOC_BITS] = ~0;
|
||||
bp->bits[i / MALLOC_BITS] = ~0U;
|
||||
|
||||
for(; i < k; i++)
|
||||
bp->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS);
|
||||
@ -651,7 +649,8 @@ malloc_make_chunks(int bits)
|
||||
static void *
|
||||
malloc_bytes(size_t size)
|
||||
{
|
||||
int i,j;
|
||||
size_t i;
|
||||
int j;
|
||||
u_int u;
|
||||
struct pginfo *bp;
|
||||
int k;
|
||||
@ -697,7 +696,7 @@ malloc_bytes(size_t size)
|
||||
k <<= bp->shift;
|
||||
|
||||
if (malloc_junk)
|
||||
memset((u_char*)bp->page + k, SOME_JUNK, bp->size);
|
||||
memset((u_char*)bp->page + k, SOME_JUNK, (size_t)bp->size);
|
||||
|
||||
return (u_char *)bp->page + k;
|
||||
}
|
||||
@ -736,9 +735,9 @@ static void *
|
||||
irealloc(void *ptr, size_t size)
|
||||
{
|
||||
void *p;
|
||||
u_long osize, idx;
|
||||
size_t osize, idx;
|
||||
struct pginfo **mp;
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
if (suicide)
|
||||
abort();
|
||||
@ -760,7 +759,7 @@ irealloc(void *ptr, size_t size)
|
||||
if (*mp == MALLOC_FIRST) { /* Page allocation */
|
||||
|
||||
/* Check the pointer */
|
||||
if ((u_long)ptr & malloc_pagemask) {
|
||||
if ((size_t)ptr & malloc_pagemask) {
|
||||
wrtwarning("modified (page-) pointer.\n");
|
||||
return 0;
|
||||
}
|
||||
@ -778,13 +777,13 @@ irealloc(void *ptr, size_t size)
|
||||
} else if (*mp >= MALLOC_MAGIC) { /* Chunk allocation */
|
||||
|
||||
/* Check the pointer for sane values */
|
||||
if (((u_long)ptr & ((*mp)->size-1))) {
|
||||
if (((size_t)ptr & ((*mp)->size-1))) {
|
||||
wrtwarning("modified (chunk-) pointer.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find the chunk index in the page */
|
||||
i = ((u_long)ptr & malloc_pagemask) >> (*mp)->shift;
|
||||
i = ((size_t)ptr & malloc_pagemask) >> (*mp)->shift;
|
||||
|
||||
/* Verify that it isn't a free chunk already */
|
||||
if ((*mp)->bits[i/MALLOC_BITS] & (1<<(i%MALLOC_BITS))) {
|
||||
@ -826,11 +825,11 @@ irealloc(void *ptr, size_t size)
|
||||
*/
|
||||
|
||||
static __inline__ void
|
||||
free_pages(void *ptr, int idx, struct pginfo *info)
|
||||
free_pages(void *ptr, size_t idx, struct pginfo *info)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
struct pgfree *pf, *pt=0;
|
||||
u_long l;
|
||||
size_t l;
|
||||
void *tail;
|
||||
|
||||
if (info == MALLOC_FREE) {
|
||||
@ -843,7 +842,7 @@ free_pages(void *ptr, int idx, struct pginfo *info)
|
||||
return;
|
||||
}
|
||||
|
||||
if ((u_long)ptr & malloc_pagemask) {
|
||||
if ((size_t)ptr & malloc_pagemask) {
|
||||
wrtwarning("modified (page-) pointer.\n");
|
||||
return;
|
||||
}
|
||||
@ -956,16 +955,16 @@ free_pages(void *ptr, int idx, struct pginfo *info)
|
||||
*/
|
||||
|
||||
static __inline__ void
|
||||
free_bytes(void *ptr, int idx, struct pginfo *info)
|
||||
free_bytes(void *ptr, size_t idx, struct pginfo *info)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
struct pginfo **mp;
|
||||
void *vp;
|
||||
|
||||
/* Find the chunk number on the page */
|
||||
i = ((u_long)ptr & malloc_pagemask) >> info->shift;
|
||||
i = ((size_t)ptr & malloc_pagemask) >> info->shift;
|
||||
|
||||
if (((u_long)ptr & (info->size-1))) {
|
||||
if (((size_t)ptr & (info->size-1))) {
|
||||
wrtwarning("modified (chunk-) pointer.\n");
|
||||
return;
|
||||
}
|
||||
@ -976,7 +975,7 @@ free_bytes(void *ptr, int idx, struct pginfo *info)
|
||||
}
|
||||
|
||||
if (malloc_junk)
|
||||
memset(ptr, SOME_JUNK, info->size);
|
||||
memset(ptr, SOME_JUNK, (size_t)info->size);
|
||||
|
||||
info->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS);
|
||||
info->free++;
|
||||
@ -1010,7 +1009,7 @@ free_bytes(void *ptr, int idx, struct pginfo *info)
|
||||
*mp = info->next;
|
||||
|
||||
/* Free the page & the info structure if need be */
|
||||
page_dir[ptr2idx(info->page)] = MALLOC_FIRST;
|
||||
page_dir[idx] = MALLOC_FIRST;
|
||||
vp = info->page; /* Order is important ! */
|
||||
if(vp != (void*)info)
|
||||
ifree(info);
|
||||
@ -1021,7 +1020,7 @@ static void
|
||||
ifree(void *ptr)
|
||||
{
|
||||
struct pginfo *info;
|
||||
int idx;
|
||||
size_t idx;
|
||||
|
||||
/* This is legal */
|
||||
if (!ptr)
|
||||
|
Loading…
Reference in New Issue
Block a user