Commit ac24ef5c authored by Jonathan Kew's avatar Jonathan Kew Committed by Richard Pospesel
Browse files

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

Differential Revision: https://phabricator.services.mozilla.com/D187690

ESR102 backport amend: removed MOZ_ prefix from Bug 1761040
parent 7c18fe80
Loading
Loading
Loading
Loading
+1 −5
Changes for gfx/thebes/SharedFontList-impl.h: 1 added line, 5 removed lines.
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
Changes for gfx/thebes/SharedFontList.cpp: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -703,6 +703,24 @@ FontList::FontList(uint32_t aGeneration) {

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

FontList::Header& FontList::GetHeader() const 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
Changes for gfx/thebes/gfxPlatformFontList.cpp: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -2915,6 +2915,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));
  }
}