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 size_t malloc_usable_size(const void *ptr); 40 41 void malloc_stats_print(void (*write_cb)(void *, const char *), 42 void *cbopaque, const char *opts); 43 int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, 44 size_t newlen); 45 int mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp); 46 int mallctlbymib(const size_t *mib, size_t miblen, void *oldp, 47 size_t *oldlenp, void *newp, size_t newlen); 48 49 #define MALLOCX_LG_ALIGN(la) (la) 50 #define MALLOCX_ALIGN(a) (ffsl(a)-1) 51 #define MALLOCX_ZERO ((int)0x40) 52 #define MALLOCX_ARENA(a) ((int)(((a)+1) << 8)) 53 54 void *mallocx(size_t size, int flags); 55 void *rallocx(void *ptr, size_t size, int flags); 56 size_t xallocx(void *ptr, size_t size, size_t extra, int flags); 57 size_t sallocx(const void *ptr, int flags); 58 void dallocx(void *ptr, int flags); 59 size_t nallocx(size_t size, int flags); 60 61 #define ALLOCM_LG_ALIGN(la) (la) 62 #define ALLOCM_ALIGN(a) (ffsl(a)-1) 63 #define ALLOCM_ZERO ((int)0x40) 64 #define ALLOCM_NO_MOVE ((int)0x80) 65 66 #define ALLOCM_SUCCESS 0 67 #define ALLOCM_ERR_OOM 1 68 #define ALLOCM_ERR_NOT_MOVED 2 69 70 int allocm(void **ptr, size_t *rsize, size_t size, int flags) __nonnull(1); 71 int rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, 72 int flags) __nonnull(1); 73 int sallocm(const void *ptr, size_t *rsize, int flags) __nonnull(1); 74 int dallocm(void *ptr, int flags) __nonnull(1); 75 int nallocm(size_t *rsize, size_t size, int flags); 76 77 void * __calloc(size_t, size_t) __malloc_like; 78 void * __malloc(size_t) __malloc_like; 79 void * __realloc(void *, size_t); 80 void __free(void *); 81 int __posix_memalign(void **, size_t, size_t); 82 size_t __malloc_usable_size(const void *); 83 void *__mallocx(size_t size, int flags); 84 void *__rallocx(void *ptr, size_t size, int flags); 85 size_t __xallocx(void *ptr, size_t size, size_t extra, int flags); 86 size_t __sallocx(const void *ptr, int flags); 87 void __dallocx(void *ptr, int flags); 88 size_t __nallocx(size_t size, int flags); 89 int __allocm(void **, size_t *, size_t, int) __nonnull(1); 90 int __rallocm(void **, size_t *, size_t, size_t, int) __nonnull(1); 91 int __sallocm(const void *, size_t *, int) __nonnull(1); 92 int __dallocm(void *, int) __nonnull(1); 93 int __nallocm(size_t *, size_t, int); 94 __END_DECLS 95 96 #endif /* _MALLOC_NP_H_ */ 97