1d89ec533Spatrick //===-- harness.cpp ---------------------------------------------*- C++ -*-===// 2d89ec533Spatrick // 3d89ec533Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4d89ec533Spatrick // See https://llvm.org/LICENSE.txt for license information. 5d89ec533Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6d89ec533Spatrick // 7d89ec533Spatrick //===----------------------------------------------------------------------===// 8d89ec533Spatrick 9d89ec533Spatrick #include "gwp_asan/tests/harness.h" 101f9cb04fSpatrick 111f9cb04fSpatrick namespace gwp_asan { 121f9cb04fSpatrick namespace test { OnlyOnce()131f9cb04fSpatrickbool OnlyOnce() { 141f9cb04fSpatrick static int x = 0; 151f9cb04fSpatrick return !x++; 161f9cb04fSpatrick } 171f9cb04fSpatrick } // namespace test 181f9cb04fSpatrick } // namespace gwp_asan 19*810390e3Srobert 20*810390e3Srobert // Optnone to ensure that the calls to these functions are not optimized away, 21*810390e3Srobert // as we're looking for them in the backtraces. 22*810390e3Srobert __attribute__((optnone)) char * AllocateMemory(gwp_asan::GuardedPoolAllocator & GPA)23*810390e3SrobertAllocateMemory(gwp_asan::GuardedPoolAllocator &GPA) { 24*810390e3Srobert return static_cast<char *>(GPA.allocate(1)); 25*810390e3Srobert } 26*810390e3Srobert __attribute__((optnone)) void DeallocateMemory(gwp_asan::GuardedPoolAllocator & GPA,void * Ptr)27*810390e3SrobertDeallocateMemory(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) { 28*810390e3Srobert GPA.deallocate(Ptr); 29*810390e3Srobert } 30*810390e3Srobert __attribute__((optnone)) void DeallocateMemory2(gwp_asan::GuardedPoolAllocator & GPA,void * Ptr)31*810390e3SrobertDeallocateMemory2(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) { 32*810390e3Srobert GPA.deallocate(Ptr); 33*810390e3Srobert } TouchMemory(void * Ptr)34*810390e3Srobert__attribute__((optnone)) void TouchMemory(void *Ptr) { 35*810390e3Srobert *(reinterpret_cast<volatile char *>(Ptr)) = 7; 36*810390e3Srobert } 37