xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.cpp (revision 480093f4440d54b30b3025afeac24b48f2ba7a2e)
168d75effSDimitry Andric //===-- wrappers_c.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 // Skip this compilation unit if compiled as part of Bionic.
1268d75effSDimitry Andric #if !SCUDO_ANDROID || !_BIONIC
1368d75effSDimitry Andric 
1468d75effSDimitry Andric #include "allocator_config.h"
1568d75effSDimitry Andric #include "wrappers_c.h"
1668d75effSDimitry Andric #include "wrappers_c_checks.h"
1768d75effSDimitry Andric 
1868d75effSDimitry Andric #include <stdint.h>
1968d75effSDimitry Andric #include <stdio.h>
2068d75effSDimitry Andric 
21*480093f4SDimitry Andric #define SCUDO_PREFIX(name) name
22*480093f4SDimitry Andric #define SCUDO_ALLOCATOR Allocator
23*480093f4SDimitry Andric 
24*480093f4SDimitry Andric extern "C" void SCUDO_PREFIX(malloc_postinit)();
25*480093f4SDimitry Andric static scudo::Allocator<scudo::Config, SCUDO_PREFIX(malloc_postinit)>
26*480093f4SDimitry Andric     SCUDO_ALLOCATOR;
2768d75effSDimitry Andric // Pointer to the static allocator so that the C++ wrappers can access it.
2868d75effSDimitry Andric // Technically we could have a completely separated heap for C & C++ but in
2968d75effSDimitry Andric // reality the amount of cross pollination between the two is staggering.
30*480093f4SDimitry Andric scudo::Allocator<scudo::Config, SCUDO_PREFIX(malloc_postinit)> *
31*480093f4SDimitry Andric     CONCATENATE(SCUDO_ALLOCATOR, Ptr) = &SCUDO_ALLOCATOR;
3268d75effSDimitry Andric 
3368d75effSDimitry Andric #include "wrappers_c.inc"
34*480093f4SDimitry Andric 
3568d75effSDimitry Andric #undef SCUDO_ALLOCATOR
3668d75effSDimitry Andric #undef SCUDO_PREFIX
3768d75effSDimitry Andric 
38*480093f4SDimitry Andric extern "C" INTERFACE void __scudo_print_stats(void) { Allocator.printStats(); }
3968d75effSDimitry Andric 
4068d75effSDimitry Andric #endif // !SCUDO_ANDROID || !_BIONIC
41