Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 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 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 21 | // Regular MallocDispatch definitions. |
| 22 | #define SCUDO_PREFIX(name) CONCATENATE(scudo_, name) |
| 23 | #define SCUDO_ALLOCATOR Allocator |
Dynamic Tools Team | 83eaa51 | 2020-01-09 11:43:16 -0800 | [diff] [blame] | 24 | |
| 25 | extern "C" void SCUDO_PREFIX(malloc_postinit)(); |
Vitaly Buka | 5d3d727 | 2021-04-29 01:19:51 -0700 | [diff] [blame] | 26 | SCUDO_REQUIRE_CONSTANT_INITIALIZATION |
Dynamic Tools Team | 83eaa51 | 2020-01-09 11:43:16 -0800 | [diff] [blame] | 27 | static scudo::Allocator<scudo::AndroidConfig, SCUDO_PREFIX(malloc_postinit)> |
| 28 | SCUDO_ALLOCATOR; |
Dynamic Tools Team | 83eaa51 | 2020-01-09 11:43:16 -0800 | [diff] [blame] | 29 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 30 | #include "wrappers_c.inc" |
Dynamic Tools Team | 83eaa51 | 2020-01-09 11:43:16 -0800 | [diff] [blame] | 31 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 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 |
Dynamic Tools Team | 83eaa51 | 2020-01-09 11:43:16 -0800 | [diff] [blame] | 38 | |
| 39 | extern "C" void SCUDO_PREFIX(malloc_postinit)(); |
Vitaly Buka | 5d3d727 | 2021-04-29 01:19:51 -0700 | [diff] [blame] | 40 | SCUDO_REQUIRE_CONSTANT_INITIALIZATION |
Dynamic Tools Team | 83eaa51 | 2020-01-09 11:43:16 -0800 | [diff] [blame] | 41 | static scudo::Allocator<scudo::AndroidSvelteConfig, |
| 42 | SCUDO_PREFIX(malloc_postinit)> |
| 43 | SCUDO_ALLOCATOR; |
Dynamic Tools Team | 83eaa51 | 2020-01-09 11:43:16 -0800 | [diff] [blame] | 44 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 45 | #include "wrappers_c.inc" |
Dynamic Tools Team | 83eaa51 | 2020-01-09 11:43:16 -0800 | [diff] [blame] | 46 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 47 | #undef SCUDO_ALLOCATOR |
| 48 | #undef SCUDO_PREFIX |
| 49 | |
Dynamic Tools Team | ac40305 | 2020-02-06 15:46:05 -0800 | [diff] [blame] | 50 | // TODO(kostyak): support both allocators. |
| 51 | INTERFACE void __scudo_print_stats(void) { Allocator.printStats(); } |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 52 | |
Peter Collingbourne | 75ee3bc | 2021-01-05 19:03:03 -0800 | [diff] [blame] | 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) { |
Dynamic Tools Team | 0d7d2ae | 2020-04-21 15:30:50 -0700 | [diff] [blame] | 59 | Allocator.getErrorInfo(error_info, fault_addr, stack_depot, region_info, |
Peter Collingbourne | 75ee3bc | 2021-01-05 19:03:03 -0800 | [diff] [blame] | 60 | ring_buffer, memory, memory_tags, memory_addr, |
| 61 | memory_size); |
Dynamic Tools Team | 0d7d2ae | 2020-04-21 15:30:50 -0700 | [diff] [blame] | 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 | |
Peter Collingbourne | 75ee3bc | 2021-01-05 19:03:03 -0800 | [diff] [blame] | 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 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 88 | #endif // SCUDO_ANDROID && _BIONIC |