зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1550037 - patch 1 - Migrate shared font-list code from mozilla::ipc::SharedMemoryBasic to base::SharedMemory APIs. r=jwatt
The base::SharedMemory class provides APIs to create a "read-only" copy of a shared memory block, which means it can be shared to a child process without the risk that the child might map it as writable and corrupt the contents. We want to use this facility for the font list, hence switching the shared-memory APIs used. Differential Revision: https://phabricator.services.mozilla.com/D68778 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
af4ac5130b
Коммит
1bf1c749a5
|
@ -4977,7 +4977,7 @@ mozilla::ipc::IPCResult ContentParent::RecvGetOutputColorProfileData(
|
|||
|
||||
mozilla::ipc::IPCResult ContentParent::RecvGetFontListShmBlock(
|
||||
const uint32_t& aGeneration, const uint32_t& aIndex,
|
||||
mozilla::ipc::SharedMemoryBasic::Handle* aOut) {
|
||||
base::SharedMemoryHandle* aOut) {
|
||||
auto fontList = gfxPlatformFontList::PlatformFontList();
|
||||
MOZ_RELEASE_ASSERT(fontList, "gfxPlatformFontList not initialized?");
|
||||
fontList->ShareFontListShmBlockToProcess(aGeneration, aIndex, Pid(), aOut);
|
||||
|
|
|
@ -1148,7 +1148,7 @@ class ContentParent final
|
|||
|
||||
mozilla::ipc::IPCResult RecvGetFontListShmBlock(
|
||||
const uint32_t& aGeneration, const uint32_t& aIndex,
|
||||
mozilla::ipc::SharedMemoryBasic::Handle* aOut);
|
||||
base::SharedMemoryHandle* aOut);
|
||||
|
||||
mozilla::ipc::IPCResult RecvInitializeFamily(const uint32_t& aGeneration,
|
||||
const uint32_t& aFamilyIndex);
|
||||
|
|
|
@ -1266,7 +1266,7 @@ parent:
|
|||
* until it has mapped the font-list memory.
|
||||
*/
|
||||
sync GetFontListShmBlock(uint32_t aGeneration, uint32_t aIndex)
|
||||
returns (Handle aHandle);
|
||||
returns (SharedMemoryHandle aHandle);
|
||||
|
||||
/**
|
||||
* Ask the parent to initialize a given font family, so that face metadata
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "SharedFontList.h"
|
||||
|
||||
#include "mozilla/ipc/SharedMemoryBasic.h"
|
||||
#include "base/shared_memory.h"
|
||||
|
||||
#include "gfxFontUtils.h"
|
||||
#include "nsClassHashtable.h"
|
||||
|
@ -224,10 +224,10 @@ class FontList {
|
|||
* specific child process.
|
||||
*/
|
||||
void ShareShmBlockToProcess(uint32_t aIndex, base::ProcessId aPid,
|
||||
mozilla::ipc::SharedMemoryBasic::Handle* aOut) {
|
||||
base::SharedMemoryHandle* aOut) {
|
||||
if (aIndex >= mBlocks.Length()) {
|
||||
// Block index out of range
|
||||
*aOut = mozilla::ipc::SharedMemoryBasic::NULLHandle();
|
||||
*aOut = base::SharedMemory::NULLHandle();
|
||||
}
|
||||
if (!mBlocks[aIndex]->mShmem->ShareToProcess(aPid, aOut)) {
|
||||
MOZ_CRASH("failed to share block");
|
||||
|
@ -240,7 +240,7 @@ class FontList {
|
|||
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
||||
size_t result = mBlocks.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
||||
for (const auto& b : mBlocks) {
|
||||
result += aMallocSizeOf(b.get()) + aMallocSizeOf(b->mShmem);
|
||||
result += aMallocSizeOf(b.get()) + aMallocSizeOf(b->mShmem.get());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -268,7 +268,8 @@ class FontList {
|
|||
|
||||
private:
|
||||
struct ShmBlock {
|
||||
ShmBlock(mozilla::ipc::SharedMemoryBasic* aShmem, void* aAddr)
|
||||
// Takes ownership of aShmem
|
||||
ShmBlock(base::SharedMemory* aShmem, void* aAddr)
|
||||
: mShmem(aShmem), mAddr(aAddr) {}
|
||||
|
||||
// The first 32-bit word of each block holds the current amount allocated
|
||||
|
@ -278,7 +279,7 @@ class FontList {
|
|||
return *static_cast<std::atomic<uint32_t>*>(mAddr);
|
||||
}
|
||||
|
||||
RefPtr<mozilla::ipc::SharedMemoryBasic> mShmem;
|
||||
mozilla::UniquePtr<base::SharedMemory> mShmem;
|
||||
void* mAddr; // Address where the shared memory block is mapped in this
|
||||
// process; avoids virtual call to mShmem->memory() each time
|
||||
// we need to convert between Pointer and a real C++ pointer.
|
||||
|
|
|
@ -519,7 +519,7 @@ FontList::~FontList() { DetachShmBlocks(); }
|
|||
|
||||
bool FontList::AppendShmBlock() {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
ipc::SharedMemoryBasic* newShm = new ipc::SharedMemoryBasic();
|
||||
base::SharedMemory* newShm = new base::SharedMemory();
|
||||
if (!newShm->Create(SHM_BLOCK_SIZE)) {
|
||||
MOZ_CRASH("failed to create shared memory");
|
||||
return false;
|
||||
|
@ -556,17 +556,16 @@ FontList::ShmBlock* FontList::GetBlockFromParent(uint32_t aIndex) {
|
|||
// If we have no existing blocks, we don't want a generation check yet;
|
||||
// the header in the first block will define the generation of this list
|
||||
uint32_t generation = aIndex == 0 ? 0 : GetGeneration();
|
||||
ipc::SharedMemoryBasic::Handle handle = ipc::SharedMemoryBasic::NULLHandle();
|
||||
base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle();
|
||||
if (!dom::ContentChild::GetSingleton()->SendGetFontListShmBlock(
|
||||
generation, aIndex, &handle)) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<ipc::SharedMemoryBasic> newShm = new ipc::SharedMemoryBasic();
|
||||
base::SharedMemory* newShm = new base::SharedMemory();
|
||||
if (!newShm->IsHandleValid(handle)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!newShm->SetHandle(handle,
|
||||
mozilla::ipc::SharedMemoryBasic::RightsReadOnly)) {
|
||||
if (!newShm->SetHandle(handle, true)) {
|
||||
MOZ_CRASH("failed to set shm handle");
|
||||
}
|
||||
if (!newShm->Map(SHM_BLOCK_SIZE)) {
|
||||
|
|
|
@ -2267,17 +2267,16 @@ void gfxPlatformFontList::CancelInitOtherFamilyNamesTask() {
|
|||
}
|
||||
|
||||
void gfxPlatformFontList::ShareFontListShmBlockToProcess(
|
||||
uint32_t aGeneration, uint32_t aIndex, /*base::ProcessId*/ uint32_t aPid,
|
||||
/*mozilla::ipc::SharedMemoryBasic::Handle*/ void* aOut) {
|
||||
uint32_t aGeneration, uint32_t aIndex, base::ProcessId aPid,
|
||||
base::SharedMemoryHandle* aOut) {
|
||||
auto list = SharedFontList();
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
auto out = static_cast<mozilla::ipc::SharedMemoryBasic::Handle*>(aOut);
|
||||
if (!aGeneration || list->GetGeneration() == aGeneration) {
|
||||
list->ShareShmBlockToProcess(aIndex, aPid, out);
|
||||
list->ShareShmBlockToProcess(aIndex, aPid, aOut);
|
||||
} else {
|
||||
*out = mozilla::ipc::SharedMemoryBasic::NULLHandle();
|
||||
*aOut = base::SharedMemory::NULLHandle();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include "mozilla/RangedArray.h"
|
||||
#include "nsLanguageAtomService.h"
|
||||
|
||||
#include "base/shared_memory.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace fontlist {
|
||||
struct AliasData;
|
||||
|
@ -262,8 +264,8 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
|
|||
// result in build failure due to (indirect) inclusion of windows.h
|
||||
// in generated bindings code.
|
||||
void ShareFontListShmBlockToProcess(
|
||||
uint32_t aGeneration, uint32_t aIndex, /*base::ProcessId*/ uint32_t aPid,
|
||||
/*mozilla::ipc::SharedMemoryBasic::Handle*/ void* aOut);
|
||||
uint32_t aGeneration, uint32_t aIndex, base::ProcessId aPid,
|
||||
base::SharedMemoryHandle* aOut);
|
||||
|
||||
void SetCharacterMap(uint32_t aGeneration,
|
||||
const mozilla::fontlist::Pointer& aFacePtr,
|
||||
|
|
Загрузка…
Ссылка в новой задаче