Skip to content

Commit

Permalink
Backed out 15 changesets (bug 1479960, bug 1426526, bug 1534780, bug …
Browse files Browse the repository at this point in the history
…1536697) for toolchain bustages on UniquePtrExtensions.h . CLOSED TREE

Backed out changeset a8518ea4b594 (bug 1479960)
Backed out changeset 7172762c4b87 (bug 1536697)
Backed out changeset 2ea5ccb8f3a1 (bug 1426526)
Backed out changeset d892a888fe9c (bug 1426526)
Backed out changeset 2c4d12bdfec3 (bug 1479960)
Backed out changeset 8a322064cf6d (bug 1479960)
Backed out changeset 47d387b6cd4a (bug 1479960)
Backed out changeset 8332565a6943 (bug 1479960)
Backed out changeset 9d7f1835f96f (bug 1479960)
Backed out changeset 0aa8af4965c5 (bug 1479960)
Backed out changeset 036809330a51 (bug 1479960)
Backed out changeset 39e18373e3d3 (bug 1479960)
Backed out changeset 6c2b995a9d30 (bug 1479960)
Backed out changeset 3c2b31744645 (bug 1534780)
Backed out changeset 26bb00a94d5d (bug 1534780)
  • Loading branch information
nbeleuzu committed Jun 28, 2019
1 parent 75888e8 commit 316a44e
Show file tree
Hide file tree
Showing 35 changed files with 1,518 additions and 674 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ add_task(async function() {
});
}

let tmpPath = expandWhitelistPath("TmpD:").toLowerCase();
let tmpPath = expandWhitelistPath(MAC ? "TmpD:" : "/dev/shm").toLowerCase();
let shouldPass = true;
for (let procName in processes) {
let whitelist = processes[procName];
Expand Down Expand Up @@ -311,22 +311,15 @@ add_task(async function() {
continue;
}

if (!WIN && filename == "/dev/urandom") {
continue;
}

// /dev/shm is always tmpfs (a memory filesystem); this isn't
// really I/O any more than mmap/munmap are.
if (LINUX && filename.startsWith("/dev/shm/")) {
continue;
}
if (!WIN) {
if (filename == "/dev/urandom") {
continue;
}

// Shared memory uses temporary files on MacOS <= 10.11 to avoid
// a kernel security bug that will never be patched (see
// https://crbug.com/project-zero/1671 for details). This can
// be removed when we no longer support those OS versions.
if (MAC && filename.startsWith(tmpPath + "/org.mozilla.ipc.")) {
continue;
// Ignore I/O due to IPC. This doesn't really touch the disk.
if (filename.startsWith(tmpPath + "/org.chromium.")) {
continue;
}
}

let expected = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ add_task(async function() {
});
}

let tmpPath = expandWhitelistPath("TmpD:").toLowerCase();
let tmpPath = expandWhitelistPath(MAC ? "TmpD:" : "/dev/shm").toLowerCase();
let shouldPass = true;
for (let phase in phases) {
let whitelist = startupPhases[phase];
Expand Down Expand Up @@ -832,22 +832,15 @@ add_task(async function() {
continue;
}

if (!WIN && filename == "/dev/urandom") {
continue;
}

// /dev/shm is always tmpfs (a memory filesystem); this isn't
// really I/O any more than mmap/munmap are.
if (LINUX && filename.startsWith("/dev/shm/")) {
continue;
}
if (!WIN) {
if (filename == "/dev/urandom") {
continue;
}

// Shared memory uses temporary files on MacOS <= 10.11 to avoid
// a kernel security bug that will never be patched (see
// https://crbug.com/project-zero/1671 for details). This can
// be removed when we no longer support those OS versions.
if (MAC && filename.startsWith(tmpPath + "/org.mozilla.ipc.")) {
continue;
// Ignore I/O due to IPC. This doesn't really touch the disk.
if (filename.startsWith(tmpPath + "/org.chromium.")) {
continue;
}
}

let expected = false;
Expand Down
94 changes: 81 additions & 13 deletions dom/ipc/MemMapSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,109 @@

#include "MemMapSnapshot.h"

#include "mozilla/AutoMemMap.h"
#include "base/eintr_wrapper.h"
#include "base/file_util.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "nsIFile.h"

#ifdef XP_UNIX
# include <sys/stat.h>
#endif

namespace mozilla {

using loader::AutoMemMap;

namespace ipc {

Result<Ok, nsresult> MemMapSnapshot::Init(size_t aSize) {
MOZ_ASSERT(!mInitialized);

if (NS_WARN_IF(!mMem.CreateFreezeable(aSize))) {
MOZ_TRY(Create(aSize));

mInitialized = true;
return Ok();
}

Result<Ok, nsresult> MemMapSnapshot::Finalize(AutoMemMap& aMem) {
MOZ_ASSERT(mInitialized);

MOZ_TRY(Freeze(aMem));

mInitialized = false;
return Ok();
}

#if defined(XP_WIN)

Result<Ok, nsresult> MemMapSnapshot::Create(size_t aSize) {
HANDLE handle = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr,
PAGE_READWRITE, 0, DWORD(aSize), nullptr);

if (!handle) {
return Err(NS_ERROR_FAILURE);
}
if (NS_WARN_IF(!mMem.Map(aSize))) {

mFile.emplace(handle);
return mMem.initWithHandle(mFile.ref(), aSize, PR_PROT_READWRITE);
}

Result<Ok, nsresult> MemMapSnapshot::Freeze(AutoMemMap& aMem) {
auto orig = mFile.ref().ClonePlatformHandle();
mFile.reset();

HANDLE handle;
if (!::DuplicateHandle(
GetCurrentProcess(), orig.release(), GetCurrentProcess(), &handle,
GENERIC_READ | FILE_MAP_READ, false, DUPLICATE_CLOSE_SOURCE)) {
return Err(NS_ERROR_FAILURE);
}

mInitialized = true;
return Ok();
return aMem.initWithHandle(FileDescriptor(handle), mMem.size());
}

Result<Ok, nsresult> MemMapSnapshot::Finalize(loader::AutoMemMap& aMem) {
MOZ_ASSERT(mInitialized);
#elif defined(XP_UNIX)

if (NS_WARN_IF(!mMem.Freeze())) {
Result<Ok, nsresult> MemMapSnapshot::Create(size_t aSize) {
FilePath path;
ScopedCloseFile fd(file_util::CreateAndOpenTemporaryShmemFile(&path));
if (!fd) {
return Err(NS_ERROR_FAILURE);
}
// TakeHandle resets mMem, so call max_size first.
size_t size = mMem.max_size();
FileDescriptor memHandle(mMem.TakeHandle());
MOZ_TRY(aMem.initWithHandle(memHandle, size));

mInitialized = false;
if (HANDLE_EINTR(ftruncate(fileno(fd), aSize)) != 0) {
return Err(NS_ERROR_FAILURE);
}

MOZ_TRY(mMem.init(FILEToFileDescriptor(fd), PR_PROT_READWRITE));

mPath.Assign(path.value().data(), path.value().length());
return Ok();
}

Result<Ok, nsresult> MemMapSnapshot::Freeze(AutoMemMap& aMem) {
// Delete the shm file after we're done here, whether we succeed or not. The
// open file descriptor will keep it alive until all remaining references
// are closed, at which point it will be automatically freed.
auto cleanup = MakeScopeExit([&]() { PR_Delete(mPath.get()); });

// Make the shm file readonly. This doesn't make a difference in practice,
// since we open and share a read-only file descriptor, and then delete the
// file. But it doesn't hurt, either.
chmod(mPath.get(), 0400);

nsCOMPtr<nsIFile> file;
MOZ_TRY(NS_NewNativeLocalFile(mPath, /* followLinks = */ false,
getter_AddRefs(file)));

return aMem.init(file);
}

#else
# error "Unsupported build configuration"
#endif

} // namespace ipc
} // namespace mozilla
25 changes: 17 additions & 8 deletions dom/ipc/MemMapSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
#ifndef dom_ipc_MemMapSnapshot_h
#define dom_ipc_MemMapSnapshot_h

#include "mozilla/AutoMemMap.h"
#include "mozilla/Attributes.h"
#include "mozilla/Maybe.h"
#include "mozilla/RangedPtr.h"
#include "mozilla/Result.h"
#include "base/shared_memory.h"
#ifdef XP_WIN
# include "mozilla/ipc/FileDescriptor.h"
#endif

namespace mozilla {
namespace loader {
class AutoMemMap;
}

namespace ipc {

/**
Expand All @@ -36,15 +35,25 @@ class MOZ_RAII MemMapSnapshot {
Result<Ok, nsresult> Init(size_t aSize);
Result<Ok, nsresult> Finalize(loader::AutoMemMap& aMap);

template <typename T>
template <typename T = void>
RangedPtr<T> Get() {
MOZ_ASSERT(mInitialized);
return {static_cast<T*>(mMem.memory()), mMem.max_size() / sizeof(T)};
return mMem.get<T>();
}

private:
base::SharedMemory mMem;
Result<Ok, nsresult> Create(size_t aSize);
Result<Ok, nsresult> Freeze(loader::AutoMemMap& aMem);

loader::AutoMemMap mMem;

bool mInitialized = false;

#ifdef XP_WIN
Maybe<FileDescriptor> mFile;
#else
nsCString mPath;
#endif
};

} // namespace ipc
Expand Down
6 changes: 1 addition & 5 deletions dom/ipc/SharedStringMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ using namespace ipc;
namespace dom {
namespace ipc {

static constexpr uint32_t kSharedStringMapMagic = 0x9e3779b9;

static inline size_t GetAlignmentOffset(size_t aOffset, size_t aAlign) {
auto mod = aOffset % aAlign;
return mod ? aAlign - mod : 0;
Expand All @@ -32,7 +30,6 @@ SharedStringMap::SharedStringMap(const FileDescriptor& aMapFile,
size_t aMapSize) {
auto result = mMap.initWithHandle(aMapFile, aMapSize);
MOZ_RELEASE_ASSERT(result.isOk());
MOZ_RELEASE_ASSERT(GetHeader().mMagic == kSharedStringMapMagic);
// We return literal nsStrings and nsCStrings pointing to the mapped data,
// which means that we may still have references to the mapped data even
// after this instance is destroyed. That means that we need to keep the
Expand All @@ -43,7 +40,6 @@ SharedStringMap::SharedStringMap(const FileDescriptor& aMapFile,
SharedStringMap::SharedStringMap(SharedStringMapBuilder&& aBuilder) {
auto result = aBuilder.Finalize(mMap);
MOZ_RELEASE_ASSERT(result.isOk());
MOZ_RELEASE_ASSERT(GetHeader().mMagic == kSharedStringMapMagic);
mMap.setPersistent();
}

Expand Down Expand Up @@ -96,7 +92,7 @@ Result<Ok, nsresult> SharedStringMapBuilder::Finalize(
}
keys.Sort();

Header header = {kSharedStringMapMagic, uint32_t(keys.Length())};
Header header = {uint32_t(keys.Length())};

size_t offset = sizeof(header);
offset += GetAlignmentOffset(offset, alignof(Header));
Expand Down
1 change: 0 additions & 1 deletion dom/ipc/SharedStringMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class SharedStringMap {
* encoded as character (*not* byte) offsets into this region.
*/
struct Header {
uint32_t mMagic;
// The number of entries in this map.
uint32_t mEntryCount;

Expand Down
6 changes: 5 additions & 1 deletion gfx/ipc/SharedDIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ nsresult SharedDIB::Create(uint32_t aSize) {
return NS_OK;
}

bool SharedDIB::IsValid() { return mShMem && mShMem->IsValid(); }
bool SharedDIB::IsValid() {
if (!mShMem) return false;

return base::SharedMemory::IsHandleValid(mShMem->handle());
}

nsresult SharedDIB::Close() {
delete mShMem;
Expand Down
5 changes: 2 additions & 3 deletions gfx/ipc/SharedDIBWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ nsresult SharedDIBWin::SetupSurface(HDC aHdc, BITMAPV4HEADER* aHdr) {

if (!mSharedHdc) return NS_ERROR_FAILURE;

mSharedBmp =
::CreateDIBSection(mSharedHdc, (BITMAPINFO*)aHdr, DIB_RGB_COLORS,
&mBitmapBits, mShMem->GetHandle(), kHeaderBytes);
mSharedBmp = ::CreateDIBSection(mSharedHdc, (BITMAPINFO*)aHdr, DIB_RGB_COLORS,
&mBitmapBits, mShMem->handle(), kHeaderBytes);
if (!mSharedBmp) return NS_ERROR_FAILURE;

mOldObj = SelectObject(mSharedHdc, mSharedBmp);
Expand Down
1 change: 1 addition & 0 deletions gfx/thebes/gfxPlatformFontList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "mozilla/Unused.h"

#include "base/eintr_wrapper.h"
#include "base/file_util.h"

#include <locale.h>

Expand Down
4 changes: 4 additions & 0 deletions ipc/chromium/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ UNIFIED_SOURCES += [
'src/base/at_exit.cc',
'src/base/command_line.cc',
'src/base/file_path.cc',
'src/base/file_util.cc',
'src/base/histogram.cc',
'src/base/logging.cc',
'src/base/message_loop.cc',
Expand All @@ -34,6 +35,7 @@ UNIFIED_SOURCES += [
if os_win:
SOURCES += [
'src/base/condition_variable_win.cc',
'src/base/file_util_win.cc',
'src/base/lock_impl_win.cc',
'src/base/message_pump_win.cc',
'src/base/object_watcher.cc',
Expand All @@ -55,6 +57,7 @@ elif not CONFIG['MOZ_SYSTEM_LIBEVENT']:
if os_posix:
UNIFIED_SOURCES += [
'src/base/condition_variable_posix.cc',
'src/base/file_util_posix.cc',
'src/base/lock_impl_posix.cc',
'src/base/message_pump_libevent.cc',
'src/base/platform_thread_posix.cc',
Expand All @@ -71,6 +74,7 @@ if os_posix:
if os_macosx:
UNIFIED_SOURCES += [
'src/base/chrome_application_mac.mm',
'src/base/file_util_mac.mm',
'src/base/mac_util.mm',
'src/base/message_pump_mac.mm',
'src/base/process_util_mac.mm',
Expand Down
Loading

0 comments on commit 316a44e

Please sign in to comment.