From 70736cfb1b96d6f29dfb4b32795b261f9aa32bcf Mon Sep 17 00:00:00 2001 From: Jed Davis Date: Wed, 4 Oct 2017 20:31:12 -0600 Subject: [PATCH] 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 --- dom/media/gmp/GMPProcessParent.cpp | 3 +- dom/plugins/base/nsPluginsDirDarwin.cpp | 60 ----------- dom/plugins/ipc/PluginProcessParent.cpp | 39 +------ ipc/chromium/src/base/process_util.h | 32 +----- ipc/chromium/src/base/process_util_bsd.cc | 3 +- ipc/chromium/src/base/process_util_linux.cc | 3 +- ipc/chromium/src/base/process_util_mac.mm | 29 +----- ipc/glue/GeckoChildProcessHost.cpp | 107 +++----------------- ipc/glue/GeckoChildProcessHost.h | 19 +--- 9 files changed, 25 insertions(+), 270 deletions(-) diff --git a/dom/media/gmp/GMPProcessParent.cpp b/dom/media/gmp/GMPProcessParent.cpp index aad88b3ab145..823e120bc3a4 100644 --- a/dom/media/gmp/GMPProcessParent.cpp +++ b/dom/media/gmp/GMPProcessParent.cpp @@ -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 diff --git a/dom/plugins/base/nsPluginsDirDarwin.cpp b/dom/plugins/base/nsPluginsDirDarwin.cpp index b6ddf77062c9..3422943b4583 100644 --- a/dom/plugins/base/nsPluginsDirDarwin.cpp +++ b/dom/plugins/base/nsPluginsDirDarwin.cpp @@ -65,19 +65,6 @@ static CFBundleRef getPluginBundle(const char* path) return bundle; } -static nsresult toCFURLRef(nsIFile* file, CFURLRef& outURL) -{ - nsCOMPtr 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)); diff --git a/dom/plugins/ipc/PluginProcessParent.cpp b/dom/plugins/ipc/PluginProcessParent.cpp index e55d5378d99c..c652df36e285 100644 --- a/dom/plugins/ipc/PluginProcessParent.cpp +++ b/dom/plugins/ipc/PluginProcessParent.cpp @@ -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 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 args; args.push_back(MungePluginDsoPath(mPluginFilePath)); - bool result = AsyncLaunch(args, selectedArchitecture); + bool result = AsyncLaunch(args); if (!result) { mLaunchCompleteTask = nullptr; } diff --git a/ipc/chromium/src/base/process_util.h b/ipc/chromium/src/base/process_util.h index 32b1c803c2bf..77388d3869d0 100644 --- a/ipc/chromium/src/base/process_util.h +++ b/ipc/chromium/src/base/process_util.h @@ -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 environment_map; bool LaunchApp(const std::vector& 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 diff --git a/ipc/chromium/src/base/process_util_bsd.cc b/ipc/chromium/src/base/process_util_bsd.cc index cb7086ccd60a..e695fe16f02f 100644 --- a/ipc/chromium/src/base/process_util_bsd.cc +++ b/ipc/chromium/src/base/process_util_bsd.cc @@ -34,8 +34,7 @@ bool LaunchApp(const std::vector& argv, bool LaunchApp(const std::vector& 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]; diff --git a/ipc/chromium/src/base/process_util_linux.cc b/ipc/chromium/src/base/process_util_linux.cc index aab06a90ed02..cc9ffec55b5d 100644 --- a/ipc/chromium/src/base/process_util_linux.cc +++ b/ipc/chromium/src/base/process_util_linux.cc @@ -34,8 +34,7 @@ bool LaunchApp(const std::vector& argv, bool LaunchApp(const std::vector& 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 argv_cstr(new char*[argv.size() + 1]); // Illegal to allocate memory after fork and before execvp InjectiveMultimap fd_shuffle1, fd_shuffle2; diff --git a/ipc/chromium/src/base/process_util_mac.mm b/ipc/chromium/src/base/process_util_mac.mm index 3711e86745e5..34736feeb262 100644 --- a/ipc/chromium/src/base/process_util_mac.mm +++ b/ipc/chromium/src/base/process_util_mac.mm @@ -33,8 +33,7 @@ bool LaunchApp(const std::vector& argv, bool LaunchApp(const std::vector& 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& 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& 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.) diff --git a/ipc/glue/GeckoChildProcessHost.cpp b/ipc/glue/GeckoChildProcessHost.cpp index 81ad062a0a50..6fabb96e0e4f 100644 --- a/ipc/glue/GeckoChildProcessHost.cpp +++ b/ipc/glue/GeckoChildProcessHost.cpp @@ -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(::CFArrayGetValueAtIndex(pluginContainerArchs, i)); - int currentArchInt = 0; - if (!::CFNumberGetValue(currentArch, kCFNumberIntType, ¤tArchInt)) { - 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 aExtraOpts, int aTimeoutMs, base::ProcessArchitecture arch) +GeckoChildProcessHost::SyncLaunch(std::vector aExtraOpts, int aTimeoutMs) { PrepareLaunch(); MessageLoop* ioLoop = XRE_GetIOMessageLoop(); NS_ASSERTION(MessageLoop::current() != ioLoop, "sync launch from the IO thread NYI"); - ioLoop->PostTask(NewNonOwningRunnableMethod, - base::ProcessArchitecture>( + ioLoop->PostTask(NewNonOwningRunnableMethod>( "ipc::GeckoChildProcessHost::RunPerformAsyncLaunch", this, &GeckoChildProcessHost::RunPerformAsyncLaunch, - aExtraOpts, - arch)); + aExtraOpts)); return WaitUntilConnected(aTimeoutMs); } bool -GeckoChildProcessHost::AsyncLaunch(std::vector aExtraOpts, - base::ProcessArchitecture arch) +GeckoChildProcessHost::AsyncLaunch(std::vector aExtraOpts) { PrepareLaunch(); MessageLoop* ioLoop = XRE_GetIOMessageLoop(); - ioLoop->PostTask(NewNonOwningRunnableMethod, - base::ProcessArchitecture>( + ioLoop->PostTask(NewNonOwningRunnableMethod>( "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, - base::ProcessArchitecture>( + ioLoop->PostTask(NewNonOwningRunnableMethod>( "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 aExtraOpts, base::ProcessArchitecture arch) +GeckoChildProcessHost::PerformAsyncLaunch(std::vector aExtraOpts) { #ifdef MOZ_GECKO_PROFILER AutoSetProfilerEnvVarsForChildProcess profilerEnvironment; @@ -605,7 +527,7 @@ GeckoChildProcessHost::PerformAsyncLaunch(std::vector 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 aExtraOpts, b } bool -GeckoChildProcessHost::RunPerformAsyncLaunch(std::vector aExtraOpts, - base::ProcessArchitecture aArch) +GeckoChildProcessHost::RunPerformAsyncLaunch(std::vector 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& aCmdLine) } bool -GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector& aExtraOpts, base::ProcessArchitecture arch) +GeckoChildProcessHost::PerformAsyncLaunchInternal(std::vector& 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& 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 diff --git a/ipc/glue/GeckoChildProcessHost.h b/ipc/glue/GeckoChildProcessHost.h index 4e089270b396..b3df498e98a1 100644 --- a/ipc/glue/GeckoChildProcessHost.h +++ b/ipc/glue/GeckoChildProcessHost.h @@ -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& aExtraOpts, - base::ProcessArchitecture arch); + bool PerformAsyncLaunchInternal(std::vector& aExtraOpts); - bool RunPerformAsyncLaunch(StringVector aExtraOpts=StringVector(), - base::ProcessArchitecture aArch=base::GetCurrentProcessArchitecture()); + bool RunPerformAsyncLaunch(StringVector aExtraOpts=StringVector()); enum class BinaryPathType { Self,