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