Commit 1dc2c44e authored by vegorov@chromium.org's avatar vegorov@chromium.org

Clear JS function result caches in all global contexts.

Original patch by Mark Lam <mark.lam@palm.com> from Hewlett-Packard Development Company, LP. (http://codereview.chromium.org/4187007)

Fix memory corruption in JSFunctionResultCache::Clear caused by out of bounds writes which was revealed by the patch.

Review URL: http://codereview.chromium.org/4200009

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5738 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 302abe30
...@@ -581,25 +581,22 @@ void Heap::EnsureFromSpaceIsCommitted() { ...@@ -581,25 +581,22 @@ void Heap::EnsureFromSpaceIsCommitted() {
} }
class ClearThreadJSFunctionResultCachesVisitor: public ThreadVisitor { void Heap::ClearJSFunctionResultCaches() {
virtual void VisitThread(ThreadLocalTop* top) { if (Bootstrapper::IsActive()) return;
Context* context = top->context_;
if (context == NULL) return;
Object* context = global_contexts_list_;
while (!context->IsUndefined()) {
// Get the caches for this context:
FixedArray* caches = FixedArray* caches =
context->global()->global_context()->jsfunction_result_caches(); Context::cast(context)->jsfunction_result_caches();
// Clear the caches:
int length = caches->length(); int length = caches->length();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
JSFunctionResultCache::cast(caches->get(i))->Clear(); JSFunctionResultCache::cast(caches->get(i))->Clear();
} }
// Get the next context:
context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK);
} }
};
void Heap::ClearJSFunctionResultCaches() {
if (Bootstrapper::IsActive()) return;
ClearThreadJSFunctionResultCachesVisitor visitor;
ThreadManager::IterateArchivedThreads(&visitor);
} }
......
...@@ -1952,7 +1952,9 @@ void JSFunctionResultCache::MakeZeroSize() { ...@@ -1952,7 +1952,9 @@ void JSFunctionResultCache::MakeZeroSize() {
void JSFunctionResultCache::Clear() { void JSFunctionResultCache::Clear() {
int cache_size = Smi::cast(get(kCacheSizeIndex))->value(); int cache_size = Smi::cast(get(kCacheSizeIndex))->value();
Object** entries_start = RawField(this, OffsetOfElementAt(kEntriesIndex)); Object** entries_start = RawField(this, OffsetOfElementAt(kEntriesIndex));
MemsetPointer(entries_start, Heap::the_hole_value(), cache_size); MemsetPointer(entries_start,
Heap::the_hole_value(),
cache_size - kEntriesIndex);
MakeZeroSize(); MakeZeroSize();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment