diff options
-rw-r--r-- | sys/kern/kern_malloc.c | 40 | ||||
-rw-r--r-- | sys/sys/malloc.h | 14 |
2 files changed, 44 insertions, 10 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 3de5e17..1ced96a 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94 - * $Id: kern_malloc.c,v 1.47 1998/08/16 01:21:51 bde Exp $ + * $Id: kern_malloc.c,v 1.48 1998/10/25 17:44:51 phk Exp $ */ #include "opt_vm.h" @@ -53,12 +53,11 @@ #include <vm/vm_map.h> static void kmeminit __P((void *)); -static void malloc_init __P((struct malloc_type *)); SYSINIT(kmem, SI_SUB_KMEM, SI_ORDER_FIRST, kmeminit, NULL) static MALLOC_DEFINE(M_FREE, "free", "should be on free list"); -static struct malloc_type *kmemstatistics = M_FREE; +static struct malloc_type *kmemstatistics; static struct kmembuckets bucket[MINBUCKET + 16]; static struct kmemusage *kmemusage; static char *kmembase; @@ -432,14 +431,18 @@ kmeminit(dummy) } } -static void -malloc_init(type) - struct malloc_type *type; +void +malloc_init(data) + void *data; { + struct malloc_type *type = (struct malloc_type *)data; if (type->ks_magic != M_MAGIC) panic("malloc type lacks magic"); + if (type->ks_next) + return; + if (cnt.v_page_count == 0) panic("malloc_init not allowed before vm init"); @@ -451,3 +454,28 @@ malloc_init(type) type->ks_next = kmemstatistics; kmemstatistics = type; } + +void +malloc_uninit(data) + void *data; +{ + struct malloc_type *type = (struct malloc_type *)data; + struct malloc_type *t; + + if (type->ks_magic != M_MAGIC) + panic("malloc type lacks magic"); + + if (cnt.v_page_count == 0) + panic("malloc_uninit not allowed before vm init"); + + if (type == kmemstatistics) + kmemstatistics = type->ks_next; + else { + for (t = kmemstatistics; t->ks_next != NULL; t = t->ks_next) { + if (t->ks_next == type) { + t->ks_next = type->ks_next; + break; + } + } + } +} diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h index a04c688..d8e0cd8 100644 --- a/sys/sys/malloc.h +++ b/sys/sys/malloc.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)malloc.h 8.5 (Berkeley) 5/3/95 - * $Id: malloc.h,v 1.36 1997/12/27 09:42:03 bde Exp $ + * $Id: malloc.h,v 1.37 1998/03/08 09:58:26 julian Exp $ */ #ifndef _SYS_MALLOC_H_ @@ -64,15 +64,20 @@ struct malloc_type { u_short ks_mapblocks; /* number of times blocked for kernel map */ }; +#ifdef KERNEL + +void malloc_init __P((void *)); +void malloc_uninit __P((void *)); + #define MALLOC_DEFINE(type, shortdesc, longdesc) \ struct malloc_type type[1] = { \ { NULL, 0, 0, 0, 0, 0, 0, M_MAGIC, shortdesc, 0, 0 } \ }; \ - struct __hack + SYSINIT(type##_init, SI_SUB_KMEM, SI_ORDER_ANY, malloc_init, type); \ + SYSUNINIT(type##_uninit, SI_SUB_KMEM, SI_ORDER_ANY, malloc_uninit, type) #define MALLOC_DECLARE(type) \ - extern struct malloc_type type[1]; \ - struct __hack + extern struct malloc_type type[1] #ifdef MALLOC_INSTANTIATE #define MALLOC_MAKE_TYPE(type, shortdesc, longdesc) \ @@ -85,6 +90,7 @@ struct malloc_type { MALLOC_MAKE_TYPE(M_CACHE, "namecache", "Dynamically allocated cache entries"); MALLOC_MAKE_TYPE(M_DEVBUF, "devbuf", "device driver memory"); MALLOC_MAKE_TYPE(M_TEMP, "temp", "misc temporary data buffers"); +#endif /* KERNEL */ /* * Array of descriptors that describe the contents of each page |