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 (void)(stack_depot_size); 47 Allocator.getErrorInfo(error_info, fault_addr, stack_depot, region_info, 48 ring_buffer, ring_buffer_size, memory, memory_tags, 49 memory_addr, memory_size); 50 } 51 52 INTERFACE const char *__scudo_get_stack_depot_addr() { 53 return Allocator.getStackDepotAddress(); 54 } 55 56 INTERFACE size_t __scudo_get_stack_depot_size() { 57 return sizeof(scudo::StackDepot); 58 } 59 60 INTERFACE const char *__scudo_get_region_info_addr() { 61 return Allocator.getRegionInfoArrayAddress(); 62 } 63 64 INTERFACE size_t __scudo_get_region_info_size() { 65 return Allocator.getRegionInfoArraySize(); 66 } 67 68 INTERFACE const char *__scudo_get_ring_buffer_addr() { 69 return Allocator.getRingBufferAddress(); 70 } 71 72 INTERFACE size_t __scudo_get_ring_buffer_size() { 73 return Allocator.getRingBufferSize(); 74 } 75 76 #endif // SCUDO_ANDROID && _BIONIC 77