1 /*- 2 * Copyright (C) 2006 Jason Evans <jasone@FreeBSD.org>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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 15 * distribution. 16 * 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. 28 * 29 * $FreeBSD$ 30 */ 31 32 #ifndef _MALLOC_NP_H_ 33 #define _MALLOC_NP_H_ 34 #include <sys/cdefs.h> 35 #include <sys/types.h> 36 #include <strings.h> 37 38 __BEGIN_DECLS 39 typedef void *(chunk_alloc_t)(void *, size_t, size_t, bool *, bool *, unsigned); 40 typedef bool (chunk_dalloc_t)(void *, size_t, bool, unsigned); 41 typedef bool (chunk_commit_t)(void *, size_t, size_t, size_t, unsigned); 42 typedef bool (chunk_decommit_t)(void *, size_t, size_t, size_t, unsigned); 43 typedef bool (chunk_purge_t)(void *, size_t, size_t, size_t, unsigned); 44 typedef bool (chunk_split_t)(void *, size_t, size_t, size_t, bool, unsigned); 45 typedef bool (chunk_merge_t)(void *, size_t, void *, size_t, bool, unsigned); 46 typedef struct { 47 chunk_alloc_t *alloc; 48 chunk_dalloc_t *dalloc; 49 chunk_commit_t *commit; 50 chunk_decommit_t *decommit; 51 chunk_purge_t *purge; 52 chunk_split_t *split; 53 chunk_merge_t *merge; 54 } chunk_hooks_t; 55 56 size_t malloc_usable_size(const void *ptr); 57 58 void malloc_stats_print(void (*write_cb)(void *, const char *), 59 void *cbopaque, const char *opts); 60 int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, 61 size_t newlen); 62 int mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp); 63 int mallctlbymib(const size_t *mib, size_t miblen, void *oldp, 64 size_t *oldlenp, void *newp, size_t newlen); 65 66 #define MALLOCX_LG_ALIGN(la) (la) 67 #define MALLOCX_ALIGN(a) (ffsl(a)-1) 68 #define MALLOCX_ZERO ((int)0x40) 69 #define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8)) 70 #define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1) 71 #define MALLOCX_ARENA(a) ((int)(((a)+1) << 20)) 72 73 void *mallocx(size_t size, int flags); 74 void *rallocx(void *ptr, size_t size, int flags); 75 size_t xallocx(void *ptr, size_t size, size_t extra, int flags); 76 size_t sallocx(const void *ptr, int flags); 77 void dallocx(void *ptr, int flags); 78 void sdallocx(void *ptr, size_t size, int flags); 79 size_t nallocx(size_t size, int flags); 80 81 void * __calloc(size_t number, size_t size) __malloc_like; 82 void * __malloc(size_t size) __malloc_like; 83 void * __realloc(void *ptr, size_t size); 84 void __free(void *ptr); 85 int __posix_memalign(void **ptr, size_t alignment, size_t size); 86 void *__aligned_alloc(size_t alignment, size_t size); 87 size_t __malloc_usable_size(const void *ptr); 88 void *__mallocx(size_t size, int flags); 89 void *__rallocx(void *ptr, size_t size, int flags); 90 size_t __xallocx(void *ptr, size_t size, size_t extra, int flags); 91 size_t __sallocx(const void *ptr, int flags); 92 void __dallocx(void *ptr, int flags); 93 void __sdallocx(void *ptr, size_t size, int flags); 94 size_t __nallocx(size_t size, int flags); 95 __END_DECLS 96 97 #endif /* _MALLOC_NP_H_ */ 98