Commit e78f6b30 authored by Jonathan Kew's avatar Jonathan Kew
Browse files

Bug 1848890 - Guard access to FontList::mBlocks with the font-list lock. r=jnicol a=RyanVM

parent 7106ae10
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -334,11 +334,7 @@ class FontList {
    mozilla::UniquePtr<base::SharedMemory> mShmem;
  };

  Header& GetHeader() {
    // It's invalid to try and access this before the first block exists.
    MOZ_ASSERT(mBlocks.Length() > 0);
    return *static_cast<Header*>(mBlocks[0]->Memory());
  }
  Header& GetHeader() const;

  /**
   * Create a new shared memory block and append to the FontList's list
+18 −0
Original line number Diff line number Diff line
@@ -725,6 +725,24 @@ FontList::FontList(uint32_t aGeneration) {

FontList::~FontList() { DetachShmBlocks(); }

FontList::Header& FontList::GetHeader() const MOZ_NO_THREAD_SAFETY_ANALYSIS {
  // We only need to lock if we're not on the main thread.
  bool isMainThread = NS_IsMainThread();
  if (!isMainThread) {
    gfxPlatformFontList::PlatformFontList()->Lock();
  }

  // It's invalid to try and access this before the first block exists.
  MOZ_ASSERT(mBlocks.Length() > 0);
  auto& result = *static_cast<Header*>(mBlocks[0]->Memory());

  if (!isMainThread) {
    gfxPlatformFontList::PlatformFontList()->Unlock();
  }

  return result;
}

bool FontList::AppendShmBlock(uint32_t aSizeNeeded) {
  MOZ_ASSERT(XRE_IsParentProcess());
  uint32_t size = std::max(aSizeNeeded, SHM_BLOCK_SIZE);
+1 −0
Original line number Diff line number Diff line
@@ -2984,6 +2984,7 @@ base::SharedMemoryHandle gfxPlatformFontList::ShareShmBlockToProcess(
void gfxPlatformFontList::ShmBlockAdded(uint32_t aGeneration, uint32_t aIndex,
                                        base::SharedMemoryHandle aHandle) {
  if (SharedFontList()) {
    AutoLock lock(mLock);
    SharedFontList()->ShmBlockAdded(aGeneration, aIndex, std::move(aHandle));
  }
}