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 <stdbool.h> 37 #include <strings.h> 38 39 __BEGIN_DECLS 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); 47 typedef struct { 48 chunk_alloc_t *alloc; 49 chunk_dalloc_t *dalloc; 50 chunk_commit_t *commit; 51 chunk_decommit_t *decommit; 52 chunk_purge_t *purge; 53 chunk_split_t *split; 54 chunk_merge_t *merge; 55 } chunk_hooks_t; 56 57 size_t malloc_usable_size(const void *ptr); 58 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, 62 size_t newlen); 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); 66 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)) 73 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); 81 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 *__mallocx(size_t size, int flags); 90 void *__rallocx(void *ptr, size_t size, int flags); 91 size_t __xallocx(void *ptr, size_t size, size_t extra, int flags); 92 size_t __sallocx(const void *ptr, int flags); 93 void __dallocx(void *ptr, int flags); 94 void __sdallocx(void *ptr, size_t size, int flags); 95 size_t __nallocx(size_t size, int flags); 96 __END_DECLS 97 98 #endif /* _MALLOC_NP_H_ */ 99