gecko-dev/ipc/glue/moz.build
Jed Davis b0a1468c01 Bug 1456911 - Rewrite the fd shuffling to be simpler & handle identity mappings correctly. r=froydnj
This replaces some old Chromium code that tries to minimally disentangle
an arbitrary file descriptor mapping with simpler algorithm, for several
reasons:

1. Do something appropriate when a file descriptor is mapped to the same
fd number in the child; currently they're ignored, which means they'll
be closed if they were close-on-exec.  This implementation duplicates
the fd twice in that case, which seems to be uncommon in practice; this
isn't maximally efficient but avoids special-case code.

2. Make this more generally applicable; the previous design is
specialized for arbitrary code running between fork and exec, but we
also want to use this on OS X with posix_spawn, which exposes a very
limited set of operations.

3. Avoid the use of C++ standard library iterators in async signal safe
code; the Chromium developers mention that this is a potential problem in
some debugging implementations that take locks.

4. In general the algorithm is simpler and should be more "obviously
correct"; more concretely, it should get complete coverage just by being
run normally in a debug build.

As a convenient side benefit, CloseSuperfluousFds now takes an arbitrary
predicate for which fds to leave open, which means it can be used in
other code that needs it without creating a fake fd mapping.

MozReview-Commit-ID: EoiRttrbrKL

--HG--
extra : rebase_source : 336e0ba9f56dc80f7347dc62617b4ad1efea7e7e
2018-04-25 17:44:08 -06:00

245 lines
6.0 KiB
Python

# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
include('/media/webrtc/webrtc.mozbuild')
EXPORTS += [
'nsIIPCSerializableInputStream.h',
'nsIIPCSerializableURI.h',
]
EXPORTS.mozilla.ipc += [
'BackgroundChild.h',
'BackgroundParent.h',
'BackgroundUtils.h',
'BrowserProcessSubThread.h',
'ByteBuf.h',
'CrashReporterClient.h',
'CrashReporterHost.h',
'CrashReporterMetadataShmem.h',
'CrossProcessMutex.h',
'CrossProcessSemaphore.h',
'EnvironmentMap.h',
'FileDescriptor.h',
'FileDescriptorSetChild.h',
'FileDescriptorSetParent.h',
'FileDescriptorUtils.h',
'GeckoChildProcessHost.h',
'InputStreamUtils.h',
'IOThreadChild.h',
'IPCStreamAlloc.h',
'IPCStreamDestination.h',
'IPCStreamSource.h',
'IPCStreamUtils.h',
'IPDLParamTraits.h',
'MessageChannel.h',
'MessageLink.h',
'Neutering.h',
'ProcessChild.h',
'ProtocolUtils.h',
'ScopedXREEmbed.h',
'SharedMemory.h',
'SharedMemoryBasic.h',
'Shmem.h',
'TaskFactory.h',
'Transport.h',
'URIUtils.h',
'WindowsMessageLoop.h',
]
if CONFIG['OS_ARCH'] == 'WINNT':
EXPORTS.mozilla.ipc += [
'Transport_win.h',
]
SOURCES += [
'SharedMemory_windows.cpp',
'Transport_win.cpp',
'WindowsMessageLoop.cpp',
]
else:
EXPORTS.mozilla.ipc += [
'Transport_posix.h',
]
UNIFIED_SOURCES += [
'SharedMemory_posix.cpp',
'Transport_posix.cpp',
]
if CONFIG['OS_ARCH'] == 'WINNT':
SOURCES += [
'CrossProcessMutex_windows.cpp',
]
elif not CONFIG['OS_ARCH'] in ('NetBSD', 'OpenBSD'):
UNIFIED_SOURCES += [
'CrossProcessMutex_posix.cpp',
]
else:
UNIFIED_SOURCES += [
'CrossProcessMutex_unimplemented.cpp',
]
if CONFIG['OS_ARCH'] == 'WINNT':
SOURCES += [
'CrossProcessSemaphore_windows.cpp',
]
elif CONFIG['OS_ARCH'] != 'Darwin':
UNIFIED_SOURCES += [
'CrossProcessSemaphore_posix.cpp',
]
else:
UNIFIED_SOURCES += [
'CrossProcessSemaphore_unimplemented.cpp',
]
# Android has its own,
# almost-but-not-quite-compatible-with-POSIX-or-/dev/shm shared memory
# impl.
if CONFIG['OS_TARGET'] == 'Android':
EXPORTS.mozilla.ipc += ['SharedMemoryBasic_android.h']
UNIFIED_SOURCES += [
'SharedMemoryBasic_android.cpp',
]
elif CONFIG['OS_ARCH'] == 'Darwin':
EXPORTS.mozilla.ipc += ['SharedMemoryBasic_mach.h']
SOURCES += [
'SharedMemoryBasic_mach.mm',
]
else:
EXPORTS.mozilla.ipc += ['SharedMemoryBasic_chromium.h']
if CONFIG['OS_ARCH'] == 'Linux':
UNIFIED_SOURCES += [
'ProcessUtils_linux.cpp',
]
elif CONFIG['OS_ARCH'] in ('DragonFly', 'FreeBSD', 'NetBSD', 'OpenBSD'):
UNIFIED_SOURCES += [
'ProcessUtils_bsd.cpp'
]
elif CONFIG['OS_ARCH'] == 'Darwin':
UNIFIED_SOURCES += [
'ProcessUtils_mac.mm'
]
else:
UNIFIED_SOURCES += [
'ProcessUtils_none.cpp',
]
if CONFIG['OS_ARCH'] != 'WINNT':
EXPORTS.mozilla.ipc += [
'FileDescriptorShuffle.h',
]
UNIFIED_SOURCES += [
'FileDescriptorShuffle.cpp',
]
EXPORTS.ipc += [
'IPCMessageUtils.h',
]
UNIFIED_SOURCES += [
'BackgroundImpl.cpp',
'BackgroundUtils.cpp',
'BrowserProcessSubThread.cpp',
'CrashReporterClient.cpp',
'CrashReporterHost.cpp',
'CrashReporterMetadataShmem.cpp',
'FileDescriptor.cpp',
'FileDescriptorUtils.cpp',
'InputStreamUtils.cpp',
'IPCMessageUtils.cpp',
'IPCStreamChild.cpp',
'IPCStreamDestination.cpp',
'IPCStreamParent.cpp',
'IPCStreamSource.cpp',
'IPCStreamUtils.cpp',
'MessageChannel.cpp',
'MessageLink.cpp',
'MessagePump.cpp',
'ProcessChild.cpp',
'ProtocolUtils.cpp',
'ScopedXREEmbed.cpp',
'SharedMemory.cpp',
'Shmem.cpp',
'StringUtil.cpp',
'URIUtils.cpp',
]
SOURCES += [
'BackgroundChildImpl.cpp',
'BackgroundParentImpl.cpp',
'FileDescriptorSetChild.cpp',
'FileDescriptorSetParent.cpp',
]
if CONFIG['OS_ARCH'] == 'Darwin':
# GeckoChildProcessHost.cpp cannot be built unified due to OSX header
# clashes with TextRange.
SOURCES += [
'GeckoChildProcessHost.cpp',
]
else:
UNIFIED_SOURCES += [
'GeckoChildProcessHost.cpp',
]
if CONFIG['CC_TYPE'] in ('msvc', 'clang-cl'):
# This is intended as a temporary hack to support building with VS2015.
# 'reinterpret_cast': conversion from 'DWORD' to 'HANDLE' of greater size
SOURCES['BackgroundChildImpl.cpp'].flags += ['-wd4312']
SOURCES['BackgroundParentImpl.cpp'].flags += ['-wd4312']
LOCAL_INCLUDES += [
'/caps',
'/dom/broadcastchannel',
'/dom/indexedDB',
'/dom/storage',
'/media/webrtc/trunk',
'/xpcom/build',
]
IPDL_SOURCES = [
'InputStreamParams.ipdlh',
'IPCStream.ipdlh',
'PBackground.ipdl',
'PBackgroundSharedTypes.ipdlh',
'PBackgroundTest.ipdl',
'PChildToParentStream.ipdl',
'PFileDescriptorSet.ipdl',
'PParentToChildStream.ipdl',
'ProtocolTypes.ipdlh',
'URIParams.ipdlh',
]
LOCAL_INCLUDES += [
'/dom/ipc',
'/toolkit/crashreporter',
'/toolkit/xre',
'/xpcom/threads',
]
include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'
for var in ('MOZ_CHILD_PROCESS_NAME', 'MOZ_CHILD_PROCESS_BUNDLE',
'DLL_PREFIX', 'DLL_SUFFIX'):
DEFINES[var] = '"%s"' % CONFIG[var]
if CONFIG['MOZ_SANDBOX'] and CONFIG['OS_ARCH'] == 'WINNT':
LOCAL_INCLUDES += [
'/security/sandbox/chromium',
'/security/sandbox/chromium-shim',
'/security/sandbox/win/src/sandboxbroker',
]
if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
CXXFLAGS += ['-Wno-shadow']
if CONFIG['NIGHTLY_BUILD']:
DEFINES['ASYNC_CONTENTPROC_LAUNCH'] = True
# Add libFuzzer configuration directives
include('/tools/fuzzing/libfuzzer-config.mozbuild')