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 "internal_defs.h" |
16 | #include "platform.h" |
17 | #include "scudo/interface.h" |
18 | #include "wrappers_c.h" |
19 | #include "wrappers_c_checks.h" |
20 | |
21 | #include <stdint.h> |
22 | #include <stdio.h> |
23 | |
24 | // Regular MallocDispatch definitions. |
25 | #define SCUDO_PREFIX(name) CONCATENATE(scudo_, name) |
26 | #define SCUDO_ALLOCATOR Allocator |
27 | |
28 | extern "C" void SCUDO_PREFIX(malloc_postinit)(); |
29 | SCUDO_REQUIRE_CONSTANT_INITIALIZATION |
30 | static scudo::Allocator<scudo::Config, SCUDO_PREFIX(malloc_postinit)> |
31 | SCUDO_ALLOCATOR; |
32 | |
33 | #include "wrappers_c.inc" |
34 | |
35 | #undef SCUDO_ALLOCATOR |
36 | #undef SCUDO_PREFIX |
37 | |
38 | // TODO(kostyak): support both allocators. |
39 | INTERFACE void __scudo_print_stats(void) { Allocator.printStats(); } |
40 | |
41 | INTERFACE void __scudo_get_error_info( |
42 | struct scudo_error_info *error_info, uintptr_t fault_addr, |
43 | const char *stack_depot, size_t stack_depot_size, const char *region_info, |
44 | const char *ring_buffer, size_t ring_buffer_size, const char *memory, |
45 | const char *memory_tags, uintptr_t memory_addr, size_t memory_size) { |
46 | Allocator.getErrorInfo(error_info, fault_addr, stack_depot, stack_depot_size, |
47 | region_info, ring_buffer, ring_buffer_size, memory, |
48 | memory_tags, memory_addr, memory_size); |
49 | } |
50 | |
51 | INTERFACE const char *__scudo_get_stack_depot_addr() { |
52 | return Allocator.getStackDepotAddress(); |
53 | } |
54 | |
55 | INTERFACE size_t __scudo_get_stack_depot_size() { |
56 | return Allocator.getStackDepotSize(); |
57 | } |
58 | |
59 | INTERFACE const char *__scudo_get_region_info_addr() { |
60 | return Allocator.getRegionInfoArrayAddress(); |
61 | } |
62 | |
63 | INTERFACE size_t __scudo_get_region_info_size() { |
64 | return Allocator.getRegionInfoArraySize(); |
65 | } |
66 | |
67 | INTERFACE const char *__scudo_get_ring_buffer_addr() { |
68 | return Allocator.getRingBufferAddress(); |
69 | } |
70 | |
71 | INTERFACE size_t __scudo_get_ring_buffer_size() { |
72 | return Allocator.getRingBufferSize(); |
73 | } |
74 | |
75 | #endif // SCUDO_ANDROID && _BIONIC |
76 | |