Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: third_party/WebKit/Source/platform/heap/Persistent.h

Issue 2702243003: Disallow cross-thread Persistent<> read access. (Closed)
Patch Set: rebased upto r451733 Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return m_raw == reinterpret_cast<T*>(-1); 102 return m_raw == reinterpret_cast<T*>(-1);
103 } 103 }
104 104
105 T* release() { 105 T* release() {
106 T* result = m_raw; 106 T* result = m_raw;
107 assign(nullptr); 107 assign(nullptr);
108 return result; 108 return result;
109 } 109 }
110 110
111 void clear() { assign(nullptr); } 111 void clear() { assign(nullptr); }
112 T& operator*() const { return *m_raw; } 112 T& operator*() const {
113 checkPointer();
114 return *m_raw;
115 }
113 explicit operator bool() const { return m_raw; } 116 explicit operator bool() const { return m_raw; }
114 operator T*() const { return m_raw; } 117 operator T*() const {
118 checkPointer();
119 return m_raw;
120 }
115 T* operator->() const { return *this; } 121 T* operator->() const { return *this; }
116 T* get() const { return m_raw; } 122
123 T* get() const {
124 checkPointer();
125 return m_raw;
126 }
117 127
118 template <typename U> 128 template <typename U>
119 PersistentBase& operator=(U* other) { 129 PersistentBase& operator=(U* other) {
120 assign(other); 130 assign(other);
121 return *this; 131 return *this;
122 } 132 }
123 133
124 PersistentBase& operator=(std::nullptr_t) { 134 PersistentBase& operator=(std::nullptr_t) {
125 assign(nullptr); 135 assign(nullptr);
126 return *this; 136 return *this;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if (!m_persistentNode) 246 if (!m_persistentNode)
237 return; 247 return;
238 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); 248 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state();
239 ASSERT(state->checkThread()); 249 ASSERT(state->checkThread());
240 // Persistent handle must be created and destructed in the same thread. 250 // Persistent handle must be created and destructed in the same thread.
241 ASSERT(m_state == state); 251 ASSERT(m_state == state);
242 state->freePersistentNode(m_persistentNode); 252 state->freePersistentNode(m_persistentNode);
243 m_persistentNode = nullptr; 253 m_persistentNode = nullptr;
244 } 254 }
245 255
246 void checkPointer() { 256 void checkPointer() const {
247 #if DCHECK_IS_ON() 257 #if DCHECK_IS_ON()
248 if (!m_raw || isHashTableDeletedValue()) 258 if (!m_raw || isHashTableDeletedValue())
249 return; 259 return;
250 260
251 if (crossThreadnessConfiguration != CrossThreadPersistentConfiguration) { 261 if (crossThreadnessConfiguration != CrossThreadPersistentConfiguration) {
252 ThreadState* current = ThreadState::current(); 262 ThreadState* current = ThreadState::current();
253 DCHECK(current); 263 DCHECK(current);
254 // m_creationThreadState may be null when this is used in a heap 264 // m_creationThreadState may be null when this is used in a heap
255 // collection which initialized the Persistent with memset and the 265 // collection which initialized the Persistent with memset and the
256 // constructor wasn't called. 266 // constructor wasn't called.
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 static blink::CrossThreadPersistent<T> Unwrap( 803 static blink::CrossThreadPersistent<T> Unwrap(
794 const blink::CrossThreadWeakPersistent<T>& wrapped) { 804 const blink::CrossThreadWeakPersistent<T>& wrapped) {
795 blink::CrossThreadPersistentRegion::LockScope persistentLock( 805 blink::CrossThreadPersistentRegion::LockScope persistentLock(
796 blink::ProcessHeap::crossThreadPersistentRegion()); 806 blink::ProcessHeap::crossThreadPersistentRegion());
797 return blink::CrossThreadPersistent<T>(wrapped.get()); 807 return blink::CrossThreadPersistent<T>(wrapped.get());
798 } 808 }
799 }; 809 };
800 } 810 }
801 811
802 #endif // Persistent_h 812 #endif // Persistent_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698