1570af302Sopenharmony_ci/*
2570af302Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3570af302Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4570af302Sopenharmony_ci * you may not use this file except in compliance with the License.
5570af302Sopenharmony_ci * You may obtain a copy of the License at
6570af302Sopenharmony_ci *
7570af302Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8570af302Sopenharmony_ci *
9570af302Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10570af302Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11570af302Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12570af302Sopenharmony_ci * See the License for the specific language governing permissions and
13570af302Sopenharmony_ci * limitations under the License.
14570af302Sopenharmony_ci */
15570af302Sopenharmony_ci
16570af302Sopenharmony_ci#ifndef _MUSL_MALLOC_H
17570af302Sopenharmony_ci#define _MUSL_MALLOC_H
18570af302Sopenharmony_ci
19570af302Sopenharmony_ci#include "malloc.h"
20570af302Sopenharmony_ci
21570af302Sopenharmony_ci#ifdef __cplusplus
22570af302Sopenharmony_ciextern "C" {
23570af302Sopenharmony_ci#endif
24570af302Sopenharmony_ci
25570af302Sopenharmony_ci#ifdef HOOK_ENABLE
26570af302Sopenharmony_ci#define MuslMalloc(func) __libc_ ## func
27570af302Sopenharmony_ci#else
28570af302Sopenharmony_ci#define MuslMalloc(func) func
29570af302Sopenharmony_ci#endif
30570af302Sopenharmony_ci
31570af302Sopenharmony_ci#ifdef USE_JEMALLOC
32570af302Sopenharmony_ciextern void* je_malloc(size_t size);
33570af302Sopenharmony_ciextern void* je_calloc(size_t count, size_t size);
34570af302Sopenharmony_ciextern void* je_realloc(void* p, size_t newsize);
35570af302Sopenharmony_ciextern void je_free(void* p);
36570af302Sopenharmony_ci#define MuslFunc(func) je_ ## func
37570af302Sopenharmony_ci#else
38570af302Sopenharmony_ciextern void *__libc_malloc(size_t size);
39570af302Sopenharmony_ciextern void __libc_free(void* p);
40570af302Sopenharmony_ciextern void *hook_calloc(size_t, size_t);
41570af302Sopenharmony_ci#define hook_malloc __libc_malloc
42570af302Sopenharmony_ci#define hook_free __libc_free
43570af302Sopenharmony_ci#define hook_realloc __libc_realloc
44570af302Sopenharmony_ci#define MuslFunc(func) hook_ ## func
45570af302Sopenharmony_ci#endif
46570af302Sopenharmony_ci
47570af302Sopenharmony_civoid *__libc_mmap(void*, size_t, int, int, int, off_t);
48570af302Sopenharmony_ciint __libc_munmap(void*, size_t);
49570af302Sopenharmony_civoid *__libc_calloc(size_t, size_t);
50570af302Sopenharmony_civoid *__libc_realloc(void *, size_t);
51570af302Sopenharmony_civoid *__libc_valloc(size_t);
52570af302Sopenharmony_civoid *__libc_aligned_alloc(size_t, size_t);
53570af302Sopenharmony_cisize_t __libc_malloc_usable_size(void *);
54570af302Sopenharmony_ciint __libc_prctl(int, ...);
55570af302Sopenharmony_ci
56570af302Sopenharmony_cistruct mallinfo2 __libc_mallinfo2(void);
57570af302Sopenharmony_ci
58570af302Sopenharmony_ciint __libc_malloc_iterate(void* base, size_t size, void (*callback)(void* base, size_t size, void* arg), void* arg);
59570af302Sopenharmony_civoid __libc_malloc_disable(void);
60570af302Sopenharmony_civoid __libc_malloc_enable(void);
61570af302Sopenharmony_ci
62570af302Sopenharmony_ciint __libc_malloc_info(int options, FILE* fp);
63570af302Sopenharmony_civoid __libc_malloc_stats_print(void (*write_cb) (void *, const char *), void *cbopaque, const char *opts);
64570af302Sopenharmony_ci
65570af302Sopenharmony_ciint __libc_mallopt(int param, int value);
66570af302Sopenharmony_cissize_t __libc_malloc_backtrace(void* pointer, uintptr_t* frames, size_t frame_count);
67570af302Sopenharmony_ci
68570af302Sopenharmony_ci
69570af302Sopenharmony_ci#ifdef __cplusplus
70570af302Sopenharmony_ci}
71570af302Sopenharmony_ci#endif
72570af302Sopenharmony_ci
73570af302Sopenharmony_ci#endif
74