1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_COMMON_MAC_OBJC_ZOMBIE_H_ 6 #define CHROME_COMMON_MAC_OBJC_ZOMBIE_H_ 7 8 #include "base/basictypes.h" 9 10 // You should think twice every single time you use anything from this 11 // namespace. 12 namespace ObjcEvilDoers { 13 14 // Enable zombie object debugging. This implements a variant of Apple's 15 // NSZombieEnabled which can help expose use-after-free errors where messages 16 // are sent to freed Objective-C objects in production builds. 17 // 18 // Returns NO if it fails to enable. 19 // 20 // When |zombieAllObjects| is YES, all objects inheriting from 21 // NSObject become zombies on -dealloc. If NO, -shouldBecomeCrZombie 22 // is queried to determine whether to make the object a zombie. 23 // 24 // |zombieCount| controls how many zombies to store before freeing the 25 // oldest. Set to 0 to free objects immediately after making them 26 // zombies. 27 bool ZombieEnable(bool zombieAllObjects, size_t zombieCount); 28 29 // Disable zombies. 30 void ZombieDisable(); 31 32 } // namespace ObjcEvilDoers 33 34 #if defined(OS_MACOSX) 35 #if defined(__OBJC__) 36 37 #import <Foundation/Foundation.h> 38 39 @interface NSObject (CrZombie) 40 - (BOOL)shouldBecomeCrZombie; 41 @end 42 43 #endif // __OBJC__ 44 #endif // OS_MACOSX 45 46 #endif // CHROME_COMMON_MAC_OBJC_ZOMBIE_H_ 47