1 2 /* $NetBSD: kmem.h,v 1.6 2010/02/21 01:46:36 darran Exp $ */ 3 4 /*- 5 * Copyright (c) 2009 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Andrew Doran. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef _OPENSOLARIS_SYS_KMEM_H_ 34 #define _OPENSOLARIS_SYS_KMEM_H_ 35 36 #include_next <sys/kmem.h> 37 #include_next <sys/pool.h> 38 #include_next <sys/vmem.h> 39 40 typedef void kmem_cache_t; 41 42 u_long kmem_size(void); 43 u_long kmem_used(void); 44 void kmem_reap(void); 45 46 void *calloc(size_t n, size_t s); 47 48 static inline kmem_cache_t * 49 kmem_cache_create(char *name, size_t bufsize, size_t align, 50 int (*constructor)(void *, void *, int), void (*destructor)(void *, void *), 51 void (*reclaim)(void *) __unused, void *private, vmem_t *vmp, int cflags) 52 { 53 pool_cache_t pc; 54 55 KASSERT(vmp == NULL); 56 57 pc = pool_cache_init(bufsize, align, 0, 0, name, NULL, IPL_NONE, 58 constructor, destructor, private); 59 if (pc != NULL && reclaim != NULL) { 60 pool_cache_set_drain_hook(pc, (void *)reclaim, private); 61 } 62 return pc; 63 } 64 65 #define kmem_cache_destroy(cache) pool_cache_destroy(cache) 66 #define kmem_cache_alloc(cache, flags) pool_cache_get(cache, flags) 67 #define kmem_cache_free(cache, buf) pool_cache_put(cache, buf) 68 #define kmem_cache_reap_now(cache) pool_cache_invalidate(cache) 69 70 #define KM_PUSHPAGE 0x00 /* XXXNETBSD */ 71 #define KMC_NODEBUG 0x00 72 73 #endif /* _OPENSOLARIS_SYS_KMEM_H_ */ 74