]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/malloc_np.h
Revert "nl_types.h: explicitly include cdefs.h"
[FreeBSD/FreeBSD.git] / include / malloc_np.h
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
44 typedef struct extent_hooks_s extent_hooks_t;
45 typedef void *(extent_alloc_t)(extent_hooks_t *, void *, size_t, size_t,
46     __MyBool *, __MyBool *, unsigned);
47 typedef __MyBool (extent_dalloc_t)(extent_hooks_t *, void *, size_t, __MyBool,
48     unsigned);
49 typedef void (extent_destroy_t)(extent_hooks_t *, void *, size_t, __MyBool,
50     unsigned);
51 typedef __MyBool (extent_commit_t)(extent_hooks_t *, void *, size_t, size_t,
52     size_t, unsigned);
53 typedef __MyBool (extent_decommit_t)(extent_hooks_t *, void *, size_t, size_t,
54     size_t, unsigned);
55 typedef __MyBool (extent_purge_t)(extent_hooks_t *, void *, size_t, size_t, size_t,
56     unsigned);
57 typedef __MyBool (extent_split_t)(extent_hooks_t *, void *, size_t, size_t, size_t,
58     __MyBool, unsigned);
59 typedef __MyBool (extent_merge_t)(extent_hooks_t *, void *, size_t, void *, size_t,
60     __MyBool, unsigned);
61 struct 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
73 size_t  malloc_usable_size(const void *ptr);
74
75 void    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
81 int     mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
82     size_t newlen);
83 int     mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
84 int     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
94 void    *mallocx(size_t size, int flags);
95 void    *rallocx(void *ptr, size_t size, int flags);
96 size_t  xallocx(void *ptr, size_t size, size_t extra, int flags);
97 size_t  sallocx(const void *ptr, int flags);
98 void    dallocx(void *ptr, int flags);
99 void    sdallocx(void *ptr, size_t size, int flags);
100 size_t  nallocx(size_t size, int flags);
101
102 void *  __calloc(size_t number, size_t size) __malloc_like;
103 void *  __malloc(size_t size) __malloc_like;
104 void *  __realloc(void *ptr, size_t size);
105 void    __free(void *ptr);
106 int     __posix_memalign(void **ptr, size_t alignment, size_t size);
107 void    *__aligned_alloc(size_t alignment, size_t size);
108 size_t  __malloc_usable_size(const void *ptr);
109 void    __malloc_stats_print(void (*write_cb)(void *, const char *),
110     void *cbopaque, const char *opts);
111 int     __mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
112     size_t newlen);
113 int     __mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
114 int     __mallctlbymib(const size_t *mib, size_t miblen, void *oldp,
115     size_t *oldlenp, void *newp, size_t newlen);
116 void    *__mallocx(size_t size, int flags);
117 void    *__rallocx(void *ptr, size_t size, int flags);
118 size_t  __xallocx(void *ptr, size_t size, size_t extra, int flags);
119 size_t  __sallocx(const void *ptr, int flags);
120 void    __dallocx(void *ptr, int flags);
121 void    __sdallocx(void *ptr, size_t size, int flags);
122 size_t  __nallocx(size_t size, int flags);
123
124 void    *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_ */