blob: 18c3bf2c0edfa2f2cecf2ef0af3838d28de25de3 [file] [log] [blame]
Dynamic Tools Team517193e2019-09-11 14:48:41 +00001//===-- 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 Team517193e2019-09-11 14:48:41 +000021// Regular MallocDispatch definitions.
22#define SCUDO_PREFIX(name) CONCATENATE(scudo_, name)
23#define SCUDO_ALLOCATOR Allocator
Dynamic Tools Team83eaa512020-01-09 11:43:16 -080024
25extern "C" void SCUDO_PREFIX(malloc_postinit)();
Vitaly Buka5d3d7272021-04-29 01:19:51 -070026SCUDO_REQUIRE_CONSTANT_INITIALIZATION
Dynamic Tools Team83eaa512020-01-09 11:43:16 -080027static scudo::Allocator<scudo::AndroidConfig, SCUDO_PREFIX(malloc_postinit)>
28 SCUDO_ALLOCATOR;
Dynamic Tools Team83eaa512020-01-09 11:43:16 -080029
Dynamic Tools Team517193e2019-09-11 14:48:41 +000030#include "wrappers_c.inc"
Dynamic Tools Team83eaa512020-01-09 11:43:16 -080031
Dynamic Tools Team517193e2019-09-11 14:48:41 +000032#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 Team83eaa512020-01-09 11:43:16 -080038
39extern "C" void SCUDO_PREFIX(malloc_postinit)();
Vitaly Buka5d3d7272021-04-29 01:19:51 -070040SCUDO_REQUIRE_CONSTANT_INITIALIZATION
Dynamic Tools Team83eaa512020-01-09 11:43:16 -080041static scudo::Allocator<scudo::AndroidSvelteConfig,
42 SCUDO_PREFIX(malloc_postinit)>
43 SCUDO_ALLOCATOR;
Dynamic Tools Team83eaa512020-01-09 11:43:16 -080044
Dynamic Tools Team517193e2019-09-11 14:48:41 +000045#include "wrappers_c.inc"
Dynamic Tools Team83eaa512020-01-09 11:43:16 -080046
Dynamic Tools Team517193e2019-09-11 14:48:41 +000047#undef SCUDO_ALLOCATOR
48#undef SCUDO_PREFIX
49
Dynamic Tools Teamac403052020-02-06 15:46:05 -080050// TODO(kostyak): support both allocators.
51INTERFACE void __scudo_print_stats(void) { Allocator.printStats(); }
Dynamic Tools Team517193e2019-09-11 14:48:41 +000052
Peter Collingbourne75ee3bc2021-01-05 19:03:03 -080053INTERFACE 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 Team0d7d2ae2020-04-21 15:30:50 -070059 Allocator.getErrorInfo(error_info, fault_addr, stack_depot, region_info,
Peter Collingbourne75ee3bc2021-01-05 19:03:03 -080060 ring_buffer, memory, memory_tags, memory_addr,
61 memory_size);
Dynamic Tools Team0d7d2ae2020-04-21 15:30:50 -070062}
63
64INTERFACE const char *__scudo_get_stack_depot_addr() {
65 return Allocator.getStackDepotAddress();
66}
67
68INTERFACE size_t __scudo_get_stack_depot_size() {
69 return sizeof(scudo::StackDepot);
70}
71
72INTERFACE const char *__scudo_get_region_info_addr() {
73 return Allocator.getRegionInfoArrayAddress();
74}
75
76INTERFACE size_t __scudo_get_region_info_size() {
77 return Allocator.getRegionInfoArraySize();
78}
79
Peter Collingbourne75ee3bc2021-01-05 19:03:03 -080080INTERFACE const char *__scudo_get_ring_buffer_addr() {
81 return Allocator.getRingBufferAddress();
82}
83
84INTERFACE size_t __scudo_get_ring_buffer_size() {
85 return Allocator.getRingBufferSize();
86}
87
Dynamic Tools Team517193e2019-09-11 14:48:41 +000088#endif // SCUDO_ANDROID && _BIONIC