168d75effSDimitry Andric //===-- wrappers_c_bionic.cpp -----------------------------------*- C++ -*-===//
268d75effSDimitry Andric //
368d75effSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
468d75effSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
568d75effSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
668d75effSDimitry Andric //
768d75effSDimitry Andric //===----------------------------------------------------------------------===//
868d75effSDimitry Andric
968d75effSDimitry Andric #include "platform.h"
1068d75effSDimitry Andric
1168d75effSDimitry Andric // This is only used when compiled as part of Bionic.
1268d75effSDimitry Andric #if SCUDO_ANDROID && _BIONIC
1368d75effSDimitry Andric
1468d75effSDimitry Andric #include "allocator_config.h"
155f757f3fSDimitry Andric #include "internal_defs.h"
165f757f3fSDimitry Andric #include "platform.h"
175f757f3fSDimitry Andric #include "scudo/interface.h"
1868d75effSDimitry Andric #include "wrappers_c.h"
1968d75effSDimitry Andric #include "wrappers_c_checks.h"
2068d75effSDimitry Andric
2168d75effSDimitry Andric #include <stdint.h>
2268d75effSDimitry Andric #include <stdio.h>
2368d75effSDimitry Andric
2468d75effSDimitry Andric // Regular MallocDispatch definitions.
2568d75effSDimitry Andric #define SCUDO_PREFIX(name) CONCATENATE(scudo_, name)
2668d75effSDimitry Andric #define SCUDO_ALLOCATOR Allocator
27480093f4SDimitry Andric
28480093f4SDimitry Andric extern "C" void SCUDO_PREFIX(malloc_postinit)();
29fe6060f1SDimitry Andric SCUDO_REQUIRE_CONSTANT_INITIALIZATION
305f757f3fSDimitry Andric static scudo::Allocator<scudo::Config, SCUDO_PREFIX(malloc_postinit)>
31480093f4SDimitry Andric SCUDO_ALLOCATOR;
32480093f4SDimitry Andric
3368d75effSDimitry Andric #include "wrappers_c.inc"
34480093f4SDimitry Andric
3568d75effSDimitry Andric #undef SCUDO_ALLOCATOR
3668d75effSDimitry Andric #undef SCUDO_PREFIX
3768d75effSDimitry Andric
385ffd83dbSDimitry Andric // TODO(kostyak): support both allocators.
__scudo_print_stats(void)395ffd83dbSDimitry Andric INTERFACE void __scudo_print_stats(void) { Allocator.printStats(); }
405ffd83dbSDimitry Andric
__scudo_get_error_info(struct scudo_error_info * error_info,uintptr_t fault_addr,const char * stack_depot,size_t stack_depot_size,const char * region_info,const char * ring_buffer,size_t ring_buffer_size,const char * memory,const char * memory_tags,uintptr_t memory_addr,size_t memory_size)415f757f3fSDimitry Andric INTERFACE void __scudo_get_error_info(
425f757f3fSDimitry Andric struct scudo_error_info *error_info, uintptr_t fault_addr,
435f757f3fSDimitry Andric const char *stack_depot, size_t stack_depot_size, const char *region_info,
445f757f3fSDimitry Andric const char *ring_buffer, size_t ring_buffer_size, const char *memory,
455f757f3fSDimitry Andric const char *memory_tags, uintptr_t memory_addr, size_t memory_size) {
46*0fca6ea1SDimitry Andric Allocator.getErrorInfo(error_info, fault_addr, stack_depot, stack_depot_size,
47*0fca6ea1SDimitry Andric region_info, ring_buffer, ring_buffer_size, memory,
48*0fca6ea1SDimitry Andric memory_tags, memory_addr, memory_size);
495ffd83dbSDimitry Andric }
505ffd83dbSDimitry Andric
__scudo_get_stack_depot_addr()515ffd83dbSDimitry Andric INTERFACE const char *__scudo_get_stack_depot_addr() {
525ffd83dbSDimitry Andric return Allocator.getStackDepotAddress();
535ffd83dbSDimitry Andric }
545ffd83dbSDimitry Andric
__scudo_get_stack_depot_size()555ffd83dbSDimitry Andric INTERFACE size_t __scudo_get_stack_depot_size() {
56*0fca6ea1SDimitry Andric return Allocator.getStackDepotSize();
575ffd83dbSDimitry Andric }
585ffd83dbSDimitry Andric
__scudo_get_region_info_addr()595ffd83dbSDimitry Andric INTERFACE const char *__scudo_get_region_info_addr() {
605ffd83dbSDimitry Andric return Allocator.getRegionInfoArrayAddress();
615ffd83dbSDimitry Andric }
625ffd83dbSDimitry Andric
__scudo_get_region_info_size()635ffd83dbSDimitry Andric INTERFACE size_t __scudo_get_region_info_size() {
645ffd83dbSDimitry Andric return Allocator.getRegionInfoArraySize();
6568d75effSDimitry Andric }
6668d75effSDimitry Andric
__scudo_get_ring_buffer_addr()67fe6060f1SDimitry Andric INTERFACE const char *__scudo_get_ring_buffer_addr() {
68fe6060f1SDimitry Andric return Allocator.getRingBufferAddress();
69fe6060f1SDimitry Andric }
70fe6060f1SDimitry Andric
__scudo_get_ring_buffer_size()71fe6060f1SDimitry Andric INTERFACE size_t __scudo_get_ring_buffer_size() {
72fe6060f1SDimitry Andric return Allocator.getRingBufferSize();
73fe6060f1SDimitry Andric }
74fe6060f1SDimitry Andric
7568d75effSDimitry Andric #endif // SCUDO_ANDROID && _BIONIC
76