xref: /freebsd/contrib/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
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 SCUDO_REQUIRE_CONSTANT_INITIALIZATION
27 static scudo::Allocator<scudo::AndroidConfig, SCUDO_PREFIX(malloc_postinit)>
28     SCUDO_ALLOCATOR;
29 
30 #include "wrappers_c.inc"
31 
32 #undef SCUDO_ALLOCATOR
33 #undef SCUDO_PREFIX
34 
35 // Svelte MallocDispatch definitions.
36 #define SCUDO_PREFIX(name) CONCATENATE(scudo_svelte_, name)
37 #define SCUDO_ALLOCATOR SvelteAllocator
38 
39 extern "C" void SCUDO_PREFIX(malloc_postinit)();
40 SCUDO_REQUIRE_CONSTANT_INITIALIZATION
41 static scudo::Allocator<scudo::AndroidSvelteConfig,
42                         SCUDO_PREFIX(malloc_postinit)>
43     SCUDO_ALLOCATOR;
44 
45 #include "wrappers_c.inc"
46 
47 #undef SCUDO_ALLOCATOR
48 #undef SCUDO_PREFIX
49 
50 // TODO(kostyak): support both allocators.
51 INTERFACE void __scudo_print_stats(void) { Allocator.printStats(); }
52 
53 INTERFACE void
54 __scudo_get_error_info(struct scudo_error_info *error_info,
55                        uintptr_t fault_addr, const char *stack_depot,
56                        const char *region_info, const char *ring_buffer,
57                        const char *memory, const char *memory_tags,
58                        uintptr_t memory_addr, size_t memory_size) {
59   Allocator.getErrorInfo(error_info, fault_addr, stack_depot, region_info,
60                          ring_buffer, memory, memory_tags, memory_addr,
61                          memory_size);
62 }
63 
64 INTERFACE const char *__scudo_get_stack_depot_addr() {
65   return Allocator.getStackDepotAddress();
66 }
67 
68 INTERFACE size_t __scudo_get_stack_depot_size() {
69   return sizeof(scudo::StackDepot);
70 }
71 
72 INTERFACE const char *__scudo_get_region_info_addr() {
73   return Allocator.getRegionInfoArrayAddress();
74 }
75 
76 INTERFACE size_t __scudo_get_region_info_size() {
77   return Allocator.getRegionInfoArraySize();
78 }
79 
80 INTERFACE const char *__scudo_get_ring_buffer_addr() {
81   return Allocator.getRingBufferAddress();
82 }
83 
84 INTERFACE size_t __scudo_get_ring_buffer_size() {
85   return Allocator.getRingBufferSize();
86 }
87 
88 #endif // SCUDO_ANDROID && _BIONIC
89