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

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

Issue 1143323004: Oilpan: Validate pointers stored in CrossThreadPersistent (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 | no next file » | 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // different from the construction thread. 345 // different from the construction thread.
346 template<typename T> 346 template<typename T>
347 class CrossThreadPersistent : public PersistentBase<GlobalPersistents, CrossThre adPersistent<T>> { 347 class CrossThreadPersistent : public PersistentBase<GlobalPersistents, CrossThre adPersistent<T>> {
348 public: 348 public:
349 CrossThreadPersistent() : m_raw(nullptr) { } 349 CrossThreadPersistent() : m_raw(nullptr) { }
350 350
351 CrossThreadPersistent(std::nullptr_t) : m_raw(nullptr) { } 351 CrossThreadPersistent(std::nullptr_t) : m_raw(nullptr) { }
352 352
353 CrossThreadPersistent(T* raw) : m_raw(raw) 353 CrossThreadPersistent(T* raw) : m_raw(raw)
354 { 354 {
355 checkPointer();
355 recordBacktrace(); 356 recordBacktrace();
356 } 357 }
357 358
358 explicit CrossThreadPersistent(T& raw) : m_raw(&raw) 359 explicit CrossThreadPersistent(T& raw) : m_raw(&raw)
359 { 360 {
361 checkPointer();
360 recordBacktrace(); 362 recordBacktrace();
361 } 363 }
362 364
363 CrossThreadPersistent(const CrossThreadPersistent& other) : m_raw(other) { r ecordBacktrace(); } 365 CrossThreadPersistent(const CrossThreadPersistent& other) : m_raw(other)
366 {
367 checkPointer();
368 recordBacktrace();
369 }
364 370
365 template<typename U> 371 template<typename U>
366 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : m_raw(other) { recordBacktrace(); } 372 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : m_raw(other)
373 {
374 checkPointer();
375 recordBacktrace();
376 }
367 377
368 template<typename U> 378 template<typename U>
369 CrossThreadPersistent(const Member<U>& other) : m_raw(other) { recordBacktra ce(); } 379 CrossThreadPersistent(const Member<U>& other) : m_raw(other)
380 {
381 checkPointer();
382 recordBacktrace();
383 }
370 384
371 template<typename U> 385 template<typename U>
372 CrossThreadPersistent(const RawPtr<U>& other) : m_raw(other.get()) { recordB acktrace(); } 386 CrossThreadPersistent(const RawPtr<U>& other) : m_raw(other.get())
373
374 template<typename U>
375 CrossThreadPersistent& operator=(U* other)
376 { 387 {
377 m_raw = other; 388 checkPointer();
378 recordBacktrace(); 389 recordBacktrace();
379 return *this;
380 }
381
382 CrossThreadPersistent& operator=(std::nullptr_t)
383 {
384 m_raw = nullptr;
385 return *this;
386 } 390 }
387 391
388 void clear() { m_raw = nullptr; } 392 void clear() { m_raw = nullptr; }
389 393
390 virtual ~CrossThreadPersistent() 394 virtual ~CrossThreadPersistent()
391 { 395 {
392 m_raw = nullptr; 396 m_raw = nullptr;
393 } 397 }
394 398
395 template<typename VisitorDispatcher> 399 template<typename VisitorDispatcher>
(...skipping 16 matching lines...) Expand all
412 416
413 T& operator*() const { return *m_raw; } 417 T& operator*() const { return *m_raw; }
414 418
415 bool operator!() const { return !m_raw; } 419 bool operator!() const { return !m_raw; }
416 420
417 operator T*() const { return m_raw; } 421 operator T*() const { return m_raw; }
418 operator RawPtr<T>() const { return m_raw; } 422 operator RawPtr<T>() const { return m_raw; }
419 423
420 T* operator->() const { return *this; } 424 T* operator->() const { return *this; }
421 425
426 template<typename U>
427 CrossThreadPersistent& operator=(U* other)
428 {
429 m_raw = other;
430 checkPointer();
431 recordBacktrace();
432 return *this;
433 }
434
435 CrossThreadPersistent& operator=(std::nullptr_t)
436 {
437 m_raw = nullptr;
438 return *this;
439 }
440
422 CrossThreadPersistent& operator=(const CrossThreadPersistent& other) 441 CrossThreadPersistent& operator=(const CrossThreadPersistent& other)
423 { 442 {
424 m_raw = other; 443 m_raw = other;
444 checkPointer();
425 recordBacktrace(); 445 recordBacktrace();
426 return *this; 446 return *this;
427 } 447 }
428 448
429 template<typename U> 449 template<typename U>
430 CrossThreadPersistent& operator=(const CrossThreadPersistent<U>& other) 450 CrossThreadPersistent& operator=(const CrossThreadPersistent<U>& other)
431 { 451 {
432 m_raw = other; 452 m_raw = other;
453 checkPointer();
433 recordBacktrace(); 454 recordBacktrace();
434 return *this; 455 return *this;
435 } 456 }
436 457
437 template<typename U> 458 template<typename U>
438 CrossThreadPersistent& operator=(const Member<U>& other) 459 CrossThreadPersistent& operator=(const Member<U>& other)
439 { 460 {
440 m_raw = other; 461 m_raw = other;
462 checkPointer();
441 recordBacktrace(); 463 recordBacktrace();
442 return *this; 464 return *this;
443 } 465 }
444 466
445 template<typename U> 467 template<typename U>
446 CrossThreadPersistent& operator=(const RawPtr<U>& other) 468 CrossThreadPersistent& operator=(const RawPtr<U>& other)
447 { 469 {
448 m_raw = other; 470 m_raw = other;
471 checkPointer();
449 recordBacktrace(); 472 recordBacktrace();
450 return *this; 473 return *this;
451 } 474 }
452 475
453 T* get() const { return m_raw; } 476 T* get() const { return m_raw; }
454 477
455 private: 478 private:
479 void checkPointer()
480 {
481 #if ENABLE(ASSERT)
482 if (!m_raw)
483 return;
484 // Heap::isHeapObjectAlive(m_raw) checks that m_raw is a traceable
485 // object. In other words, it checks that the pointer is either of:
486 //
487 // (a) a pointer to the head of an on-heap object.
488 // (b) a pointer to the head of an on-heap mixin object.
489 //
490 // Otherwise, Heap::isHeapObjectAlive will crash when it calls
491 // header->checkHeader().
492 Heap::isHeapObjectAlive(m_raw);
493 #endif
494 }
495
456 #if ENABLE(GC_PROFILING) 496 #if ENABLE(GC_PROFILING)
457 void recordBacktrace() 497 void recordBacktrace()
458 { 498 {
459 if (m_raw) 499 if (m_raw)
460 m_tracingName = Heap::createBacktraceString(); 500 m_tracingName = Heap::createBacktraceString();
461 } 501 }
462 502
463 String m_tracingName; 503 String m_tracingName;
464 #else 504 #else
465 inline void recordBacktrace() const { } 505 inline void recordBacktrace() const { }
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin k::IsGarbageCollectedType<T>::value> { 1220 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin k::IsGarbageCollectedType<T>::value> {
1181 static_assert(sizeof(T), "T must be fully defined"); 1221 static_assert(sizeof(T), "T must be fully defined");
1182 }; 1222 };
1183 1223
1184 template<typename T> 1224 template<typename T>
1185 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; 1225 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete;
1186 1226
1187 } // namespace WTF 1227 } // namespace WTF
1188 1228
1189 #endif 1229 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698