| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef Persistent_h | 5 #ifndef Persistent_h |
| 6 #define Persistent_h | 6 #define Persistent_h |
| 7 | 7 |
| 8 #include "platform/heap/Heap.h" | 8 #include "platform/heap/Heap.h" |
| 9 #include "platform/heap/Member.h" | 9 #include "platform/heap/Member.h" |
| 10 #include "platform/heap/PersistentNode.h" | 10 #include "platform/heap/PersistentNode.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); | 220 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); |
| 221 ASSERT(state->checkThread()); | 221 ASSERT(state->checkThread()); |
| 222 m_persistentNode = state->getPersistentRegion()->allocatePersistentNode( | 222 m_persistentNode = state->getPersistentRegion()->allocatePersistentNode( |
| 223 this, traceCallback); | 223 this, traceCallback); |
| 224 #if ENABLE(ASSERT) | 224 #if ENABLE(ASSERT) |
| 225 m_state = state; | 225 m_state = state; |
| 226 #endif | 226 #endif |
| 227 } | 227 } |
| 228 | 228 |
| 229 void uninitialize() { | 229 void uninitialize() { |
| 230 // TODO(haraken): This is a short-term hack to prevent use-after-frees |
| 231 // during a shutdown sequence. |
| 232 // 1) blink::shutdown() frees the underlying storage for persistent nodes. |
| 233 // 2) ~MessageLoop() destructs some Chromium-side objects that hold |
| 234 // Persistent. It touches the underlying storage and crashes. |
| 235 if (WTF::isShutdown()) |
| 236 return; |
| 237 |
| 230 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { | 238 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { |
| 231 if (acquireLoad(reinterpret_cast<void* volatile*>(&m_persistentNode))) | 239 if (acquireLoad(reinterpret_cast<void* volatile*>(&m_persistentNode))) |
| 232 ProcessHeap::crossThreadPersistentRegion().freePersistentNode( | 240 ProcessHeap::crossThreadPersistentRegion().freePersistentNode( |
| 233 m_persistentNode); | 241 m_persistentNode); |
| 234 return; | 242 return; |
| 235 } | 243 } |
| 236 | 244 |
| 237 if (!m_persistentNode) | 245 if (!m_persistentNode) |
| 238 return; | 246 return; |
| 239 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); | 247 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 static blink::CrossThreadPersistent<T> Unwrap( | 811 static blink::CrossThreadPersistent<T> Unwrap( |
| 804 const blink::CrossThreadWeakPersistent<T>& wrapped) { | 812 const blink::CrossThreadWeakPersistent<T>& wrapped) { |
| 805 blink::CrossThreadPersistentRegion::LockScope persistentLock( | 813 blink::CrossThreadPersistentRegion::LockScope persistentLock( |
| 806 blink::ProcessHeap::crossThreadPersistentRegion()); | 814 blink::ProcessHeap::crossThreadPersistentRegion()); |
| 807 return blink::CrossThreadPersistent<T>(wrapped.get()); | 815 return blink::CrossThreadPersistent<T>(wrapped.get()); |
| 808 } | 816 } |
| 809 }; | 817 }; |
| 810 } | 818 } |
| 811 | 819 |
| 812 #endif // Persistent_h | 820 #endif // Persistent_h |
| OLD | NEW |