malloc_np.h revision 286911
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: head/include/malloc_np.h 286911 2015-08-19 00:06:46Z jasone $
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
39typedef void *(chunk_alloc_t)(void *, size_t, size_t, _Bool *, _Bool *,
40    unsigned);
41typedef _Bool (chunk_dalloc_t)(void *, size_t, _Bool, unsigned);
42typedef _Bool (chunk_commit_t)(void *, size_t, size_t, size_t, unsigned);
43typedef _Bool (chunk_decommit_t)(void *, size_t, size_t, size_t, unsigned);
44typedef _Bool (chunk_purge_t)(void *, size_t, size_t, size_t, unsigned);
45typedef _Bool (chunk_split_t)(void *, size_t, size_t, size_t, _Bool, unsigned);
46typedef _Bool (chunk_merge_t)(void *, size_t, void *, size_t, _Bool, unsigned);
47typedef 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
57size_t	malloc_usable_size(const void *ptr);
58
59void	malloc_stats_print(void (*write_cb)(void *, const char *),
60    void *cbopaque, const char *opts);
61int	mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
62    size_t newlen);
63int	mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
64int	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
74void	*mallocx(size_t size, int flags);
75void	*rallocx(void *ptr, size_t size, int flags);
76size_t	xallocx(void *ptr, size_t size, size_t extra, int flags);
77size_t	sallocx(const void *ptr, int flags);
78void	dallocx(void *ptr, int flags);
79void	sdallocx(void *ptr, size_t size, int flags);
80size_t	nallocx(size_t size, int flags);
81
82void *	__calloc(size_t number, size_t size) __malloc_like;
83void *	__malloc(size_t size) __malloc_like;
84void *	__realloc(void *ptr, size_t size);
85void	__free(void *ptr);
86int	__posix_memalign(void **ptr, size_t alignment, size_t size);
87void	*__aligned_alloc(size_t alignment, size_t size);
88size_t	__malloc_usable_size(const void *ptr);
89void	*__mallocx(size_t size, int flags);
90void	*__rallocx(void *ptr, size_t size, int flags);
91size_t	__xallocx(void *ptr, size_t size, size_t extra, int flags);
92size_t	__sallocx(const void *ptr, int flags);
93void	__dallocx(void *ptr, int flags);
94void	__sdallocx(void *ptr, size_t size, int flags);
95size_t	__nallocx(size_t size, int flags);
96__END_DECLS
97
98#endif /* _MALLOC_NP_H_ */
99