xref: /netbsd-src/sys/sys/kmem.h (revision 62be88ee264890a442b7e92f4effe8c755d76c7a)
1*62be88eeSthorpej /*	$NetBSD: kmem.h,v 1.12 2021/01/24 17:29:11 thorpej Exp $	*/
2bc497781Syamt 
3bc497781Syamt /*-
4bc497781Syamt  * Copyright (c)2006 YAMAMOTO Takashi,
5bc497781Syamt  * All rights reserved.
6bc497781Syamt  *
7bc497781Syamt  * Redistribution and use in source and binary forms, with or without
8bc497781Syamt  * modification, are permitted provided that the following conditions
9bc497781Syamt  * are met:
10bc497781Syamt  * 1. Redistributions of source code must retain the above copyright
11bc497781Syamt  *    notice, this list of conditions and the following disclaimer.
12bc497781Syamt  * 2. Redistributions in binary form must reproduce the above copyright
13bc497781Syamt  *    notice, this list of conditions and the following disclaimer in the
14bc497781Syamt  *    documentation and/or other materials provided with the distribution.
15bc497781Syamt  *
16bc497781Syamt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17bc497781Syamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18bc497781Syamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19bc497781Syamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20bc497781Syamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21bc497781Syamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22bc497781Syamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23bc497781Syamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24bc497781Syamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25bc497781Syamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26bc497781Syamt  * SUCH DAMAGE.
27bc497781Syamt  */
28bc497781Syamt 
29bc497781Syamt #ifndef _SYS_KMEM_H_
30bc497781Syamt #define	_SYS_KMEM_H_
31bc497781Syamt 
32bc497781Syamt #include <sys/types.h>
33bc497781Syamt 
34bc497781Syamt typedef unsigned int km_flag_t;
35bc497781Syamt 
368effb66eSrmind void	kmem_init(void);
378effb66eSrmind size_t	kmem_roundup_size(size_t);
388effb66eSrmind 
39bc497781Syamt void *	kmem_alloc(size_t, km_flag_t);
408308eb1fSyamt void *	kmem_zalloc(size_t, km_flag_t);
41bc497781Syamt void	kmem_free(void *, size_t);
42e62ee4d4Spara 
438effb66eSrmind void *	kmem_intr_alloc(size_t, km_flag_t);
448effb66eSrmind void *	kmem_intr_zalloc(size_t, km_flag_t);
4502bf188bSrmind void	kmem_intr_free(void *, size_t);
46bc497781Syamt 
4764afb694Schristos char *	kmem_asprintf(const char *, ...) __printflike(1, 2);
488effb66eSrmind 
493afe107bSchristos char *	kmem_strdupsize(const char *, size_t *, km_flag_t);
50c4daf5eaSchristos #define kmem_strdup(s, f)	kmem_strdupsize((s), NULL, (f))
51c4daf5eaSchristos char *	kmem_strndup(const char *, size_t, km_flag_t);
523afe107bSchristos void	kmem_strfree(char *);
533afe107bSchristos 
54*62be88eeSthorpej void *	kmem_tmpbuf_alloc(size_t, void *, size_t, km_flag_t);
55*62be88eeSthorpej void	kmem_tmpbuf_free(void *, size_t, void *);
56*62be88eeSthorpej 
5731224ff9Sad /*
588effb66eSrmind  * km_flag_t values:
5931224ff9Sad  */
60bc497781Syamt #define	KM_SLEEP	0x00000001	/* can sleep */
61bc497781Syamt #define	KM_NOSLEEP	0x00000002	/* don't sleep */
62bc497781Syamt 
63bc497781Syamt #endif /* !_SYS_KMEM_H_ */
64