• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef _MUSL_MALLOC_H
17 #define _MUSL_MALLOC_H
18 
19 #include "malloc.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #ifdef HOOK_ENABLE
26 #define MuslMalloc(func) __libc_ ## func
27 #else
28 #define MuslMalloc(func) func
29 #endif
30 
31 #ifdef USE_JEMALLOC
32 extern void* je_malloc(size_t size);
33 extern void* je_calloc(size_t count, size_t size);
34 extern void* je_realloc(void* p, size_t newsize);
35 extern void je_free(void* p);
36 #define MuslFunc(func) je_ ## func
37 #else
38 extern void *__libc_malloc(size_t size);
39 extern void __libc_free(void* p);
40 extern void *hook_calloc(size_t, size_t);
41 #define hook_malloc __libc_malloc
42 #define hook_free __libc_free
43 #define hook_realloc __libc_realloc
44 #define MuslFunc(func) hook_ ## func
45 #endif
46 
47 void *__libc_mmap(void*, size_t, int, int, int, off_t);
48 int __libc_munmap(void*, size_t);
49 void *__libc_calloc(size_t, size_t);
50 void *__libc_realloc(void *, size_t);
51 void *__libc_valloc(size_t);
52 void *__libc_aligned_alloc(size_t, size_t);
53 size_t __libc_malloc_usable_size(void *);
54 int __libc_prctl(int, ...);
55 
56 struct mallinfo2 __libc_mallinfo2(void);
57 
58 int __libc_malloc_iterate(void* base, size_t size, void (*callback)(void* base, size_t size, void* arg), void* arg);
59 void __libc_malloc_disable(void);
60 void __libc_malloc_enable(void);
61 
62 int __libc_malloc_info(int options, FILE* fp);
63 void __libc_malloc_stats_print(void (*write_cb) (void *, const char *), void *cbopaque, const char *opts);
64 
65 int __libc_mallopt(int param, int value);
66 ssize_t __libc_malloc_backtrace(void* pointer, uintptr_t* frames, size_t frame_count);
67 
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 #endif
74