2 * Copyright (C) 2006 Jason Evans <jasone@FreeBSD.org>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice(s), this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified other than the possible
11 * addition of one or more copyright notices.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice(s), this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 #include <sys/types.h>
40 typedef struct extent_hooks_s extent_hooks_t;
41 typedef void *(extent_alloc_t)(extent_hooks_t *, void *, size_t, size_t, bool *,
43 typedef bool (extent_dalloc_t)(extent_hooks_t *, void *, size_t, bool,
45 typedef void (extent_destroy_t)(extent_hooks_t *, void *, size_t, bool,
47 typedef bool (extent_commit_t)(extent_hooks_t *, void *, size_t, size_t, size_t,
49 typedef bool (extent_decommit_t)(extent_hooks_t *, void *, size_t, size_t,
51 typedef bool (extent_purge_t)(extent_hooks_t *, void *, size_t, size_t, size_t,
53 typedef bool (extent_split_t)(extent_hooks_t *, void *, size_t, size_t, size_t,
55 typedef bool (extent_merge_t)(extent_hooks_t *, void *, size_t, void *, size_t,
57 struct extent_hooks_s {
58 extent_alloc_t *alloc;
59 extent_dalloc_t *dalloc;
60 extent_destroy_t *destroy;
61 extent_commit_t *commit;
62 extent_decommit_t *decommit;
63 extent_purge_t *purge_lazy;
64 extent_purge_t *purge_forced;
65 extent_split_t *split;
66 extent_merge_t *merge;
69 size_t malloc_usable_size(const void *ptr);
71 void malloc_stats_print(void (*write_cb)(void *, const char *),
72 void *cbopaque, const char *opts);
74 #define MALLCTL_ARENAS_ALL 4096
75 #define MALLCTL_ARENAS_DESTROYED 4097
77 int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
79 int mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
80 int mallctlbymib(const size_t *mib, size_t miblen, void *oldp,
81 size_t *oldlenp, void *newp, size_t newlen);
83 #define MALLOCX_LG_ALIGN(la) ((int)(la))
84 #define MALLOCX_ALIGN(a) ((int)(ffsl((int)(a))-1))
85 #define MALLOCX_ZERO ((int)0x40)
86 #define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8))
87 #define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1)
88 #define MALLOCX_ARENA(a) ((((int)(a))+1) << 20)
90 void *mallocx(size_t size, int flags);
91 void *rallocx(void *ptr, size_t size, int flags);
92 size_t xallocx(void *ptr, size_t size, size_t extra, int flags);
93 size_t sallocx(const void *ptr, int flags);
94 void dallocx(void *ptr, int flags);
95 void sdallocx(void *ptr, size_t size, int flags);
96 size_t nallocx(size_t size, int flags);
98 void * __calloc(size_t number, size_t size) __malloc_like;
99 void * __malloc(size_t size) __malloc_like;
100 void * __realloc(void *ptr, size_t size);
101 void __free(void *ptr);
102 int __posix_memalign(void **ptr, size_t alignment, size_t size);
103 void *__aligned_alloc(size_t alignment, size_t size);
104 size_t __malloc_usable_size(const void *ptr);
105 void __malloc_stats_print(void (*write_cb)(void *, const char *),
106 void *cbopaque, const char *opts);
107 int __mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
109 int __mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
110 int __mallctlbymib(const size_t *mib, size_t miblen, void *oldp,
111 size_t *oldlenp, void *newp, size_t newlen);
112 void *__mallocx(size_t size, int flags);
113 void *__rallocx(void *ptr, size_t size, int flags);
114 size_t __xallocx(void *ptr, size_t size, size_t extra, int flags);
115 size_t __sallocx(const void *ptr, int flags);
116 void __dallocx(void *ptr, int flags);
117 void __sdallocx(void *ptr, size_t size, int flags);
118 size_t __nallocx(size_t size, int flags);
121 #endif /* _MALLOC_NP_H_ */