OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/objc_zombie.h" | 5 #import "chrome/browser/ui/cocoa/objc_zombie.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <mach-o/dyld.h> | 8 #include <mach-o/dyld.h> |
9 #include <mach-o/nlist.h> | 9 #include <mach-o/nlist.h> |
10 | 10 |
11 #import <objc/objc-class.h> | 11 #import <objc/objc-class.h> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/mac/mac_util.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
16 #include "base/sys_info.h" | |
17 #import "chrome/app/breakpad_mac.h" | 17 #import "chrome/app/breakpad_mac.h" |
18 #import "chrome/browser/ui/cocoa/objc_method_swizzle.h" | 18 #import "chrome/browser/ui/cocoa/objc_method_swizzle.h" |
19 | 19 |
20 // Deallocated objects are re-classed as |CrZombie|. No superclass | 20 // Deallocated objects are re-classed as |CrZombie|. No superclass |
21 // because then the class would have to override many/most of the | 21 // because then the class would have to override many/most of the |
22 // inherited methods (|NSObject| is like a category magnet!). | 22 // inherited methods (|NSObject| is like a category magnet!). |
23 @interface CrZombie { | 23 @interface CrZombie { |
24 Class isa; | 24 Class isa; |
25 } | 25 } |
26 @end | 26 @end |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 UMA_HISTOGRAM_ENUMERATION("OSX.ZombieInitFailure", failure, FAILED_MAX); | 272 UMA_HISTOGRAM_ENUMERATION("OSX.ZombieInitFailure", failure, FAILED_MAX); |
273 } | 273 } |
274 | 274 |
275 // Initialize our globals, returning YES on success. | 275 // Initialize our globals, returning YES on success. |
276 BOOL ZombieInit() { | 276 BOOL ZombieInit() { |
277 static BOOL initialized = NO; | 277 static BOOL initialized = NO; |
278 if (initialized) | 278 if (initialized) |
279 return YES; | 279 return YES; |
280 | 280 |
281 // Whitelist releases that are compatible with objc zombies. | 281 // Whitelist releases that are compatible with objc zombies. |
282 int32 major_version = 0, minor_version = 0, bugfix_version = 0; | 282 if (base::mac::IsOSLeopard()) { |
283 base::SysInfo::OperatingSystemVersionNumbers( | |
284 &major_version, &minor_version, &bugfix_version); | |
285 | |
286 if (major_version < 10 || (major_version == 10 && minor_version < 5)) { | |
287 return NO; | |
288 } else if (major_version == 10 && minor_version == 5) { | |
289 g_objectDestruct = LookupObjectDestruct_10_5(); | 283 g_objectDestruct = LookupObjectDestruct_10_5(); |
290 if (!g_objectDestruct) { | 284 if (!g_objectDestruct) { |
291 RecordZombieFailure(FAILED_10_5); | 285 RecordZombieFailure(FAILED_10_5); |
292 return NO; | 286 return NO; |
293 } | 287 } |
294 } else if (major_version == 10 && minor_version == 6) { | 288 } else if (base::mac::IsOSSnowLeopard()) { |
295 g_objectDestruct = LookupObjectDestruct_10_6(); | 289 g_objectDestruct = LookupObjectDestruct_10_6(); |
296 if (!g_objectDestruct) { | 290 if (!g_objectDestruct) { |
297 RecordZombieFailure(FAILED_10_6); | 291 RecordZombieFailure(FAILED_10_6); |
298 return NO; | 292 return NO; |
299 } | 293 } |
300 } else { | 294 } else if (base::mac::IsOSLionOrLater()) { |
301 // Assume the future looks like the present. | 295 // Assume the future looks like the present. |
302 g_objectDestruct = LookupObjectDestruct_10_6(); | 296 g_objectDestruct = LookupObjectDestruct_10_6(); |
303 | 297 |
304 // Put all future failures into the MAX bin. New OS releases come | 298 // Put all future failures into the MAX bin. New OS releases come |
305 // out infrequently enough that this should always correspond to | 299 // out infrequently enough that this should always correspond to |
306 // "Next release", and once the next release happens that bin will | 300 // "Next release", and once the next release happens that bin will |
307 // get an official name. | 301 // get an official name. |
308 if (!g_objectDestruct) { | 302 if (!g_objectDestruct) { |
309 RecordZombieFailure(FAILED_MAX); | 303 RecordZombieFailure(FAILED_MAX); |
310 return NO; | 304 return NO; |
311 } | 305 } |
| 306 } else { |
| 307 return NO; |
312 } | 308 } |
313 | 309 |
314 Class rootClass = [NSObject class]; | 310 Class rootClass = [NSObject class]; |
315 g_originalDeallocIMP = | 311 g_originalDeallocIMP = |
316 class_getMethodImplementation(rootClass, @selector(dealloc)); | 312 class_getMethodImplementation(rootClass, @selector(dealloc)); |
317 // objc_getClass() so CrZombie doesn't need +class. | 313 // objc_getClass() so CrZombie doesn't need +class. |
318 g_zombieClass = objc_getClass("CrZombie"); | 314 g_zombieClass = objc_getClass("CrZombie"); |
319 g_fatZombieClass = objc_getClass("CrFatZombie"); | 315 g_fatZombieClass = objc_getClass("CrFatZombie"); |
320 g_fatZombieSize = class_getInstanceSize(g_fatZombieClass); | 316 g_fatZombieSize = class_getInstanceSize(g_fatZombieClass); |
321 | 317 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 if (oldZombies) { | 493 if (oldZombies) { |
498 for (size_t i = 0; i < oldCount; ++i) { | 494 for (size_t i = 0; i < oldCount; ++i) { |
499 if (oldZombies[i].object) | 495 if (oldZombies[i].object) |
500 object_dispose(oldZombies[i].object); | 496 object_dispose(oldZombies[i].object); |
501 } | 497 } |
502 free(oldZombies); | 498 free(oldZombies); |
503 } | 499 } |
504 } | 500 } |
505 | 501 |
506 } // namespace ObjcEvilDoers | 502 } // namespace ObjcEvilDoers |
OLD | NEW |