1861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris/* 2861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * Copyright (C) 2014 The Android Open Source Project 3861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * All rights reserved. 4861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * 5861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * Redistribution and use in source and binary forms, with or without 6861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * modification, are permitted provided that the following conditions 7861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * are met: 8861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * * Redistributions of source code must retain the above copyright 9861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * notice, this list of conditions and the following disclaimer. 10861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * * Redistributions in binary form must reproduce the above copyright 11861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * notice, this list of conditions and the following disclaimer in 12861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * the documentation and/or other materials provided with the 13861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * distribution. 14861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * 15861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris * SUCH DAMAGE. 27861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris */ 28861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris 29cbc80ba9d839675a0c4891e2ab33f39ba51b04b2Elliott Hughes#pragma once 30861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris 3163860cb8fd1adf3f679b9b4ad876323a8d65cd9dChristopher Ferris#include <sys/cdefs.h> 32861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris 3363860cb8fd1adf3f679b9b4ad876323a8d65cd9dChristopher Ferris#include <private/bionic_macros.h> 34861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris 35861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris// ============================================================================= 36861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris// Used to disable the debug allocation calls. 37861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris// ============================================================================= 3863860cb8fd1adf3f679b9b4ad876323a8d65cd9dChristopher Ferrisbool DebugDisableInitialize(); 3963860cb8fd1adf3f679b9b4ad876323a8d65cd9dChristopher Ferrisvoid DebugDisableFinalize(); 40861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris 4163860cb8fd1adf3f679b9b4ad876323a8d65cd9dChristopher Ferrisbool DebugCallsDisabled(); 4263860cb8fd1adf3f679b9b4ad876323a8d65cd9dChristopher Ferrisvoid DebugDisableSet(bool disable); 43861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris 44861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferrisclass ScopedDisableDebugCalls { 45861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris public: 46861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris ScopedDisableDebugCalls() : disabled_(DebugCallsDisabled()) { 47861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris if (!disabled_) { 4863860cb8fd1adf3f679b9b4ad876323a8d65cd9dChristopher Ferris DebugDisableSet(true); 49861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris } 50861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris } 51861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris ~ScopedDisableDebugCalls() { 52861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris if (!disabled_) { 5363860cb8fd1adf3f679b9b4ad876323a8d65cd9dChristopher Ferris DebugDisableSet(false); 54861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris } 55861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris } 56861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris 57861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris private: 58861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris bool disabled_; 59861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris 60861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris DISALLOW_COPY_AND_ASSIGN(ScopedDisableDebugCalls); 61861c0ef37bcfcae56d88572cb01c18bcfe1fadedChristopher Ferris}; 62