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 void *(chunk_alloc_t)(void *, size_t, size_t, bool *, bool *, unsigned);
41 typedef bool (chunk_dalloc_t)(void *, size_t, bool, unsigned);
42 typedef bool (chunk_commit_t)(void *, size_t, size_t, size_t, unsigned);
43 typedef bool (chunk_decommit_t)(void *, size_t, size_t, size_t, unsigned);
44 typedef bool (chunk_purge_t)(void *, size_t, size_t, size_t, unsigned);
45 typedef bool (chunk_split_t)(void *, size_t, size_t, size_t, bool, unsigned);
46 typedef bool (chunk_merge_t)(void *, size_t, void *, size_t, bool, unsigned);
49 chunk_dalloc_t *dalloc;
50 chunk_commit_t *commit;
51 chunk_decommit_t *decommit;
57 size_t malloc_usable_size(const void *ptr);
59 void malloc_stats_print(void (*write_cb)(void *, const char *),
60 void *cbopaque, const char *opts);
61 int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
63 int mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
64 int mallctlbymib(const size_t *mib, size_t miblen, void *oldp,
65 size_t *oldlenp, void *newp, size_t newlen);
67 #define MALLOCX_LG_ALIGN(la) (la)
68 #define MALLOCX_ALIGN(a) (ffsl(a)-1)
69 #define MALLOCX_ZERO ((int)0x40)
70 #define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8))
71 #define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1)
72 #define MALLOCX_ARENA(a) ((int)(((a)+1) << 20))
74 void *mallocx(size_t size, int flags);
75 void *rallocx(void *ptr, size_t size, int flags);
76 size_t xallocx(void *ptr, size_t size, size_t extra, int flags);
77 size_t sallocx(const void *ptr, int flags);
78 void dallocx(void *ptr, int flags);
79 void sdallocx(void *ptr, size_t size, int flags);
80 size_t nallocx(size_t size, int flags);
82 void * __calloc(size_t number, size_t size) __malloc_like;
83 void * __malloc(size_t size) __malloc_like;
84 void * __realloc(void *ptr, size_t size);
85 void __free(void *ptr);
86 int __posix_memalign(void **ptr, size_t alignment, size_t size);
87 void *__aligned_alloc(size_t alignment, size_t size);
88 size_t __malloc_usable_size(const void *ptr);
89 void __malloc_stats_print(void (*write_cb)(void *, const char *),
90 void *cbopaque, const char *opts);
91 int __mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
93 int __mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
94 int __mallctlbymib(const size_t *mib, size_t miblen, void *oldp,
95 size_t *oldlenp, void *newp, size_t newlen);
96 void *__mallocx(size_t size, int flags);
97 void *__rallocx(void *ptr, size_t size, int flags);
98 size_t __xallocx(void *ptr, size_t size, size_t extra, int flags);
99 size_t __sallocx(const void *ptr, int flags);
100 void __dallocx(void *ptr, int flags);
101 void __sdallocx(void *ptr, size_t size, int flags);
102 size_t __nallocx(size_t size, int flags);
105 #endif /* _MALLOC_NP_H_ */