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

Side by Side Diff: Source/platform/heap/Handle.h

Issue 1146373002: Oilpan: Validate pointers stored in Persistent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // We have to construct and destruct Persistent in the same thread. 217 // We have to construct and destruct Persistent in the same thread.
218 template<typename T> 218 template<typename T>
219 class Persistent : public PersistentBase<ThreadLocalPersistents<ThreadingTrait<T >::Affinity>, Persistent<T>> { 219 class Persistent : public PersistentBase<ThreadLocalPersistents<ThreadingTrait<T >::Affinity>, Persistent<T>> {
220 public: 220 public:
221 Persistent() : m_raw(nullptr) { } 221 Persistent() : m_raw(nullptr) { }
222 222
223 Persistent(std::nullptr_t) : m_raw(nullptr) { } 223 Persistent(std::nullptr_t) : m_raw(nullptr) { }
224 224
225 Persistent(T* raw) : m_raw(raw) 225 Persistent(T* raw) : m_raw(raw)
226 { 226 {
227 ASSERT(!m_raw || ThreadStateFor<ThreadingTrait<T>::Affinity>::state()->f indPageFromAddress(m_raw)); 227 checkPointer();
228 recordBacktrace(); 228 recordBacktrace();
229 } 229 }
230 230
231 explicit Persistent(T& raw) : m_raw(&raw) 231 explicit Persistent(T& raw) : m_raw(&raw)
232 { 232 {
233 ASSERT(!m_raw || ThreadStateFor<ThreadingTrait<T>::Affinity>::state()->f indPageFromAddress(m_raw)); 233 checkPointer();
234 recordBacktrace(); 234 recordBacktrace();
235 } 235 }
236 236
237 Persistent(const Persistent& other) : m_raw(other) { recordBacktrace(); } 237 Persistent(const Persistent& other) : m_raw(other)
238 {
239 checkPointer();
240 recordBacktrace();
241 }
238 242
239 template<typename U> 243 template<typename U>
240 Persistent(const Persistent<U>& other) : m_raw(other) { recordBacktrace(); } 244 Persistent(const Persistent<U>& other) : m_raw(other)
245 {
246 checkPointer();
247 recordBacktrace();
248 }
241 249
242 template<typename U> 250 template<typename U>
243 Persistent(const Member<U>& other) : m_raw(other) { recordBacktrace(); } 251 Persistent(const Member<U>& other) : m_raw(other)
252 {
253 checkPointer();
254 recordBacktrace();
255 }
244 256
245 template<typename U> 257 template<typename U>
246 Persistent(const RawPtr<U>& other) : m_raw(other.get()) { recordBacktrace(); } 258 Persistent(const RawPtr<U>& other) : m_raw(other.get())
247
248 template<typename U>
249 Persistent& operator=(U* other)
250 { 259 {
251 m_raw = other; 260 checkPointer();
252 recordBacktrace(); 261 recordBacktrace();
253 return *this;
254 }
255
256 Persistent& operator=(std::nullptr_t)
257 {
258 m_raw = nullptr;
259 return *this;
260 } 262 }
261 263
262 void clear() { m_raw = nullptr; } 264 void clear() { m_raw = nullptr; }
263 265
264 virtual ~Persistent() 266 virtual ~Persistent()
265 { 267 {
266 m_raw = nullptr; 268 m_raw = nullptr;
267 } 269 }
268 270
269 template<typename VisitorDispatcher> 271 template<typename VisitorDispatcher>
(...skipping 16 matching lines...) Expand all
286 288
287 T& operator*() const { return *m_raw; } 289 T& operator*() const { return *m_raw; }
288 290
289 bool operator!() const { return !m_raw; } 291 bool operator!() const { return !m_raw; }
290 292
291 operator T*() const { return m_raw; } 293 operator T*() const { return m_raw; }
292 operator RawPtr<T>() const { return m_raw; } 294 operator RawPtr<T>() const { return m_raw; }
293 295
294 T* operator->() const { return *this; } 296 T* operator->() const { return *this; }
295 297
298 template<typename U>
299 Persistent& operator=(U* other)
300 {
301 m_raw = other;
302 checkPointer();
303 recordBacktrace();
304 return *this;
305 }
306
307 Persistent& operator=(std::nullptr_t)
308 {
309 m_raw = nullptr;
310 return *this;
311 }
312
296 Persistent& operator=(const Persistent& other) 313 Persistent& operator=(const Persistent& other)
297 { 314 {
298 m_raw = other; 315 m_raw = other;
316 checkPointer();
299 recordBacktrace(); 317 recordBacktrace();
300 return *this; 318 return *this;
301 } 319 }
302 320
303 template<typename U> 321 template<typename U>
304 Persistent& operator=(const Persistent<U>& other) 322 Persistent& operator=(const Persistent<U>& other)
305 { 323 {
306 m_raw = other; 324 m_raw = other;
325 checkPointer();
307 recordBacktrace(); 326 recordBacktrace();
308 return *this; 327 return *this;
309 } 328 }
310 329
311 template<typename U> 330 template<typename U>
312 Persistent& operator=(const Member<U>& other) 331 Persistent& operator=(const Member<U>& other)
313 { 332 {
314 m_raw = other; 333 m_raw = other;
334 checkPointer();
315 recordBacktrace(); 335 recordBacktrace();
316 return *this; 336 return *this;
317 } 337 }
318 338
319 template<typename U> 339 template<typename U>
320 Persistent& operator=(const RawPtr<U>& other) 340 Persistent& operator=(const RawPtr<U>& other)
321 { 341 {
322 m_raw = other; 342 m_raw = other;
343 checkPointer();
323 recordBacktrace(); 344 recordBacktrace();
324 return *this; 345 return *this;
325 } 346 }
326 347
327 T* get() const { return m_raw; } 348 T* get() const { return m_raw; }
328 349
329 private: 350 private:
351 void checkPointer()
352 {
353 #if ENABLE(ASSERT)
354 if (!m_raw)
355 return;
356
357 // Heap::isHeapObjectAlive(m_raw) checks that m_raw is a traceable
358 // object. In other words, it checks that the pointer is either of:
359 //
360 // (a) a pointer to the head of an on-heap object.
361 // (b) a pointer to the head of an on-heap mixin object.
362 //
363 // Otherwise, Heap::isHeapObjectAlive will crash when it calls
364 // header->checkHeader().
365 Heap::isHeapObjectAlive(m_raw);
366 #endif
367 }
368
330 #if ENABLE(GC_PROFILING) 369 #if ENABLE(GC_PROFILING)
331 void recordBacktrace() 370 void recordBacktrace()
332 { 371 {
333 if (m_raw) 372 if (m_raw)
334 m_tracingName = Heap::createBacktraceString(); 373 m_tracingName = Heap::createBacktraceString();
335 } 374 }
336 375
337 String m_tracingName; 376 String m_tracingName;
338 #else 377 #else
339 inline void recordBacktrace() const { } 378 inline void recordBacktrace() const { }
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 // as a valid pointer. 719 // as a valid pointer.
681 if (reinterpret_cast<intptr_t>(m_raw) % allocationGranularity) 720 if (reinterpret_cast<intptr_t>(m_raw) % allocationGranularity)
682 return; 721 return;
683 722
684 // TODO(haraken): What we really want to check here is that the pointer 723 // TODO(haraken): What we really want to check here is that the pointer
685 // is a traceable object. In other words, the pointer is either of: 724 // is a traceable object. In other words, the pointer is either of:
686 // 725 //
687 // (a) a pointer to the head of an on-heap object. 726 // (a) a pointer to the head of an on-heap object.
688 // (b) a pointer to the head of an on-heap mixin object. 727 // (b) a pointer to the head of an on-heap mixin object.
689 // 728 //
690 // We can check it by calling visitor->isHeapObjectAlive(m_raw), 729 // We can check it by calling Heap::isHeapObjectAlive(m_raw),
691 // but we cannot call it here because it requres to include T.h. 730 // but we cannot call it here because it requres to include T.h.
692 // So we currently implement only the check for (a). 731 // So we currently implement only the check for (a).
693 if (!IsGarbageCollectedMixin<T>::value) 732 if (!IsGarbageCollectedMixin<T>::value)
694 HeapObjectHeader::fromPayload(m_raw)->checkHeader(); 733 HeapObjectHeader::fromPayload(m_raw)->checkHeader();
695 #endif 734 #endif
696 } 735 }
697 736
698 T* m_raw; 737 T* m_raw;
699 738
700 template<bool x, WTF::WeakHandlingFlag y, WTF::ShouldWeakPointersBeMarkedStr ongly z, typename U, typename V> friend struct CollectionBackingTraceTrait; 739 template<bool x, WTF::WeakHandlingFlag y, WTF::ShouldWeakPointersBeMarkedStr ongly z, typename U, typename V> friend struct CollectionBackingTraceTrait;
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin k::IsGarbageCollectedType<T>::value> { 1219 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin k::IsGarbageCollectedType<T>::value> {
1181 static_assert(sizeof(T), "T must be fully defined"); 1220 static_assert(sizeof(T), "T must be fully defined");
1182 }; 1221 };
1183 1222
1184 template<typename T> 1223 template<typename T>
1185 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; 1224 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete;
1186 1225
1187 } // namespace WTF 1226 } // namespace WTF
1188 1227
1189 #endif 1228 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698