|
@ -8,7 +8,7 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
static char rcsid[] = "$OpenBSD: malloc.c,v 1.58 2003/07/19 23:52:27 tdeval Exp $"; |
|
|
|
|
|
|
|
|
static char rcsid[] = "$OpenBSD: malloc.c,v 1.59 2003/08/04 16:51:49 jfb Exp $"; |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
@ -250,8 +250,7 @@ static void *malloc_bytes(size_t size); |
|
|
|
|
|
|
|
|
#ifdef MALLOC_STATS |
|
|
#ifdef MALLOC_STATS |
|
|
void |
|
|
void |
|
|
malloc_dump(fd) |
|
|
|
|
|
FILE *fd; |
|
|
|
|
|
|
|
|
malloc_dump(FILE *fd) |
|
|
{ |
|
|
{ |
|
|
struct pginfo **pd; |
|
|
struct pginfo **pd; |
|
|
struct pgfree *pf; |
|
|
struct pgfree *pf; |
|
@ -310,8 +309,7 @@ malloc_dump(fd) |
|
|
extern char *__progname; |
|
|
extern char *__progname; |
|
|
|
|
|
|
|
|
static void |
|
|
static void |
|
|
wrterror(p) |
|
|
|
|
|
char *p; |
|
|
|
|
|
|
|
|
wrterror(char *p) |
|
|
{ |
|
|
{ |
|
|
char *q = " error: "; |
|
|
char *q = " error: "; |
|
|
struct iovec iov[4]; |
|
|
struct iovec iov[4]; |
|
@ -335,8 +333,7 @@ wrterror(p) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void |
|
|
static void |
|
|
wrtwarning(p) |
|
|
|
|
|
char *p; |
|
|
|
|
|
|
|
|
wrtwarning(char *p) |
|
|
{ |
|
|
{ |
|
|
char *q = " warning: "; |
|
|
char *q = " warning: "; |
|
|
struct iovec iov[4]; |
|
|
struct iovec iov[4]; |
|
@ -359,7 +356,7 @@ wrtwarning(p) |
|
|
|
|
|
|
|
|
#ifdef MALLOC_STATS |
|
|
#ifdef MALLOC_STATS |
|
|
static void |
|
|
static void |
|
|
malloc_exit() |
|
|
|
|
|
|
|
|
malloc_exit(void) |
|
|
{ |
|
|
{ |
|
|
FILE *fd = fopen("malloc.out", "a"); |
|
|
FILE *fd = fopen("malloc.out", "a"); |
|
|
char *q = "malloc() warning: Couldn't dump stats.\n"; |
|
|
char *q = "malloc() warning: Couldn't dump stats.\n"; |
|
@ -376,8 +373,7 @@ malloc_exit() |
|
|
* Allocate a number of pages from the OS |
|
|
* Allocate a number of pages from the OS |
|
|
*/ |
|
|
*/ |
|
|
static void * |
|
|
static void * |
|
|
map_pages(pages) |
|
|
|
|
|
size_t pages; |
|
|
|
|
|
|
|
|
map_pages(size_t pages) |
|
|
{ |
|
|
{ |
|
|
caddr_t result, tail; |
|
|
caddr_t result, tail; |
|
|
|
|
|
|
|
@ -412,8 +408,7 @@ map_pages(pages) |
|
|
* Extend page directory |
|
|
* Extend page directory |
|
|
*/ |
|
|
*/ |
|
|
static int |
|
|
static int |
|
|
extend_pgdir(index) |
|
|
|
|
|
u_long index; |
|
|
|
|
|
|
|
|
extend_pgdir(u_long index) |
|
|
{ |
|
|
{ |
|
|
struct pginfo **new, **old; |
|
|
struct pginfo **new, **old; |
|
|
size_t i, oldlen; |
|
|
size_t i, oldlen; |
|
@ -466,7 +461,7 @@ extend_pgdir(index) |
|
|
* Initialize the world |
|
|
* Initialize the world |
|
|
*/ |
|
|
*/ |
|
|
static void |
|
|
static void |
|
|
malloc_init () |
|
|
|
|
|
|
|
|
malloc_init(void) |
|
|
{ |
|
|
{ |
|
|
char *p, b[64]; |
|
|
char *p, b[64]; |
|
|
int i, j; |
|
|
int i, j; |
|
@ -584,8 +579,7 @@ malloc_init () |
|
|
* Allocate a number of complete pages |
|
|
* Allocate a number of complete pages |
|
|
*/ |
|
|
*/ |
|
|
static void * |
|
|
static void * |
|
|
malloc_pages(size) |
|
|
|
|
|
size_t size; |
|
|
|
|
|
|
|
|
malloc_pages(size_t size) |
|
|
{ |
|
|
{ |
|
|
void *p, *delay_free = NULL; |
|
|
void *p, *delay_free = NULL; |
|
|
int i; |
|
|
int i; |
|
@ -670,8 +664,7 @@ malloc_pages(size) |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
static __inline__ int |
|
|
static __inline__ int |
|
|
malloc_make_chunks(bits) |
|
|
|
|
|
int bits; |
|
|
|
|
|
|
|
|
malloc_make_chunks(int bits) |
|
|
{ |
|
|
{ |
|
|
struct pginfo *bp; |
|
|
struct pginfo *bp; |
|
|
void *pp; |
|
|
void *pp; |
|
@ -765,8 +758,7 @@ malloc_make_chunks(bits) |
|
|
* Allocate a fragment |
|
|
* Allocate a fragment |
|
|
*/ |
|
|
*/ |
|
|
static void * |
|
|
static void * |
|
|
malloc_bytes(size) |
|
|
|
|
|
size_t size; |
|
|
|
|
|
|
|
|
malloc_bytes(size_t size) |
|
|
{ |
|
|
{ |
|
|
int i,j; |
|
|
int i,j; |
|
|
u_long u; |
|
|
u_long u; |
|
@ -828,8 +820,7 @@ malloc_bytes(size) |
|
|
* Allocate a piece of memory |
|
|
* Allocate a piece of memory |
|
|
*/ |
|
|
*/ |
|
|
static void * |
|
|
static void * |
|
|
imalloc(size) |
|
|
|
|
|
size_t size; |
|
|
|
|
|
|
|
|
imalloc(size_t size) |
|
|
{ |
|
|
{ |
|
|
void *result; |
|
|
void *result; |
|
|
|
|
|
|
|
@ -861,9 +852,7 @@ imalloc(size) |
|
|
* Change the size of an allocation. |
|
|
* Change the size of an allocation. |
|
|
*/ |
|
|
*/ |
|
|
static void * |
|
|
static void * |
|
|
irealloc(ptr, size) |
|
|
|
|
|
void *ptr; |
|
|
|
|
|
size_t size; |
|
|
|
|
|
|
|
|
irealloc(void *ptr, size_t size) |
|
|
{ |
|
|
{ |
|
|
void *p; |
|
|
void *p; |
|
|
u_long osize, index; |
|
|
u_long osize, index; |
|
@ -966,10 +955,7 @@ irealloc(ptr, size) |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
static __inline__ void |
|
|
static __inline__ void |
|
|
free_pages(ptr, index, info) |
|
|
|
|
|
void *ptr; |
|
|
|
|
|
int index; |
|
|
|
|
|
struct pginfo *info; |
|
|
|
|
|
|
|
|
free_pages(void *ptr, int index, struct pginfo *info) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
struct pgfree *pf, *pt=NULL; |
|
|
struct pgfree *pf, *pt=NULL; |
|
@ -1104,10 +1090,7 @@ free_pages(ptr, index, info) |
|
|
|
|
|
|
|
|
/* ARGSUSED */ |
|
|
/* ARGSUSED */ |
|
|
static __inline__ void |
|
|
static __inline__ void |
|
|
free_bytes(ptr, index, info) |
|
|
|
|
|
void *ptr; |
|
|
|
|
|
int index; |
|
|
|
|
|
struct pginfo *info; |
|
|
|
|
|
|
|
|
free_bytes(void *ptr, int index, struct pginfo *info) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
struct pginfo **mp; |
|
|
struct pginfo **mp; |
|
@ -1178,8 +1161,7 @@ free_bytes(ptr, index, info) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void |
|
|
static void |
|
|
ifree(ptr) |
|
|
|
|
|
void *ptr; |
|
|
|
|
|
|
|
|
ifree(void *ptr) |
|
|
{ |
|
|
{ |
|
|
struct pginfo *info; |
|
|
struct pginfo *info; |
|
|
int index; |
|
|
int index; |
|
|