From 8308eb1f7a8f77840c80afb1b0a3172837780f18 Mon Sep 17 00:00:00 2001 From: yamt Date: Sun, 25 Jun 2006 08:10:04 +0000 Subject: [PATCH] implement kmem_zalloc. --- sys/kern/subr_kmem.c | 22 ++++++++++++++++++++-- sys/sys/kmem.h | 3 ++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/sys/kern/subr_kmem.c b/sys/kern/subr_kmem.c index 3028a88c07e3..a391268e4b85 100644 --- a/sys/kern/subr_kmem.c +++ b/sys/kern/subr_kmem.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_kmem.c,v 1.1 2006/06/25 08:00:01 yamt Exp $ */ +/* $NetBSD: subr_kmem.c,v 1.2 2006/06/25 08:10:04 yamt Exp $ */ /*- * Copyright (c)2006 YAMAMOTO Takashi, @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.1 2006/06/25 08:00:01 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.2 2006/06/25 08:10:04 yamt Exp $"); #include #include @@ -85,6 +85,24 @@ kmem_alloc(size_t size, km_flag_t kmflags) kmf_to_vmf(kmflags) | VM_INSTANTFIT); } +/* + * kmem_zalloc: allocate wired memory. + * + * => must not be called from interrupt context. + */ + +void * +kmem_zalloc(size_t size, km_flag_t kmflags) +{ + void *p; + + p = kmem_alloc(size, kmflags); + if (p != NULL) { + memset(p, 0, size); + } + return p; +} + /* * kmem_free: free wired memory allocated by kmem_alloc. * diff --git a/sys/sys/kmem.h b/sys/sys/kmem.h index 6057e5ee9947..1e89cc1aaaf8 100644 --- a/sys/sys/kmem.h +++ b/sys/sys/kmem.h @@ -1,4 +1,4 @@ -/* $NetBSD: kmem.h,v 1.1 2006/06/25 08:00:01 yamt Exp $ */ +/* $NetBSD: kmem.h,v 1.2 2006/06/25 08:10:04 yamt Exp $ */ /*- * Copyright (c)2006 YAMAMOTO Takashi, @@ -34,6 +34,7 @@ typedef unsigned int km_flag_t; void *kmem_alloc(size_t, km_flag_t); +void *kmem_zalloc(size_t, km_flag_t); void kmem_free(void *, size_t); void kmem_init(void); size_t kmem_roundup_size(size_t);