xref: /aosp_15_r20/external/scudo/standalone/wrappers_c.h (revision 76559068c068bd27e82aff38fac3bfc865233bca)
1*76559068SAndroid Build Coastguard Worker //===-- wrappers_c.h --------------------------------------------*- C++ -*-===//
2*76559068SAndroid Build Coastguard Worker //
3*76559068SAndroid Build Coastguard Worker // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*76559068SAndroid Build Coastguard Worker // See https://llvm.org/LICENSE.txt for license information.
5*76559068SAndroid Build Coastguard Worker // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*76559068SAndroid Build Coastguard Worker //
7*76559068SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
8*76559068SAndroid Build Coastguard Worker 
9*76559068SAndroid Build Coastguard Worker #ifndef SCUDO_WRAPPERS_C_H_
10*76559068SAndroid Build Coastguard Worker #define SCUDO_WRAPPERS_C_H_
11*76559068SAndroid Build Coastguard Worker 
12*76559068SAndroid Build Coastguard Worker #include "platform.h"
13*76559068SAndroid Build Coastguard Worker #include "stats.h"
14*76559068SAndroid Build Coastguard Worker 
15*76559068SAndroid Build Coastguard Worker // Bionic's struct mallinfo consists of size_t (mallinfo(3) uses int).
16*76559068SAndroid Build Coastguard Worker #if SCUDO_ANDROID
17*76559068SAndroid Build Coastguard Worker typedef size_t __scudo_mallinfo_data_t;
18*76559068SAndroid Build Coastguard Worker #else
19*76559068SAndroid Build Coastguard Worker typedef int __scudo_mallinfo_data_t;
20*76559068SAndroid Build Coastguard Worker #endif
21*76559068SAndroid Build Coastguard Worker 
22*76559068SAndroid Build Coastguard Worker struct __scudo_mallinfo {
23*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t arena;
24*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t ordblks;
25*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t smblks;
26*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t hblks;
27*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t hblkhd;
28*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t usmblks;
29*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t fsmblks;
30*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t uordblks;
31*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t fordblks;
32*76559068SAndroid Build Coastguard Worker   __scudo_mallinfo_data_t keepcost;
33*76559068SAndroid Build Coastguard Worker };
34*76559068SAndroid Build Coastguard Worker 
35*76559068SAndroid Build Coastguard Worker struct __scudo_mallinfo2 {
36*76559068SAndroid Build Coastguard Worker   size_t arena;
37*76559068SAndroid Build Coastguard Worker   size_t ordblks;
38*76559068SAndroid Build Coastguard Worker   size_t smblks;
39*76559068SAndroid Build Coastguard Worker   size_t hblks;
40*76559068SAndroid Build Coastguard Worker   size_t hblkhd;
41*76559068SAndroid Build Coastguard Worker   size_t usmblks;
42*76559068SAndroid Build Coastguard Worker   size_t fsmblks;
43*76559068SAndroid Build Coastguard Worker   size_t uordblks;
44*76559068SAndroid Build Coastguard Worker   size_t fordblks;
45*76559068SAndroid Build Coastguard Worker   size_t keepcost;
46*76559068SAndroid Build Coastguard Worker };
47*76559068SAndroid Build Coastguard Worker 
48*76559068SAndroid Build Coastguard Worker // Android sometimes includes malloc.h no matter what, which yields to
49*76559068SAndroid Build Coastguard Worker // conflicting return types for mallinfo() if we use our own structure. So if
50*76559068SAndroid Build Coastguard Worker // struct mallinfo is declared (#define courtesy of malloc.h), use it directly.
51*76559068SAndroid Build Coastguard Worker #if STRUCT_MALLINFO_DECLARED
52*76559068SAndroid Build Coastguard Worker #define SCUDO_MALLINFO mallinfo
53*76559068SAndroid Build Coastguard Worker #else
54*76559068SAndroid Build Coastguard Worker #define SCUDO_MALLINFO __scudo_mallinfo
55*76559068SAndroid Build Coastguard Worker #endif
56*76559068SAndroid Build Coastguard Worker 
57*76559068SAndroid Build Coastguard Worker #if !SCUDO_ANDROID || !_BIONIC
58*76559068SAndroid Build Coastguard Worker extern "C" void malloc_postinit();
59*76559068SAndroid Build Coastguard Worker extern HIDDEN scudo::Allocator<scudo::Config, malloc_postinit> Allocator;
60*76559068SAndroid Build Coastguard Worker #endif
61*76559068SAndroid Build Coastguard Worker 
62*76559068SAndroid Build Coastguard Worker #endif // SCUDO_WRAPPERS_C_H_
63