1234370Sjasone/*
2234370Sjasone * CDDL HEADER START
3234370Sjasone *
4234370Sjasone * The contents of this file are subject to the terms of the
5234370Sjasone * Common Development and Distribution License, Version 1.0 only
6234370Sjasone * (the "License").  You may not use this file except in compliance
7234370Sjasone * with the License.
8234370Sjasone *
9234370Sjasone * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10234370Sjasone * or http://www.opensolaris.org/os/licensing.
11234370Sjasone * See the License for the specific language governing permissions
12234370Sjasone * and limitations under the License.
13234370Sjasone *
14234370Sjasone * When distributing Covered Code, include this CDDL HEADER in each
15234370Sjasone * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16234370Sjasone * If applicable, add the following below this CDDL HEADER, with the
17234370Sjasone * fields enclosed by brackets "[]" replaced with your own identifying
18234370Sjasone * information: Portions Copyright [yyyy] [name of copyright owner]
19234370Sjasone *
20234370Sjasone * CDDL HEADER END
21234370Sjasone *
22234370Sjasone * $FreeBSD: releng/11.0/cddl/compat/opensolaris/lib/libumem/umem.h 178414 2008-04-22 07:43:00Z jb $
23234370Sjasone */
24234370Sjasone/*
25234370Sjasone * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26234370Sjasone * Use is subject to license terms.
27234370Sjasone */
28234370Sjasone
29234370Sjasone#ifndef _UMEM_H
30234370Sjasone#define	_UMEM_H
31234370Sjasone
32234370Sjasone
33234370Sjasone
34234370Sjasone#include <sys/types.h>
35234370Sjasone#include <stdlib.h>
36234370Sjasone
37234370Sjasone#ifdef	__cplusplus
38234370Sjasoneextern "C" {
39234370Sjasone#endif
40234370Sjasone
41234370Sjasone#define	UMEM_DEFAULT	0x0000	/* normal -- may fail */
42234370Sjasone#define	UMEM_NOFAIL	0x0100	/* Never fails -- may call exit(2) */
43234370Sjasone
44234370Sjasone#define	UMEM_FLAGS	0xffff	/* all settable umem flags */
45234370Sjasone
46234370Sjasoneextern void *umem_alloc(size_t, int);
47234370Sjasoneextern void *umem_alloc_align(size_t, size_t, int);
48234370Sjasoneextern void *umem_zalloc(size_t, int);
49234370Sjasoneextern void umem_free(void *, size_t);
50234370Sjasoneextern void umem_free_align(void *, size_t);
51234370Sjasone
52234370Sjasone/*
53234370Sjasone * Flags for umem_cache_create()
54234370Sjasone */
55234370Sjasone#define	UMC_NOTOUCH	0x00010000
56234370Sjasone#define	UMC_NODEBUG	0x00020000
57234370Sjasone#define	UMC_NOMAGAZINE	0x00040000
58234370Sjasone#define	UMC_NOHASH	0x00080000
59234370Sjasone
60234370Sjasonestruct umem_cache;		/* cache structure is opaque to umem clients */
61234370Sjasone
62234370Sjasonetypedef struct umem_cache umem_cache_t;
63234370Sjasonetypedef int umem_constructor_t(void *, void *, int);
64234370Sjasonetypedef void umem_destructor_t(void *, void *);
65234370Sjasonetypedef void umem_reclaim_t(void *);
66234370Sjasone
67234370Sjasonetypedef int umem_nofail_callback_t(void);
68234370Sjasone#define	UMEM_CALLBACK_RETRY		0
69234370Sjasone#define	UMEM_CALLBACK_EXIT(status)	(0x100 | ((status) & 0xFF))
70234370Sjasone
71234370Sjasoneextern void umem_nofail_callback(umem_nofail_callback_t *);
72234370Sjasone
73234370Sjasoneextern umem_cache_t *umem_cache_create(char *, size_t,
74234370Sjasone    size_t, umem_constructor_t *, umem_destructor_t *, umem_reclaim_t *,
75234370Sjasone    void *, void *, int);
76234370Sjasoneextern void umem_cache_destroy(umem_cache_t *);
77234370Sjasone
78234370Sjasoneextern void *umem_cache_alloc(umem_cache_t *, int);
79234370Sjasoneextern void umem_cache_free(umem_cache_t *, void *);
80234370Sjasone
81234370Sjasoneextern void umem_reap(void);
82234370Sjasone
83234370Sjasone#ifdef	__cplusplus
84234370Sjasone}
85234370Sjasone#endif
86234370Sjasone
87234370Sjasone#endif	/* _UMEM_H */
88234370Sjasone