1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 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 32#ifndef _MALLOC_NP_H_ 33#define _MALLOC_NP_H_ 34 35#include <sys/types.h> 36 37#ifdef __cplusplus 38#define __MyBool bool 39#else 40#define __MyBool _Bool 41#endif 42 43__BEGIN_DECLS 44typedef struct extent_hooks_s extent_hooks_t; 45typedef void *(extent_alloc_t)(extent_hooks_t *, void *, size_t, size_t, 46 __MyBool *, __MyBool *, unsigned); 47typedef __MyBool (extent_dalloc_t)(extent_hooks_t *, void *, size_t, __MyBool, 48 unsigned); 49typedef void (extent_destroy_t)(extent_hooks_t *, void *, size_t, __MyBool, 50 unsigned); 51typedef __MyBool (extent_commit_t)(extent_hooks_t *, void *, size_t, size_t, 52 size_t, unsigned); 53typedef __MyBool (extent_decommit_t)(extent_hooks_t *, void *, size_t, size_t, 54 size_t, unsigned); 55typedef __MyBool (extent_purge_t)(extent_hooks_t *, void *, size_t, size_t, size_t, 56 unsigned); 57typedef __MyBool (extent_split_t)(extent_hooks_t *, void *, size_t, size_t, size_t, 58 __MyBool, unsigned); 59typedef __MyBool (extent_merge_t)(extent_hooks_t *, void *, size_t, void *, size_t, 60 __MyBool, unsigned); 61struct extent_hooks_s { 62 extent_alloc_t *alloc; 63 extent_dalloc_t *dalloc; 64 extent_destroy_t *destroy; 65 extent_commit_t *commit; 66 extent_decommit_t *decommit; 67 extent_purge_t *purge_lazy; 68 extent_purge_t *purge_forced; 69 extent_split_t *split; 70 extent_merge_t *merge; 71}; 72 73size_t malloc_usable_size(const void *ptr); 74 75void malloc_stats_print(void (*write_cb)(void *, const char *), 76 void *cbopaque, const char *opts); 77 78#define MALLCTL_ARENAS_ALL 4096 79#define MALLCTL_ARENAS_DESTROYED 4097 80 81int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, 82 size_t newlen); 83int mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp); 84int mallctlbymib(const size_t *mib, size_t miblen, void *oldp, 85 size_t *oldlenp, void *newp, size_t newlen); 86 87#define MALLOCX_LG_ALIGN(la) ((int)(la)) 88#define MALLOCX_ALIGN(a) ((int)(ffsl((int)(a))-1)) 89#define MALLOCX_ZERO ((int)0x40) 90#define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8)) 91#define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1) 92#define MALLOCX_ARENA(a) ((((int)(a))+1) << 20) 93 94void *mallocx(size_t size, int flags); 95void *rallocx(void *ptr, size_t size, int flags); 96size_t xallocx(void *ptr, size_t size, size_t extra, int flags); 97size_t sallocx(const void *ptr, int flags); 98void dallocx(void *ptr, int flags); 99void sdallocx(void *ptr, size_t size, int flags); 100size_t nallocx(size_t size, int flags); 101 102void * __calloc(size_t number, size_t size) __malloc_like; 103void * __malloc(size_t size) __malloc_like; 104void * __realloc(void *ptr, size_t size); 105void __free(void *ptr); 106int __posix_memalign(void **ptr, size_t alignment, size_t size); 107void *__aligned_alloc(size_t alignment, size_t size); 108size_t __malloc_usable_size(const void *ptr); 109void __malloc_stats_print(void (*write_cb)(void *, const char *), 110 void *cbopaque, const char *opts); 111int __mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, 112 size_t newlen); 113int __mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp); 114int __mallctlbymib(const size_t *mib, size_t miblen, void *oldp, 115 size_t *oldlenp, void *newp, size_t newlen); 116void *__mallocx(size_t size, int flags); 117void *__rallocx(void *ptr, size_t size, int flags); 118size_t __xallocx(void *ptr, size_t size, size_t extra, int flags); 119size_t __sallocx(const void *ptr, int flags); 120void __dallocx(void *ptr, int flags); 121void __sdallocx(void *ptr, size_t size, int flags); 122size_t __nallocx(size_t size, int flags); 123 124void *memalign(size_t, size_t) __malloc_like __alloc_align(1) 125 __alloc_size(2); 126__END_DECLS 127 128#undef __MyBool 129 130#endif /* _MALLOC_NP_H_ */ 131