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