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 // TODO(kostyak): support both allocators.
36 INTERFACE void __scudo_print_stats(void) { Allocator.printStats(); }
37 
38 INTERFACE void
39 __scudo_get_error_info(struct scudo_error_info *error_info,
40                        uintptr_t fault_addr, const char *stack_depot,
41                        const char *region_info, const char *ring_buffer,
42                        const char *memory, const char *memory_tags,
43                        uintptr_t memory_addr, size_t memory_size) {
44   Allocator.getErrorInfo(error_info, fault_addr, stack_depot, region_info,
45                          ring_buffer, memory, memory_tags, memory_addr,
46                          memory_size);
47 }
48 
49 INTERFACE const char *__scudo_get_stack_depot_addr() {
50   return Allocator.getStackDepotAddress();
51 }
52 
53 INTERFACE size_t __scudo_get_stack_depot_size() {
54   return sizeof(scudo::StackDepot);
55 }
56 
57 INTERFACE const char *__scudo_get_region_info_addr() {
58   return Allocator.getRegionInfoArrayAddress();
59 }
60 
61 INTERFACE size_t __scudo_get_region_info_size() {
62   return Allocator.getRegionInfoArraySize();
63 }
64 
65 INTERFACE const char *__scudo_get_ring_buffer_addr() {
66   return Allocator.getRingBufferAddress();
67 }
68 
69 INTERFACE size_t __scudo_get_ring_buffer_size() {
70   return Allocator.getRingBufferSize();
71 }
72 
73 #endif // SCUDO_ANDROID && _BIONIC
74