1168404Spjd/*
2168404Spjd * CDDL HEADER START
3168404Spjd *
4168404Spjd * The contents of this file are subject to the terms of the
5168404Spjd * Common Development and Distribution License, Version 1.0 only
6168404Spjd * (the "License").  You may not use this file except in compliance
7168404Spjd * with the License.
8168404Spjd *
9168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10168404Spjd * or http://www.opensolaris.org/os/licensing.
11168404Spjd * See the License for the specific language governing permissions
12168404Spjd * and limitations under the License.
13168404Spjd *
14168404Spjd * When distributing Covered Code, include this CDDL HEADER in each
15168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16168404Spjd * If applicable, add the following below this CDDL HEADER, with the
17168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying
18168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
19168404Spjd *
20168404Spjd * CDDL HEADER END
21178414Sjb *
22178414Sjb * $FreeBSD$
23168404Spjd */
24168404Spjd/*
25168404Spjd * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26168404Spjd * Use is subject to license terms.
27168404Spjd */
28168404Spjd
29168404Spjd#ifndef _UMEM_H
30168404Spjd#define	_UMEM_H
31168404Spjd
32168404Spjd
33168404Spjd
34168404Spjd#include <sys/types.h>
35168404Spjd#include <stdlib.h>
36168404Spjd
37168404Spjd#ifdef	__cplusplus
38168404Spjdextern "C" {
39168404Spjd#endif
40168404Spjd
41168404Spjd#define	UMEM_DEFAULT	0x0000	/* normal -- may fail */
42168404Spjd#define	UMEM_NOFAIL	0x0100	/* Never fails -- may call exit(2) */
43168404Spjd
44168404Spjd#define	UMEM_FLAGS	0xffff	/* all settable umem flags */
45168404Spjd
46168404Spjdextern void *umem_alloc(size_t, int);
47168404Spjdextern void *umem_alloc_align(size_t, size_t, int);
48168404Spjdextern void *umem_zalloc(size_t, int);
49168404Spjdextern void umem_free(void *, size_t);
50168404Spjdextern void umem_free_align(void *, size_t);
51168404Spjd
52168404Spjd/*
53168404Spjd * Flags for umem_cache_create()
54168404Spjd */
55168404Spjd#define	UMC_NOTOUCH	0x00010000
56168404Spjd#define	UMC_NODEBUG	0x00020000
57168404Spjd#define	UMC_NOMAGAZINE	0x00040000
58168404Spjd#define	UMC_NOHASH	0x00080000
59168404Spjd
60168404Spjdstruct umem_cache;		/* cache structure is opaque to umem clients */
61168404Spjd
62168404Spjdtypedef struct umem_cache umem_cache_t;
63168404Spjdtypedef int umem_constructor_t(void *, void *, int);
64168404Spjdtypedef void umem_destructor_t(void *, void *);
65168404Spjdtypedef void umem_reclaim_t(void *);
66168404Spjd
67168404Spjdtypedef int umem_nofail_callback_t(void);
68168404Spjd#define	UMEM_CALLBACK_RETRY		0
69168404Spjd#define	UMEM_CALLBACK_EXIT(status)	(0x100 | ((status) & 0xFF))
70168404Spjd
71168404Spjdextern void umem_nofail_callback(umem_nofail_callback_t *);
72168404Spjd
73168404Spjdextern umem_cache_t *umem_cache_create(char *, size_t,
74168404Spjd    size_t, umem_constructor_t *, umem_destructor_t *, umem_reclaim_t *,
75168404Spjd    void *, void *, int);
76168404Spjdextern void umem_cache_destroy(umem_cache_t *);
77168404Spjd
78168404Spjdextern void *umem_cache_alloc(umem_cache_t *, int);
79168404Spjdextern void umem_cache_free(umem_cache_t *, void *);
80168404Spjd
81168404Spjdextern void umem_reap(void);
82168404Spjd
83168404Spjd#ifdef	__cplusplus
84168404Spjd}
85168404Spjd#endif
86168404Spjd
87168404Spjd#endif	/* _UMEM_H */
88