Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_dom_asmjscache_asmjscache_h |
michael@0 | 8 | #define mozilla_dom_asmjscache_asmjscache_h |
michael@0 | 9 | |
michael@0 | 10 | #include "ipc/IPCMessageUtils.h" |
michael@0 | 11 | #include "js/TypeDecls.h" |
michael@0 | 12 | #include "js/Vector.h" |
michael@0 | 13 | #include "jsapi.h" |
michael@0 | 14 | |
michael@0 | 15 | class nsIPrincipal; |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace dom { |
michael@0 | 19 | |
michael@0 | 20 | namespace quota { |
michael@0 | 21 | class Client; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | namespace asmjscache { |
michael@0 | 25 | |
michael@0 | 26 | class PAsmJSCacheEntryChild; |
michael@0 | 27 | class PAsmJSCacheEntryParent; |
michael@0 | 28 | |
michael@0 | 29 | enum OpenMode |
michael@0 | 30 | { |
michael@0 | 31 | eOpenForRead, |
michael@0 | 32 | eOpenForWrite, |
michael@0 | 33 | NUM_OPEN_MODES |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | // Each origin stores a fixed size (kNumEntries) LRU cache of compiled asm.js |
michael@0 | 37 | // modules. Each compiled asm.js module is stored in a separate file with one |
michael@0 | 38 | // extra metadata file that stores the LRU cache and enough information for a |
michael@0 | 39 | // client to pick which cached module's file to open. |
michael@0 | 40 | struct Metadata |
michael@0 | 41 | { |
michael@0 | 42 | static const unsigned kNumEntries = 16; |
michael@0 | 43 | static const unsigned kLastEntry = kNumEntries - 1; |
michael@0 | 44 | |
michael@0 | 45 | struct Entry |
michael@0 | 46 | { |
michael@0 | 47 | uint32_t mFastHash; |
michael@0 | 48 | uint32_t mNumChars; |
michael@0 | 49 | uint32_t mFullHash; |
michael@0 | 50 | unsigned mModuleIndex; |
michael@0 | 51 | |
michael@0 | 52 | void clear() { |
michael@0 | 53 | mFastHash = -1; |
michael@0 | 54 | mNumChars = -1; |
michael@0 | 55 | mFullHash = -1; |
michael@0 | 56 | } |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | Entry mEntries[kNumEntries]; |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | // Parameters specific to opening a cache entry for writing |
michael@0 | 63 | struct WriteParams |
michael@0 | 64 | { |
michael@0 | 65 | int64_t mSize; |
michael@0 | 66 | int64_t mFastHash; |
michael@0 | 67 | int64_t mNumChars; |
michael@0 | 68 | int64_t mFullHash; |
michael@0 | 69 | bool mInstalled; |
michael@0 | 70 | |
michael@0 | 71 | WriteParams() |
michael@0 | 72 | : mSize(0), |
michael@0 | 73 | mFastHash(0), |
michael@0 | 74 | mNumChars(0), |
michael@0 | 75 | mFullHash(0), |
michael@0 | 76 | mInstalled(false) |
michael@0 | 77 | { } |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | // Parameters specific to opening a cache entry for reading |
michael@0 | 81 | struct ReadParams |
michael@0 | 82 | { |
michael@0 | 83 | const jschar* mBegin; |
michael@0 | 84 | const jschar* mLimit; |
michael@0 | 85 | |
michael@0 | 86 | ReadParams() |
michael@0 | 87 | : mBegin(nullptr), |
michael@0 | 88 | mLimit(nullptr) |
michael@0 | 89 | { } |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | // Implementation of AsmJSCacheOps, installed for the main JSRuntime by |
michael@0 | 93 | // nsJSEnvironment.cpp and DOM Worker JSRuntimes in RuntimeService.cpp. |
michael@0 | 94 | // |
michael@0 | 95 | // The Open* functions cannot be called directly from AsmJSCacheOps: they take |
michael@0 | 96 | // an nsIPrincipal as the first argument instead of a Handle<JSObject*>. The |
michael@0 | 97 | // caller must map the object to an nsIPrincipal. |
michael@0 | 98 | // |
michael@0 | 99 | // These methods may be called off the main thread and guarantee not to |
michael@0 | 100 | // access the given aPrincipal except on the main thread. In exchange, the |
michael@0 | 101 | // caller must ensure the given principal is alive from when OpenEntryForX is |
michael@0 | 102 | // called to when CloseEntryForX returns. |
michael@0 | 103 | |
michael@0 | 104 | bool |
michael@0 | 105 | OpenEntryForRead(nsIPrincipal* aPrincipal, |
michael@0 | 106 | const jschar* aBegin, |
michael@0 | 107 | const jschar* aLimit, |
michael@0 | 108 | size_t* aSize, |
michael@0 | 109 | const uint8_t** aMemory, |
michael@0 | 110 | intptr_t *aHandle); |
michael@0 | 111 | void |
michael@0 | 112 | CloseEntryForRead(JS::Handle<JSObject*> aGlobal, |
michael@0 | 113 | size_t aSize, |
michael@0 | 114 | const uint8_t* aMemory, |
michael@0 | 115 | intptr_t aHandle); |
michael@0 | 116 | bool |
michael@0 | 117 | OpenEntryForWrite(nsIPrincipal* aPrincipal, |
michael@0 | 118 | bool aInstalled, |
michael@0 | 119 | const jschar* aBegin, |
michael@0 | 120 | const jschar* aEnd, |
michael@0 | 121 | size_t aSize, |
michael@0 | 122 | uint8_t** aMemory, |
michael@0 | 123 | intptr_t* aHandle); |
michael@0 | 124 | void |
michael@0 | 125 | CloseEntryForWrite(JS::Handle<JSObject*> aGlobal, |
michael@0 | 126 | size_t aSize, |
michael@0 | 127 | uint8_t* aMemory, |
michael@0 | 128 | intptr_t aHandle); |
michael@0 | 129 | |
michael@0 | 130 | bool |
michael@0 | 131 | GetBuildId(JS::BuildIdCharVector* aBuildId); |
michael@0 | 132 | |
michael@0 | 133 | // Called from QuotaManager.cpp: |
michael@0 | 134 | |
michael@0 | 135 | quota::Client* |
michael@0 | 136 | CreateClient(); |
michael@0 | 137 | |
michael@0 | 138 | // Called from ipc/ContentParent.cpp: |
michael@0 | 139 | |
michael@0 | 140 | PAsmJSCacheEntryParent* |
michael@0 | 141 | AllocEntryParent(OpenMode aOpenMode, WriteParams aWriteParams, |
michael@0 | 142 | nsIPrincipal* aPrincipal); |
michael@0 | 143 | |
michael@0 | 144 | void |
michael@0 | 145 | DeallocEntryParent(PAsmJSCacheEntryParent* aActor); |
michael@0 | 146 | |
michael@0 | 147 | // Called from ipc/ContentChild.cpp: |
michael@0 | 148 | |
michael@0 | 149 | void |
michael@0 | 150 | DeallocEntryChild(PAsmJSCacheEntryChild* aActor); |
michael@0 | 151 | |
michael@0 | 152 | } // namespace asmjscache |
michael@0 | 153 | } // namespace dom |
michael@0 | 154 | } // namespace mozilla |
michael@0 | 155 | |
michael@0 | 156 | namespace IPC { |
michael@0 | 157 | |
michael@0 | 158 | template <> |
michael@0 | 159 | struct ParamTraits<mozilla::dom::asmjscache::OpenMode> : |
michael@0 | 160 | public ContiguousEnumSerializer<mozilla::dom::asmjscache::OpenMode, |
michael@0 | 161 | mozilla::dom::asmjscache::eOpenForRead, |
michael@0 | 162 | mozilla::dom::asmjscache::NUM_OPEN_MODES> |
michael@0 | 163 | { }; |
michael@0 | 164 | |
michael@0 | 165 | template <> |
michael@0 | 166 | struct ParamTraits<mozilla::dom::asmjscache::Metadata> |
michael@0 | 167 | { |
michael@0 | 168 | typedef mozilla::dom::asmjscache::Metadata paramType; |
michael@0 | 169 | static void Write(Message* aMsg, const paramType& aParam); |
michael@0 | 170 | static bool Read(const Message* aMsg, void** aIter, paramType* aResult); |
michael@0 | 171 | static void Log(const paramType& aParam, std::wstring* aLog); |
michael@0 | 172 | }; |
michael@0 | 173 | |
michael@0 | 174 | template <> |
michael@0 | 175 | struct ParamTraits<mozilla::dom::asmjscache::WriteParams> |
michael@0 | 176 | { |
michael@0 | 177 | typedef mozilla::dom::asmjscache::WriteParams paramType; |
michael@0 | 178 | static void Write(Message* aMsg, const paramType& aParam); |
michael@0 | 179 | static bool Read(const Message* aMsg, void** aIter, paramType* aResult); |
michael@0 | 180 | static void Log(const paramType& aParam, std::wstring* aLog); |
michael@0 | 181 | }; |
michael@0 | 182 | |
michael@0 | 183 | } // namespace IPC |
michael@0 | 184 | |
michael@0 | 185 | #endif // mozilla_dom_asmjscache_asmjscache_h |