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