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

Side by Side Diff: Source/WebCore/bindings/v8/ScriptWrappable.h

Issue 13814002: First part of work to move V8 binding integrity off of vtables. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 23 matching lines...) Expand all
34 #include "V8Utilities.h" 34 #include "V8Utilities.h"
35 #include "WebCoreMemoryInstrumentation.h" 35 #include "WebCoreMemoryInstrumentation.h"
36 #include "WrapperTypeInfo.h" 36 #include "WrapperTypeInfo.h"
37 #include <v8.h> 37 #include <v8.h>
38 38
39 namespace WebCore { 39 namespace WebCore {
40 40
41 class ScriptWrappable { 41 class ScriptWrappable {
42 friend class WeakHandleListener<ScriptWrappable>; 42 friend class WeakHandleListener<ScriptWrappable>;
43 public: 43 public:
44 ScriptWrappable() { } 44 ScriptWrappable()
45 {
46 }
47
48 template <class C> static void init(C *object)
49 {
50 }
45 51
46 v8::Handle<v8::Object> wrapper() const 52 v8::Handle<v8::Object> wrapper() const
47 { 53 {
48 return v8::Handle<v8::Object>(maskOrUnmaskPointer(*m_maskedWrapper)); 54 return v8::Handle<v8::Object>(maskOrUnmaskPointer(*m_maskedWrapper));
49 } 55 }
50 56
51 void setWrapper(v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration) 57 void setWrapper(v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration)
52 { 58 {
53 ASSERT(m_maskedWrapper.IsEmpty()); 59 ASSERT(m_maskedWrapper.IsEmpty());
54 v8::Persistent<v8::Object> persistent = v8::Persistent<v8::Object>::New( isolate, wrapper); 60 v8::Persistent<v8::Object> persistent = v8::Persistent<v8::Object>::New( isolate, wrapper);
55 configuration.configureWrapper(persistent, isolate); 61 configuration.configureWrapper(persistent, isolate);
56 WeakHandleListener<ScriptWrappable>::makeWeak(isolate, persistent, this) ; 62 WeakHandleListener<ScriptWrappable>::makeWeak(isolate, persistent, this) ;
57 m_maskedWrapper = maskOrUnmaskPointer(*persistent); 63 m_maskedWrapper = maskOrUnmaskPointer(*persistent);
58 } 64 }
59 65
60 void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 66 void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
61 { 67 {
62 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); 68 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
63 info.ignoreMember(m_maskedWrapper); 69 info.ignoreMember(m_maskedWrapper);
64 } 70 }
65 71
72 protected:
73 ~ScriptWrappable()
74 {
75 }
76
66 private: 77 private:
67 inline void disposeWrapper(v8::Persistent<v8::Value> value, v8::Isolate* iso late) 78 inline void disposeWrapper(v8::Persistent<v8::Value> value, v8::Isolate* iso late)
68 { 79 {
69 ASSERT(!m_maskedWrapper.IsEmpty()); 80 ASSERT(!m_maskedWrapper.IsEmpty());
70 ASSERT(*value == maskOrUnmaskPointer(*m_maskedWrapper)); 81 ASSERT(*value == maskOrUnmaskPointer(*m_maskedWrapper));
71 value.Dispose(isolate); 82 value.Dispose(isolate);
72 m_maskedWrapper.Clear(); 83 m_maskedWrapper.Clear();
73 } 84 }
74 85
75 // Stores a masked wrapper to prevent attackers from overwriting this field
76 // with a phony wrapper.
77 v8::Persistent<v8::Object> m_maskedWrapper;
78
79 static inline v8::Object* maskOrUnmaskPointer(const v8::Object* object) 86 static inline v8::Object* maskOrUnmaskPointer(const v8::Object* object)
80 { 87 {
81 const uintptr_t objectPointer = reinterpret_cast<uintptr_t>(object); 88 const uintptr_t objectPointer = reinterpret_cast<uintptr_t>(object);
82 const uintptr_t randomMask = ~(reinterpret_cast<uintptr_t>(&WebCoreMemor yTypes::DOM) >> 13); // Entropy via ASLR. 89 const uintptr_t randomMask = ~(reinterpret_cast<uintptr_t>(&WebCoreMemor yTypes::DOM) >> 13); // Entropy via ASLR.
83 return reinterpret_cast<v8::Object*>((objectPointer ^ randomMask) & (!ob jectPointer - 1)); // Preserve null without branching. 90 return reinterpret_cast<v8::Object*>((objectPointer ^ randomMask) & (!ob jectPointer - 1)); // Preserve null without branching.
84 } 91 }
92
93 // Stores a masked wrapper to prevent attackers from overwriting this field
94 // with a phony wrapper.
95 v8::Persistent<v8::Object> m_maskedWrapper;
85 }; 96 };
86 97
87 template<> 98 template<>
88 inline void WeakHandleListener<ScriptWrappable>::callback(v8::Isolate* isolate, v8::Persistent<v8::Value> value, ScriptWrappable* key) 99 inline void WeakHandleListener<ScriptWrappable>::callback(v8::Isolate* isolate, v8::Persistent<v8::Value> value, ScriptWrappable* key)
89 { 100 {
90 ASSERT(value->IsObject()); 101 ASSERT(value->IsObject());
91 v8::Persistent<v8::Object> wrapper = v8::Persistent<v8::Object>::Cast(value) ; 102 v8::Persistent<v8::Object> wrapper = v8::Persistent<v8::Object>::Cast(value) ;
92 ASSERT(key->wrapper() == wrapper); 103 ASSERT(key->wrapper() == wrapper);
93 104
94 // Note: |object| might not be equal to |key|, e.g., if ScriptWrappable isn' t a left-most base class. 105 // Note: |object| might not be equal to |key|, e.g., if ScriptWrappable isn' t a left-most base class.
95 void* object = toNative(wrapper); 106 void* object = toNative(wrapper);
96 WrapperTypeInfo* info = toWrapperTypeInfo(wrapper); 107 WrapperTypeInfo* info = toWrapperTypeInfo(wrapper);
97 ASSERT(info->derefObjectFunction); 108 ASSERT(info->derefObjectFunction);
98 109
99 key->disposeWrapper(value, isolate); 110 key->disposeWrapper(value, isolate);
100 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed 111 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed
101 // inside key->deref(), which causes Node destructions. We should 112 // inside key->deref(), which causes Node destructions. We should
102 // make Node destructions incremental. 113 // make Node destructions incremental.
103 info->derefObject(object); 114 info->derefObject(object);
104 } 115 }
105 116
106 } // namespace WebCore 117 } // namespace WebCore
107 118
108 #endif // ScriptWrappable_h 119 #endif // ScriptWrappable_h
OLDNEW
« no previous file with comments | « Source/WebCore/Modules/websockets/CloseEvent.h ('k') | Source/WebCore/css/CSSFontFaceLoadEvent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698