]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / compiler-rt / lib / scudo / standalone / wrappers_c_bionic.cpp
1 //===-- wrappers_c_bionic.cpp -----------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "platform.h"
10
11 // This is only used when compiled as part of Bionic.
12 #if SCUDO_ANDROID && _BIONIC
13
14 #include "allocator_config.h"
15 #include "wrappers_c.h"
16 #include "wrappers_c_checks.h"
17
18 #include <stdint.h>
19 #include <stdio.h>
20
21 // Regular MallocDispatch definitions.
22 #define SCUDO_PREFIX(name) CONCATENATE(scudo_, name)
23 #define SCUDO_ALLOCATOR Allocator
24
25 extern "C" void SCUDO_PREFIX(malloc_postinit)();
26 static scudo::Allocator<scudo::AndroidConfig, SCUDO_PREFIX(malloc_postinit)>
27     SCUDO_ALLOCATOR;
28 // Pointer to the static allocator so that the C++ wrappers can access it.
29 // Technically we could have a completely separated heap for C & C++ but in
30 // reality the amount of cross pollination between the two is staggering.
31 scudo::Allocator<scudo::AndroidConfig, SCUDO_PREFIX(malloc_postinit)> *
32     CONCATENATE(SCUDO_ALLOCATOR, Ptr) = &SCUDO_ALLOCATOR;
33
34 #include "wrappers_c.inc"
35
36 #undef SCUDO_ALLOCATOR
37 #undef SCUDO_PREFIX
38
39 // Svelte MallocDispatch definitions.
40 #define SCUDO_PREFIX(name) CONCATENATE(scudo_svelte_, name)
41 #define SCUDO_ALLOCATOR SvelteAllocator
42
43 extern "C" void SCUDO_PREFIX(malloc_postinit)();
44 static scudo::Allocator<scudo::AndroidSvelteConfig,
45                         SCUDO_PREFIX(malloc_postinit)>
46     SCUDO_ALLOCATOR;
47 // Pointer to the static allocator so that the C++ wrappers can access it.
48 // Technically we could have a completely separated heap for C & C++ but in
49 // reality the amount of cross pollination between the two is staggering.
50 scudo::Allocator<scudo::AndroidSvelteConfig, SCUDO_PREFIX(malloc_postinit)> *
51     CONCATENATE(SCUDO_ALLOCATOR, Ptr) = &SCUDO_ALLOCATOR;
52
53 #include "wrappers_c.inc"
54
55 #undef SCUDO_ALLOCATOR
56 #undef SCUDO_PREFIX
57
58 // The following is the only function that will end up initializing both
59 // allocators, which will result in a slight increase in memory footprint.
60 INTERFACE void __scudo_print_stats(void) {
61   Allocator.printStats();
62   SvelteAllocator.printStats();
63 }
64
65 #endif // SCUDO_ANDROID && _BIONIC