10b57cec5SDimitry Andric //===-- wrappers_c.h --------------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef SCUDO_WRAPPERS_C_H_ 100b57cec5SDimitry Andric #define SCUDO_WRAPPERS_C_H_ 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "platform.h" 130b57cec5SDimitry Andric #include "stats.h" 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric // Bionic's struct mallinfo consists of size_t (mallinfo(3) uses int). 160b57cec5SDimitry Andric #if SCUDO_ANDROID 170b57cec5SDimitry Andric typedef size_t __scudo_mallinfo_data_t; 180b57cec5SDimitry Andric #else 190b57cec5SDimitry Andric typedef int __scudo_mallinfo_data_t; 200b57cec5SDimitry Andric #endif 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric struct __scudo_mallinfo { 230b57cec5SDimitry Andric __scudo_mallinfo_data_t arena; 240b57cec5SDimitry Andric __scudo_mallinfo_data_t ordblks; 250b57cec5SDimitry Andric __scudo_mallinfo_data_t smblks; 260b57cec5SDimitry Andric __scudo_mallinfo_data_t hblks; 270b57cec5SDimitry Andric __scudo_mallinfo_data_t hblkhd; 280b57cec5SDimitry Andric __scudo_mallinfo_data_t usmblks; 290b57cec5SDimitry Andric __scudo_mallinfo_data_t fsmblks; 300b57cec5SDimitry Andric __scudo_mallinfo_data_t uordblks; 310b57cec5SDimitry Andric __scudo_mallinfo_data_t fordblks; 320b57cec5SDimitry Andric __scudo_mallinfo_data_t keepcost; 330b57cec5SDimitry Andric }; 340b57cec5SDimitry Andric 35349cc55cSDimitry Andric struct __scudo_mallinfo2 { 36349cc55cSDimitry Andric size_t arena; 37349cc55cSDimitry Andric size_t ordblks; 38349cc55cSDimitry Andric size_t smblks; 39349cc55cSDimitry Andric size_t hblks; 40349cc55cSDimitry Andric size_t hblkhd; 41349cc55cSDimitry Andric size_t usmblks; 42349cc55cSDimitry Andric size_t fsmblks; 43349cc55cSDimitry Andric size_t uordblks; 44349cc55cSDimitry Andric size_t fordblks; 45349cc55cSDimitry Andric size_t keepcost; 46349cc55cSDimitry Andric }; 47349cc55cSDimitry Andric 480b57cec5SDimitry Andric // Android sometimes includes malloc.h no matter what, which yields to 490b57cec5SDimitry Andric // conflicting return types for mallinfo() if we use our own structure. So if 500b57cec5SDimitry Andric // struct mallinfo is declared (#define courtesy of malloc.h), use it directly. 510b57cec5SDimitry Andric #if STRUCT_MALLINFO_DECLARED 520b57cec5SDimitry Andric #define SCUDO_MALLINFO mallinfo 530b57cec5SDimitry Andric #else 540b57cec5SDimitry Andric #define SCUDO_MALLINFO __scudo_mallinfo 550b57cec5SDimitry Andric #endif 560b57cec5SDimitry Andric 57*81ad6265SDimitry Andric #if !SCUDO_ANDROID || !_BIONIC 58*81ad6265SDimitry Andric extern "C" void malloc_postinit(); 59*81ad6265SDimitry Andric extern HIDDEN scudo::Allocator<scudo::Config, malloc_postinit> Allocator; 60*81ad6265SDimitry Andric #endif 61*81ad6265SDimitry Andric 620b57cec5SDimitry Andric #endif // SCUDO_WRAPPERS_C_H_ 63