Bug 1401790 - Remove ProcessArchitecture from IPC. r=billm,jimm

This was used to support cross-architecture NPAPI plugins on OS X, but
we stopped supporting that in 54 (bug 1339182).

MozReview-Commit-ID: 2BcWYD6mguY

--HG--
extra : rebase_source : 6e509a3cc1f356ccd24f1459c43bc8fb66d7b0f4
This commit is contained in:
Jed Davis 2017-10-04 20:31:12 -06:00
Родитель 6125e83b28
Коммит 70736cfb1b
9 изменённых файлов: 25 добавлений и 270 удалений

Просмотреть файл

@ -23,7 +23,6 @@ using std::string;
using mozilla::gmp::GMPProcessParent;
using mozilla::ipc::GeckoChildProcessHost;
using base::ProcessArchitecture;
namespace mozilla {
namespace gmp {
@ -78,7 +77,7 @@ GMPProcessParent::Launch(int32_t aTimeoutMs)
args.push_back(mGMPPath);
#endif
return SyncLaunch(args, aTimeoutMs, base::GetCurrentProcessArchitecture());
return SyncLaunch(args, aTimeoutMs);
}
void

Просмотреть файл

@ -65,19 +65,6 @@ static CFBundleRef getPluginBundle(const char* path)
return bundle;
}
static nsresult toCFURLRef(nsIFile* file, CFURLRef& outURL)
{
nsCOMPtr<nsILocalFileMac> lfm = do_QueryInterface(file);
if (!lfm)
return NS_ERROR_FAILURE;
CFURLRef url;
nsresult rv = lfm->GetCFURL(&url);
if (NS_SUCCEEDED(rv))
outURL = url;
return rv;
}
bool nsPluginsDir::IsPluginFile(nsIFile* file)
{
nsCString fileName;
@ -362,49 +349,6 @@ static char* GetNextPluginStringFromHandle(Handle h, short *index)
return ret;
}
static bool IsCompatibleArch(nsIFile *file)
{
CFURLRef pluginURL = nullptr;
if (NS_FAILED(toCFURLRef(file, pluginURL)))
return false;
bool isPluginFile = false;
CFBundleRef pluginBundle = ::CFBundleCreate(kCFAllocatorDefault, pluginURL);
if (pluginBundle) {
UInt32 packageType, packageCreator;
::CFBundleGetPackageInfo(pluginBundle, &packageType, &packageCreator);
if (packageType == 'BRPL' || packageType == 'IEPL' || packageType == 'NSPL') {
// Get path to plugin as a C string.
char executablePath[PATH_MAX];
executablePath[0] = '\0';
if (!::CFURLGetFileSystemRepresentation(pluginURL, true, (UInt8*)&executablePath, PATH_MAX)) {
executablePath[0] = '\0';
}
uint32_t pluginLibArchitectures;
nsresult rv = mozilla::ipc::GeckoChildProcessHost::GetArchitecturesForBinary(executablePath, &pluginLibArchitectures);
if (NS_FAILED(rv)) {
return false;
}
uint32_t supportedArchitectures =
#ifdef __LP64__
mozilla::ipc::GeckoChildProcessHost::GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
#else
base::GetCurrentProcessArchitecture();
#endif
// Consider the plugin architecture valid if there is any overlap in the masks.
isPluginFile = !!(supportedArchitectures & pluginLibArchitectures);
}
::CFRelease(pluginBundle);
}
::CFRelease(pluginURL);
return isPluginFile;
}
/**
* Obtains all of the information currently available for this plugin.
*/
@ -414,10 +358,6 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info, PRLibrary **outLibrary)
nsresult rv = NS_OK;
if (!IsCompatibleArch(mPlugin)) {
return NS_ERROR_FAILURE;
}
// clear out the info, except for the first field.
memset(&info, 0, sizeof(info));

Просмотреть файл

@ -21,7 +21,6 @@ using mozilla::ipc::BrowserProcessSubThread;
using mozilla::ipc::GeckoChildProcessHost;
using mozilla::plugins::LaunchCompleteTask;
using mozilla::plugins::PluginProcessParent;
using base::ProcessArchitecture;
#ifdef XP_WIN
PluginProcessParent::PidSet* PluginProcessParent::sPidSet = nullptr;
@ -64,48 +63,12 @@ PluginProcessParent::Launch(mozilla::UniquePtr<LaunchCompleteTask> aLaunchComple
}
#endif
ProcessArchitecture currentArchitecture = base::GetCurrentProcessArchitecture();
uint32_t containerArchitectures = GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
uint32_t pluginLibArchitectures = currentArchitecture;
#ifdef XP_MACOSX
nsresult rv = GetArchitecturesForBinary(mPluginFilePath.c_str(), &pluginLibArchitectures);
if (NS_FAILED(rv)) {
// If the call failed just assume that we want the current architecture.
pluginLibArchitectures = currentArchitecture;
}
#endif
ProcessArchitecture selectedArchitecture = currentArchitecture;
if (!(pluginLibArchitectures & containerArchitectures & currentArchitecture)) {
// Prefererence in order: x86_64, i386, PPC. The only particularly important thing
// about this order is that we'll prefer 64-bit architectures first.
if (base::PROCESS_ARCH_X86_64 & pluginLibArchitectures & containerArchitectures) {
selectedArchitecture = base::PROCESS_ARCH_X86_64;
}
else if (base::PROCESS_ARCH_I386 & pluginLibArchitectures & containerArchitectures) {
selectedArchitecture = base::PROCESS_ARCH_I386;
}
else if (base::PROCESS_ARCH_PPC & pluginLibArchitectures & containerArchitectures) {
selectedArchitecture = base::PROCESS_ARCH_PPC;
}
else if (base::PROCESS_ARCH_ARM & pluginLibArchitectures & containerArchitectures) {
selectedArchitecture = base::PROCESS_ARCH_ARM;
}
else if (base::PROCESS_ARCH_MIPS & pluginLibArchitectures & containerArchitectures) {
selectedArchitecture = base::PROCESS_ARCH_MIPS;
}
else {
return false;
}
}
mLaunchCompleteTask = mozilla::Move(aLaunchCompleteTask);
vector<string> args;
args.push_back(MungePluginDsoPath(mPluginFilePath));
bool result = AsyncLaunch(args, selectedArchitecture);
bool result = AsyncLaunch(args);
if (!result) {
mLaunchCompleteTask = nullptr;
}

Просмотреть файл

@ -51,35 +51,6 @@ struct kinfo_proc;
namespace base {
// These can be used in a 32-bit bitmask.
enum ProcessArchitecture {
PROCESS_ARCH_I386 = 0x1,
PROCESS_ARCH_X86_64 = 0x2,
PROCESS_ARCH_PPC = 0x4,
PROCESS_ARCH_ARM = 0x8,
PROCESS_ARCH_MIPS = 0x10,
PROCESS_ARCH_ARM64 = 0x20
};
inline ProcessArchitecture GetCurrentProcessArchitecture()
{
base::ProcessArchitecture currentArchitecture;
#if defined(ARCH_CPU_X86)
currentArchitecture = base::PROCESS_ARCH_I386;
#elif defined(ARCH_CPU_X86_64)
currentArchitecture = base::PROCESS_ARCH_X86_64;
#elif defined(ARCH_CPU_PPC)
currentArchitecture = base::PROCESS_ARCH_PPC;
#elif defined(ARCH_CPU_ARMEL)
currentArchitecture = base::PROCESS_ARCH_ARM;
#elif defined(ARCH_CPU_MIPS)
currentArchitecture = base::PROCESS_ARCH_MIPS;
#elif defined(ARCH_CPU_ARM64)
currentArchitecture = base::PROCESS_ARCH_ARM64;
#endif
return currentArchitecture;
}
// A minimalistic but hopefully cross-platform set of exit codes.
// Do not change the enumeration values or you will break third-party
// installers.
@ -163,8 +134,7 @@ typedef std::map<std::string, std::string> environment_map;
bool LaunchApp(const std::vector<std::string>& argv,
const file_handle_mapping_vector& fds_to_remap,
const environment_map& env_vars_to_set,
bool wait, ProcessHandle* process_handle,
ProcessArchitecture arch=GetCurrentProcessArchitecture());
bool wait, ProcessHandle* process_handle);
// Deleter for the array of strings allocated within BuildEnvironmentArray.
struct FreeEnvVarsArray

Просмотреть файл

@ -34,8 +34,7 @@ bool LaunchApp(const std::vector<std::string>& argv,
bool LaunchApp(const std::vector<std::string>& argv,
const file_handle_mapping_vector& fds_to_remap,
const environment_map& env_vars_to_set,
bool wait, ProcessHandle* process_handle,
ProcessArchitecture arch) {
bool wait, ProcessHandle* process_handle) {
bool retval = true;
char* argv_copy[argv.size() + 1];

Просмотреть файл

@ -34,8 +34,7 @@ bool LaunchApp(const std::vector<std::string>& argv,
bool LaunchApp(const std::vector<std::string>& argv,
const file_handle_mapping_vector& fds_to_remap,
const environment_map& env_vars_to_set,
bool wait, ProcessHandle* process_handle,
ProcessArchitecture arch) {
bool wait, ProcessHandle* process_handle) {
mozilla::UniquePtr<char*[]> argv_cstr(new char*[argv.size() + 1]);
// Illegal to allocate memory after fork and before execvp
InjectiveMultimap fd_shuffle1, fd_shuffle2;

Просмотреть файл

@ -33,8 +33,7 @@ bool LaunchApp(const std::vector<std::string>& argv,
bool LaunchApp(const std::vector<std::string>& argv,
const file_handle_mapping_vector& fds_to_remap,
const environment_map& env_vars_to_set,
bool wait, ProcessHandle* process_handle,
ProcessArchitecture arch) {
bool wait, ProcessHandle* process_handle) {
bool retval = true;
char* argv_copy[argv.size() + 1];
@ -72,24 +71,6 @@ bool LaunchApp(const std::vector<std::string>& argv,
}
}
// Set up the CPU preference array.
cpu_type_t cpu_types[1];
switch (arch) {
case PROCESS_ARCH_I386:
cpu_types[0] = CPU_TYPE_X86;
break;
case PROCESS_ARCH_X86_64:
cpu_types[0] = CPU_TYPE_X86_64;
break;
case PROCESS_ARCH_PPC:
cpu_types[0] = CPU_TYPE_POWERPC;
break;
default:
cpu_types[0] = CPU_TYPE_ANY;
break;
}
// Initialize spawn attributes.
posix_spawnattr_t spawnattr;
if (posix_spawnattr_init(&spawnattr) != 0) {
return false;
@ -98,14 +79,6 @@ bool LaunchApp(const std::vector<std::string>& argv,
posix_spawnattr_destroy(&spawnattr);
});
// Set spawn attributes.
size_t attr_count = 1;
size_t attr_ocount = 0;
if (posix_spawnattr_setbinpref_np(&spawnattr, attr_count, cpu_types, &attr_ocount) != 0 ||
attr_ocount != attr_count) {
return false;
}
// Prevent the child process from inheriting any file descriptors
// that aren't named in `file_actions`. (This is an Apple-specific
// extension to posix_spawn.)

Просмотреть файл

@ -209,77 +209,6 @@ private:
};
#endif
nsresult GeckoChildProcessHost::GetArchitecturesForBinary(const char *path, uint32_t *result)
{
*result = 0;
#ifdef MOZ_WIDGET_COCOA
CFURLRef url = ::CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
(const UInt8*)path,
strlen(path),
false);
if (!url) {
return NS_ERROR_FAILURE;
}
AutoCFTypeObject autoPluginContainerURL(url);
CFArrayRef pluginContainerArchs = ::CFBundleCopyExecutableArchitecturesForURL(url);
if (!pluginContainerArchs) {
return NS_ERROR_FAILURE;
}
AutoCFTypeObject autoPluginContainerArchs(pluginContainerArchs);
CFIndex pluginArchCount = ::CFArrayGetCount(pluginContainerArchs);
for (CFIndex i = 0; i < pluginArchCount; i++) {
CFNumberRef currentArch = static_cast<CFNumberRef>(::CFArrayGetValueAtIndex(pluginContainerArchs, i));
int currentArchInt = 0;
if (!::CFNumberGetValue(currentArch, kCFNumberIntType, &currentArchInt)) {
continue;
}
switch (currentArchInt) {
case kCFBundleExecutableArchitectureI386:
*result |= base::PROCESS_ARCH_I386;
break;
case kCFBundleExecutableArchitectureX86_64:
*result |= base::PROCESS_ARCH_X86_64;
break;
case kCFBundleExecutableArchitecturePPC:
*result |= base::PROCESS_ARCH_PPC;
break;
default:
break;
}
}
return (*result ? NS_OK : NS_ERROR_FAILURE);
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
uint32_t GeckoChildProcessHost::GetSupportedArchitecturesForProcessType(GeckoProcessType type)
{
#ifdef MOZ_WIDGET_COCOA
if (type == GeckoProcessType_Plugin) {
// Cache this, it shouldn't ever change.
static uint32_t pluginContainerArchs = 0;
if (pluginContainerArchs == 0) {
FilePath exePath;
GetPathToBinary(exePath, type);
nsresult rv = GetArchitecturesForBinary(exePath.value().c_str(), &pluginContainerArchs);
NS_ASSERTION(NS_SUCCEEDED(rv) && pluginContainerArchs != 0, "Getting architecture of plugin container failed!");
if (NS_FAILED(rv) || pluginContainerArchs == 0) {
pluginContainerArchs = base::GetCurrentProcessArchitecture();
}
}
return pluginContainerArchs;
}
#endif
return base::GetCurrentProcessArchitecture();
}
// We start the unique IDs at 1 so that 0 can be used to mean that
// a component has no unique ID assigned to it.
uint32_t GeckoChildProcessHost::sNextUniqueID = 1;
@ -372,39 +301,34 @@ void GeckoChildProcessHost::InitWindowsGroupID()
#endif
bool
GeckoChildProcessHost::SyncLaunch(std::vector<std::string> aExtraOpts, int aTimeoutMs, base::ProcessArchitecture arch)
GeckoChildProcessHost::SyncLaunch(std::vector<std::string> aExtraOpts, int aTimeoutMs)
{
PrepareLaunch();
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
NS_ASSERTION(MessageLoop::current() != ioLoop, "sync launch from the IO thread NYI");
ioLoop->PostTask(NewNonOwningRunnableMethod<std::vector<std::string>,
base::ProcessArchitecture>(
ioLoop->PostTask(NewNonOwningRunnableMethod<std::vector<std::string>>(
"ipc::GeckoChildProcessHost::RunPerformAsyncLaunch",
this,
&GeckoChildProcessHost::RunPerformAsyncLaunch,
aExtraOpts,
arch));
aExtraOpts));
return WaitUntilConnected(aTimeoutMs);
}
bool
GeckoChildProcessHost::AsyncLaunch(std::vector<std::string> aExtraOpts,
base::ProcessArchitecture arch)
GeckoChildProcessHost::AsyncLaunch(std::vector<std::string> aExtraOpts)
{
PrepareLaunch();
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
ioLoop->PostTask(NewNonOwningRunnableMethod<std::vector<std::string>,
base::ProcessArchitecture>(
ioLoop->PostTask(NewNonOwningRunnableMethod<std::vector<std::string>>(
"ipc::GeckoChildProcessHost::RunPerformAsyncLaunch",
this,
&GeckoChildProcessHost::RunPerformAsyncLaunch,
aExtraOpts,
arch));
aExtraOpts));
// This may look like the sync launch wait, but we only delay as
// long as it takes to create the channel.
@ -460,13 +384,11 @@ GeckoChildProcessHost::LaunchAndWaitForProcessHandle(StringVector aExtraOpts)
PrepareLaunch();
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
ioLoop->PostTask(NewNonOwningRunnableMethod<std::vector<std::string>,
base::ProcessArchitecture>(
ioLoop->PostTask(NewNonOwningRunnableMethod<std::vector<std::string>>(
"ipc::GeckoChildProcessHost::RunPerformAsyncLaunch",
this,
&GeckoChildProcessHost::RunPerformAsyncLaunch,
aExtraOpts,
base::GetCurrentProcessArchitecture()));
aExtraOpts));
MonitorAutoLock lock(mMonitor);
while (mProcessState < PROCESS_CREATED) {
@ -558,7 +480,7 @@ GeckoChildProcessHost::SetChildLogName(const char* varName, const char* origLogN
}
bool
GeckoChildProcessHost::PerformAsyncLaunch(std::vector<std::string> aExtraOpts, base::ProcessArchitecture arch)
GeckoChildProcessHost::PerformAsyncLaunch(std::vector<std::string> aExtraOpts)
{
#ifdef MOZ_GECKO_PROFILER
AutoSetProfilerEnvVarsForChildProcess profilerEnvironment;
@ -605,7 +527,7 @@ GeckoChildProcessHost::PerformAsyncLaunch(std::vector<std::string> aExtraOpts, b
PR_SetEnv(rustLog.get());
}
bool retval = PerformAsyncLaunchInternal(aExtraOpts, arch);
bool retval = PerformAsyncLaunchInternal(aExtraOpts);
// Revert to original value
if (origNSPRLogName) {
@ -622,12 +544,11 @@ GeckoChildProcessHost::PerformAsyncLaunch(std::vector<std::string> aExtraOpts, b
}
bool
GeckoChildProcessHost::RunPerformAsyncLaunch(std::vector<std::string> aExtraOpts,
base::ProcessArchitecture aArch)
GeckoChildProcessHost::RunPerformAsyncLaunch(std::vector<std::string> aExtraOpts)
{
InitializeChannel();
bool ok = PerformAsyncLaunch(aExtraOpts, aArch);
bool ok = PerformAsyncLaunch(aExtraOpts);
if (!ok) {
// WaitUntilConnected might be waiting for us to signal.
// If something failed let's set the error state and notify.
@ -694,7 +615,7 @@ AddAppDirToCommandLine(std::vector<std::string>& aCmdLine)
}
bool
GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExtraOpts, base::ProcessArchitecture arch)
GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExtraOpts)
{
// We rely on the fact that InitializeChannel() has already been processed
// on the IO thread before this point is reached.
@ -911,7 +832,7 @@ GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector<std::string>& aExt
# if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_BSD) || defined(OS_SOLARIS)
newEnvVars,
# endif // defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_BSD) || defined(OS_SOLARIS)
false, &process, arch);
false, &process);
# endif // defined(MOZ_WIDGET_ANDROID)
// We're in the parent and the child was launched. Close the child FD in the

Просмотреть файл

@ -42,17 +42,12 @@ public:
~GeckoChildProcessHost();
static nsresult GetArchitecturesForBinary(const char *path, uint32_t *result);
static uint32_t GetSupportedArchitecturesForProcessType(GeckoProcessType type);
static uint32_t GetUniqueID();
// Block until the IPC channel for our subprocess is initialized,
// but no longer. The child process may or may not have been
// created when this method returns.
bool AsyncLaunch(StringVector aExtraOpts=StringVector(),
base::ProcessArchitecture arch=base::GetCurrentProcessArchitecture());
bool AsyncLaunch(StringVector aExtraOpts=StringVector());
virtual bool WaitUntilConnected(int32_t aTimeoutMs = 0);
@ -74,11 +69,9 @@ public:
// the IPC channel, meaning it's fully initialized. (Or until an
// error occurs.)
bool SyncLaunch(StringVector aExtraOpts=StringVector(),
int32_t timeoutMs=0,
base::ProcessArchitecture arch=base::GetCurrentProcessArchitecture());
int32_t timeoutMs=0);
virtual bool PerformAsyncLaunch(StringVector aExtraOpts=StringVector(),
base::ProcessArchitecture aArch=base::GetCurrentProcessArchitecture());
virtual bool PerformAsyncLaunch(StringVector aExtraOpts=StringVector());
virtual void OnChannelConnected(int32_t peer_pid);
virtual void OnMessageReceived(IPC::Message&& aMsg);
@ -174,11 +167,9 @@ private:
DISALLOW_EVIL_CONSTRUCTORS(GeckoChildProcessHost);
// Does the actual work for AsyncLaunch, on the IO thread.
bool PerformAsyncLaunchInternal(std::vector<std::string>& aExtraOpts,
base::ProcessArchitecture arch);
bool PerformAsyncLaunchInternal(std::vector<std::string>& aExtraOpts);
bool RunPerformAsyncLaunch(StringVector aExtraOpts=StringVector(),
base::ProcessArchitecture aArch=base::GetCurrentProcessArchitecture());
bool RunPerformAsyncLaunch(StringVector aExtraOpts=StringVector());
enum class BinaryPathType {
Self,