| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/mac/objc_zombie.h" | 5 #import "chrome/common/mac/objc_zombie.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <execinfo.h> | 8 #include <execinfo.h> |
| 9 #include <mach-o/dyld.h> | 9 #include <mach-o/dyld.h> |
| 10 #include <mach-o/nlist.h> | 10 #include <mach-o/nlist.h> |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 (*g_objectDestruct)(self); | 192 (*g_objectDestruct)(self); |
| 193 memset(self, '!', size); | 193 memset(self, '!', size); |
| 194 | 194 |
| 195 // If the instance is big enough, make it into a fat zombie and have | 195 // If the instance is big enough, make it into a fat zombie and have |
| 196 // it remember the old |isa|. Otherwise make it a regular zombie. | 196 // it remember the old |isa|. Otherwise make it a regular zombie. |
| 197 // Setting |isa| rather than using |object_setClass()| because that | 197 // Setting |isa| rather than using |object_setClass()| because that |
| 198 // function is implemented with a memory barrier. The runtime's | 198 // function is implemented with a memory barrier. The runtime's |
| 199 // |_internal_object_dispose()| (in objc-class.m) does this, so it | 199 // |_internal_object_dispose()| (in objc-class.m) does this, so it |
| 200 // should be safe (messaging free'd objects shouldn't be expected to | 200 // should be safe (messaging free'd objects shouldn't be expected to |
| 201 // be thread-safe in the first place). | 201 // be thread-safe in the first place). |
| 202 #pragma clang diagnostic push // clang warns about direct access to isa. |
| 203 #pragma clang diagnostic ignored "-Wdeprecated-objc-isa-usage" |
| 202 if (size >= g_fatZombieSize) { | 204 if (size >= g_fatZombieSize) { |
| 203 self->isa = g_fatZombieClass; | 205 self->isa = g_fatZombieClass; |
| 204 static_cast<CrFatZombie*>(self)->wasa = wasa; | 206 static_cast<CrFatZombie*>(self)->wasa = wasa; |
| 205 } else { | 207 } else { |
| 206 self->isa = g_zombieClass; | 208 self->isa = g_zombieClass; |
| 207 } | 209 } |
| 210 #pragma clang diagnostic pop |
| 208 | 211 |
| 209 // The new record to swap into |g_zombies|. If |g_zombieCount| is | 212 // The new record to swap into |g_zombies|. If |g_zombieCount| is |
| 210 // zero, then |self| will be freed immediately. | 213 // zero, then |self| will be freed immediately. |
| 211 ZombieRecord zombieToFree = {self, wasa}; | 214 ZombieRecord zombieToFree = {self, wasa}; |
| 212 zombieToFree.traceDepth = | 215 zombieToFree.traceDepth = |
| 213 std::max(backtrace(zombieToFree.trace, kBacktraceDepth), 0); | 216 std::max(backtrace(zombieToFree.trace, kBacktraceDepth), 0); |
| 214 | 217 |
| 215 // Don't involve the lock when creating zombies without a treadmill. | 218 // Don't involve the lock when creating zombies without a treadmill. |
| 216 if (g_zombieCount > 0) { | 219 if (g_zombieCount > 0) { |
| 217 base::AutoLock pin(g_lock.Get()); | 220 base::AutoLock pin(g_lock.Get()); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 if (oldZombies) { | 556 if (oldZombies) { |
| 554 for (size_t i = 0; i < oldCount; ++i) { | 557 for (size_t i = 0; i < oldCount; ++i) { |
| 555 if (oldZombies[i].object) | 558 if (oldZombies[i].object) |
| 556 object_dispose(oldZombies[i].object); | 559 object_dispose(oldZombies[i].object); |
| 557 } | 560 } |
| 558 free(oldZombies); | 561 free(oldZombies); |
| 559 } | 562 } |
| 560 } | 563 } |
| 561 | 564 |
| 562 } // namespace ObjcEvilDoers | 565 } // namespace ObjcEvilDoers |
| OLD | NEW |