LCOV - code coverage report
Current view: top level - dom/asmjscache - AsmJSCache.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 13 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13