| 1 | //===-- wrappers_c.h --------------------------------------------*- 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 | #ifndef SCUDO_WRAPPERS_C_H_ |
| 10 | #define SCUDO_WRAPPERS_C_H_ |
| 11 | |
| 12 | #include "platform.h" |
| 13 | #include "stats.h" |
| 14 | |
| 15 | // Bionic's struct mallinfo consists of size_t (mallinfo(3) uses int). |
| 16 | #if SCUDO_ANDROID |
| 17 | typedef size_t __scudo_mallinfo_data_t; |
| 18 | #else |
| 19 | typedef int __scudo_mallinfo_data_t; |
| 20 | #endif |
| 21 | |
| 22 | struct __scudo_mallinfo { |
| 23 | __scudo_mallinfo_data_t arena; |
| 24 | __scudo_mallinfo_data_t ordblks; |
| 25 | __scudo_mallinfo_data_t smblks; |
| 26 | __scudo_mallinfo_data_t hblks; |
| 27 | __scudo_mallinfo_data_t hblkhd; |
| 28 | __scudo_mallinfo_data_t usmblks; |
| 29 | __scudo_mallinfo_data_t fsmblks; |
| 30 | __scudo_mallinfo_data_t uordblks; |
| 31 | __scudo_mallinfo_data_t fordblks; |
| 32 | __scudo_mallinfo_data_t keepcost; |
| 33 | }; |
| 34 | |
| 35 | struct __scudo_mallinfo2 { |
| 36 | size_t arena; |
| 37 | size_t ordblks; |
| 38 | size_t smblks; |
| 39 | size_t hblks; |
| 40 | size_t hblkhd; |
| 41 | size_t usmblks; |
| 42 | size_t fsmblks; |
| 43 | size_t uordblks; |
| 44 | size_t fordblks; |
| 45 | size_t keepcost; |
| 46 | }; |
| 47 | |
| 48 | // Android sometimes includes malloc.h no matter what, which yields to |
| 49 | // conflicting return types for mallinfo() if we use our own structure. So if |
| 50 | // struct mallinfo is declared (#define courtesy of malloc.h), use it directly. |
| 51 | #if STRUCT_MALLINFO_DECLARED |
| 52 | #define SCUDO_MALLINFO mallinfo |
| 53 | #else |
| 54 | #define SCUDO_MALLINFO __scudo_mallinfo |
| 55 | #endif |
| 56 | |
| 57 | #if !SCUDO_ANDROID || !_BIONIC |
| 58 | extern "C" void malloc_postinit(); |
| 59 | extern HIDDEN scudo::Allocator<scudo::Config, malloc_postinit> Allocator; |
| 60 | #endif |
| 61 | |
| 62 | #endif // SCUDO_WRAPPERS_C_H_ |
| 63 | |