15ffd83dbSDimitry Andric //===-- utilities.h ---------------------------------------------*- C++ -*-===// 25ffd83dbSDimitry Andric // 35ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 55ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65ffd83dbSDimitry Andric // 75ffd83dbSDimitry Andric //===----------------------------------------------------------------------===// 85ffd83dbSDimitry Andric 9*e8d8bef9SDimitry Andric #ifndef GWP_ASAN_UTILITIES_H_ 10*e8d8bef9SDimitry Andric #define GWP_ASAN_UTILITIES_H_ 11*e8d8bef9SDimitry Andric 125ffd83dbSDimitry Andric #include "gwp_asan/definitions.h" 135ffd83dbSDimitry Andric 145ffd83dbSDimitry Andric #include <stddef.h> 155ffd83dbSDimitry Andric 165ffd83dbSDimitry Andric namespace gwp_asan { 17*e8d8bef9SDimitry Andric // Terminates in a platform-specific way with `Message`. 18*e8d8bef9SDimitry Andric void die(const char *Message); 19*e8d8bef9SDimitry Andric 20*e8d8bef9SDimitry Andric // Checks that `Condition` is true, otherwise dies with `Message`. 21*e8d8bef9SDimitry Andric GWP_ASAN_ALWAYS_INLINE void Check(bool Condition, const char *Message) { 22*e8d8bef9SDimitry Andric if (Condition) 23*e8d8bef9SDimitry Andric return; 24*e8d8bef9SDimitry Andric die(Message); 25*e8d8bef9SDimitry Andric } 265ffd83dbSDimitry Andric 275ffd83dbSDimitry Andric enum class AlignmentStrategy { 285ffd83dbSDimitry Andric // Default => POWER_OF_TWO on most platforms, BIONIC for Android Bionic. 295ffd83dbSDimitry Andric DEFAULT, 305ffd83dbSDimitry Andric POWER_OF_TWO, 315ffd83dbSDimitry Andric BIONIC, 325ffd83dbSDimitry Andric PERFECT, 335ffd83dbSDimitry Andric }; 345ffd83dbSDimitry Andric 355ffd83dbSDimitry Andric // Returns the real size of a right-aligned allocation. 365ffd83dbSDimitry Andric size_t rightAlignedAllocationSize( 375ffd83dbSDimitry Andric size_t RealAllocationSize, 385ffd83dbSDimitry Andric AlignmentStrategy Align = AlignmentStrategy::DEFAULT); 395ffd83dbSDimitry Andric } // namespace gwp_asan 40*e8d8bef9SDimitry Andric 41*e8d8bef9SDimitry Andric #endif // GWP_ASAN_UTILITIES_H_ 42