1 //===-- harness.cpp ---------------------------------------------*- 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 #include "gwp_asan/tests/harness.h" 10 11 namespace gwp_asan { 12 namespace test { OnlyOnce()13bool OnlyOnce() { 14 static int x = 0; 15 return !x++; 16 } 17 } // namespace test 18 } // namespace gwp_asan 19 20 // Optnone to ensure that the calls to these functions are not optimized away, 21 // as we're looking for them in the backtraces. 22 __attribute__((optnone)) char * AllocateMemory(gwp_asan::GuardedPoolAllocator & GPA)23AllocateMemory(gwp_asan::GuardedPoolAllocator &GPA) { 24 return static_cast<char *>(GPA.allocate(1)); 25 } 26 __attribute__((optnone)) void DeallocateMemory(gwp_asan::GuardedPoolAllocator & GPA,void * Ptr)27DeallocateMemory(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) { 28 GPA.deallocate(Ptr); 29 } 30 __attribute__((optnone)) void DeallocateMemory2(gwp_asan::GuardedPoolAllocator & GPA,void * Ptr)31DeallocateMemory2(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) { 32 GPA.deallocate(Ptr); 33 } TouchMemory(void * Ptr)34__attribute__((optnone)) void TouchMemory(void *Ptr) { 35 *(reinterpret_cast<volatile char *>(Ptr)) = 7; 36 } 37