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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/Handle.h
diff --git a/Source/platform/heap/Handle.h b/Source/platform/heap/Handle.h
index 28b9d5a4422d977fedbdeb7608eca5a37ee04220..b08159c06ba4b28565bc92e4505ec8fa65082ada 100644
--- a/Source/platform/heap/Handle.h
+++ b/Source/platform/heap/Handle.h
@@ -352,37 +352,41 @@ public:
CrossThreadPersistent(T* raw) : m_raw(raw)
{
+ checkPointer();
recordBacktrace();
}
explicit CrossThreadPersistent(T& raw) : m_raw(&raw)
{
+ checkPointer();
recordBacktrace();
}
- CrossThreadPersistent(const CrossThreadPersistent& other) : m_raw(other) { recordBacktrace(); }
-
- template<typename U>
- CrossThreadPersistent(const CrossThreadPersistent<U>& other) : m_raw(other) { recordBacktrace(); }
-
- template<typename U>
- CrossThreadPersistent(const Member<U>& other) : m_raw(other) { recordBacktrace(); }
+ CrossThreadPersistent(const CrossThreadPersistent& other) : m_raw(other)
+ {
+ checkPointer();
+ recordBacktrace();
+ }
template<typename U>
- CrossThreadPersistent(const RawPtr<U>& other) : m_raw(other.get()) { recordBacktrace(); }
+ CrossThreadPersistent(const CrossThreadPersistent<U>& other) : m_raw(other)
+ {
+ checkPointer();
+ recordBacktrace();
+ }
template<typename U>
- CrossThreadPersistent& operator=(U* other)
+ CrossThreadPersistent(const Member<U>& other) : m_raw(other)
{
- m_raw = other;
+ checkPointer();
recordBacktrace();
- return *this;
}
- CrossThreadPersistent& operator=(std::nullptr_t)
+ template<typename U>
+ CrossThreadPersistent(const RawPtr<U>& other) : m_raw(other.get())
{
- m_raw = nullptr;
- return *this;
+ checkPointer();
+ recordBacktrace();
}
void clear() { m_raw = nullptr; }
@@ -419,9 +423,25 @@ public:
T* operator->() const { return *this; }
+ template<typename U>
+ CrossThreadPersistent& operator=(U* other)
+ {
+ m_raw = other;
+ checkPointer();
+ recordBacktrace();
+ return *this;
+ }
+
+ CrossThreadPersistent& operator=(std::nullptr_t)
+ {
+ m_raw = nullptr;
+ return *this;
+ }
+
CrossThreadPersistent& operator=(const CrossThreadPersistent& other)
{
m_raw = other;
+ checkPointer();
recordBacktrace();
return *this;
}
@@ -430,6 +450,7 @@ public:
CrossThreadPersistent& operator=(const CrossThreadPersistent<U>& other)
{
m_raw = other;
+ checkPointer();
recordBacktrace();
return *this;
}
@@ -438,6 +459,7 @@ public:
CrossThreadPersistent& operator=(const Member<U>& other)
{
m_raw = other;
+ checkPointer();
recordBacktrace();
return *this;
}
@@ -446,6 +468,7 @@ public:
CrossThreadPersistent& operator=(const RawPtr<U>& other)
{
m_raw = other;
+ checkPointer();
recordBacktrace();
return *this;
}
@@ -453,6 +476,23 @@ public:
T* get() const { return m_raw; }
private:
+ void checkPointer()
+ {
+#if ENABLE(ASSERT)
+ if (!m_raw)
+ return;
+ // Heap::isHeapObjectAlive(m_raw) checks that m_raw is a traceable
+ // object. In other words, it checks that the pointer is either of:
+ //
+ // (a) a pointer to the head of an on-heap object.
+ // (b) a pointer to the head of an on-heap mixin object.
+ //
+ // Otherwise, Heap::isHeapObjectAlive will crash when it calls
+ // header->checkHeader().
+ Heap::isHeapObjectAlive(m_raw);
+#endif
+ }
+
#if ENABLE(GC_PROFILING)
void recordBacktrace()
{
« 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