xref: /openbsd-src/gnu/llvm/compiler-rt/lib/scudo/standalone/wrappers_c.h (revision 810390e339a5425391477d5d41c78d7cab2424ac)
13cab2bb3Spatrick //===-- wrappers_c.h --------------------------------------------*- C++ -*-===//
23cab2bb3Spatrick //
33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information.
53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63cab2bb3Spatrick //
73cab2bb3Spatrick //===----------------------------------------------------------------------===//
83cab2bb3Spatrick 
93cab2bb3Spatrick #ifndef SCUDO_WRAPPERS_C_H_
103cab2bb3Spatrick #define SCUDO_WRAPPERS_C_H_
113cab2bb3Spatrick 
123cab2bb3Spatrick #include "platform.h"
133cab2bb3Spatrick #include "stats.h"
143cab2bb3Spatrick 
153cab2bb3Spatrick // Bionic's struct mallinfo consists of size_t (mallinfo(3) uses int).
163cab2bb3Spatrick #if SCUDO_ANDROID
173cab2bb3Spatrick typedef size_t __scudo_mallinfo_data_t;
183cab2bb3Spatrick #else
193cab2bb3Spatrick typedef int __scudo_mallinfo_data_t;
203cab2bb3Spatrick #endif
213cab2bb3Spatrick 
223cab2bb3Spatrick struct __scudo_mallinfo {
233cab2bb3Spatrick   __scudo_mallinfo_data_t arena;
243cab2bb3Spatrick   __scudo_mallinfo_data_t ordblks;
253cab2bb3Spatrick   __scudo_mallinfo_data_t smblks;
263cab2bb3Spatrick   __scudo_mallinfo_data_t hblks;
273cab2bb3Spatrick   __scudo_mallinfo_data_t hblkhd;
283cab2bb3Spatrick   __scudo_mallinfo_data_t usmblks;
293cab2bb3Spatrick   __scudo_mallinfo_data_t fsmblks;
303cab2bb3Spatrick   __scudo_mallinfo_data_t uordblks;
313cab2bb3Spatrick   __scudo_mallinfo_data_t fordblks;
323cab2bb3Spatrick   __scudo_mallinfo_data_t keepcost;
333cab2bb3Spatrick };
343cab2bb3Spatrick 
35*810390e3Srobert struct __scudo_mallinfo2 {
36*810390e3Srobert   size_t arena;
37*810390e3Srobert   size_t ordblks;
38*810390e3Srobert   size_t smblks;
39*810390e3Srobert   size_t hblks;
40*810390e3Srobert   size_t hblkhd;
41*810390e3Srobert   size_t usmblks;
42*810390e3Srobert   size_t fsmblks;
43*810390e3Srobert   size_t uordblks;
44*810390e3Srobert   size_t fordblks;
45*810390e3Srobert   size_t keepcost;
46*810390e3Srobert };
47*810390e3Srobert 
483cab2bb3Spatrick // Android sometimes includes malloc.h no matter what, which yields to
493cab2bb3Spatrick // conflicting return types for mallinfo() if we use our own structure. So if
503cab2bb3Spatrick // struct mallinfo is declared (#define courtesy of malloc.h), use it directly.
513cab2bb3Spatrick #if STRUCT_MALLINFO_DECLARED
523cab2bb3Spatrick #define SCUDO_MALLINFO mallinfo
533cab2bb3Spatrick #else
543cab2bb3Spatrick #define SCUDO_MALLINFO __scudo_mallinfo
553cab2bb3Spatrick #endif
563cab2bb3Spatrick 
57*810390e3Srobert #if !SCUDO_ANDROID || !_BIONIC
58*810390e3Srobert extern "C" void malloc_postinit();
59*810390e3Srobert extern HIDDEN scudo::Allocator<scudo::Config, malloc_postinit> Allocator;
60*810390e3Srobert #endif
61*810390e3Srobert 
623cab2bb3Spatrick #endif // SCUDO_WRAPPERS_C_H_
63