Backed out 2 changesets (bug 1792567) for causing build bustages on GMPParent.cpp CLOSED TREE

Backed out changeset 83c15124953e (bug 1792567)
Backed out changeset 63e7210c153a (bug 1792567)
This commit is contained in:
Cristian Tuns 2022-10-12 14:51:46 -04:00
parent f2f36b1381
commit b867230c54
6 changed files with 266 additions and 51 deletions

View File

@ -27,6 +27,7 @@ XPIDL_SOURCES += [
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
XPIDL_SOURCES += [
"nsIMacPreferencesReader.idl",
"nsIMacUtils.idl",
]
EXPORTS += [
"nsObjCExceptions.h",

View File

@ -0,0 +1,26 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "nsISupports.idl"
/**
* nsIMacUtils: Generic globally-available Mac-specific utilities.
*/
[uuid(5E9072D7-FF95-455E-9466-8AF9841A72EC)]
interface nsIMacUtils : nsISupports
{
/**
* Returns a string containing a list of architectures delimited
* by "-". Architecture sets are always in the same order:
* ppc > i386 > ppc64 > x86_64 > (future additions)
*/
readonly attribute AString architecturesInBinary;
/**
* True when running under binary translation (Rosetta).
*/
readonly attribute boolean isTranslated;
};

View File

@ -30,21 +30,20 @@
#endif
#include <sys/sysctl.h>
NS_IMPL_ISUPPORTS(nsMacUtilsImpl, nsIMacUtils)
using mozilla::StaticMutexAutoLock;
using mozilla::Unused;
#if defined(MOZ_SANDBOX) || defined(__aarch64__)
// For thread safe setting/checking of sCachedAppPath
static StaticMutex sCachedAppPathMutex;
// Cache the appDir returned from GetAppPath to avoid doing I/O
static StaticAutoPtr<nsCString> sCachedAppPath
MOZ_GUARDED_BY(sCachedAppPathMutex);
StaticAutoPtr<nsCString> nsMacUtilsImpl::sCachedAppPath;
StaticMutex nsMacUtilsImpl::sCachedAppPathMutex;
#endif
std::atomic<uint32_t> nsMacUtilsImpl::sBundleArchMaskAtomic = 0;
#if defined(__aarch64__)
// Limit XUL translation to one attempt
static std::atomic<bool> sIsXULTranslated = false;
std::atomic<bool> nsMacUtilsImpl::sIsXULTranslated = false;
#endif
// Info.plist key associated with the developer repo path
@ -55,20 +54,92 @@ static std::atomic<bool> sIsXULTranslated = false;
// Workaround this constant not being available in the macOS SDK
#define kCFBundleExecutableArchitectureARM64 0x0100000c
enum TCSMStatus { TCSM_Unknown = 0, TCSM_Available, TCSM_Unavailable };
// Initialize with Unknown until we've checked if TCSM is available to set
static Atomic<TCSMStatus> sTCSMStatus(TCSM_Unknown);
Atomic<nsMacUtilsImpl::TCSMStatus> nsMacUtilsImpl::sTCSMStatus(TCSM_Unknown);
#if defined(MOZ_SANDBOX) || defined(__aarch64__)
nsresult nsMacUtilsImpl::GetArchString(nsAString& aArchString) {
if (!mBinaryArchs.IsEmpty()) {
aArchString.Assign(mBinaryArchs);
return NS_OK;
}
uint32_t archMask = base::PROCESS_ARCH_INVALID;
nsresult rv = GetArchitecturesForBundle(&archMask);
NS_ENSURE_SUCCESS(rv, rv);
// The order in the string must always be the same so
// don't do this in the loop.
if (archMask & base::PROCESS_ARCH_PPC) {
mBinaryArchs.AppendLiteral("ppc");
}
if (archMask & base::PROCESS_ARCH_I386) {
if (!mBinaryArchs.IsEmpty()) {
mBinaryArchs.Append('-');
}
mBinaryArchs.AppendLiteral("i386");
}
if (archMask & base::PROCESS_ARCH_PPC_64) {
if (!mBinaryArchs.IsEmpty()) {
mBinaryArchs.Append('-');
}
mBinaryArchs.AppendLiteral("ppc64");
}
if (archMask & base::PROCESS_ARCH_X86_64) {
if (!mBinaryArchs.IsEmpty()) {
mBinaryArchs.Append('-');
}
mBinaryArchs.AppendLiteral("x86_64");
}
if (archMask & base::PROCESS_ARCH_ARM_64) {
if (!mBinaryArchs.IsEmpty()) {
mBinaryArchs.Append('-');
}
mBinaryArchs.AppendLiteral("arm64");
}
aArchString.Truncate();
aArchString.Assign(mBinaryArchs);
return (aArchString.IsEmpty() ? NS_ERROR_FAILURE : NS_OK);
}
NS_IMETHODIMP
nsMacUtilsImpl::GetArchitecturesInBinary(nsAString& aArchString) {
return GetArchString(aArchString);
}
// True when running under binary translation (Rosetta).
NS_IMETHODIMP
nsMacUtilsImpl::GetIsTranslated(bool* aIsTranslated) {
#ifdef __ppc__
static bool sInitialized = false;
// Initialize sIsNative to 1. If the sysctl fails because it doesn't
// exist, then translation is not possible, so the process must not be
// running translated.
static int32_t sIsNative = 1;
if (!sInitialized) {
size_t sz = sizeof(sIsNative);
sysctlbyname("sysctl.proc_native", &sIsNative, &sz, nullptr, 0);
sInitialized = true;
}
*aIsTranslated = !sIsNative;
#else
// Translation only exists for ppc code. Other architectures aren't
// translated.
*aIsTranslated = false;
#endif
// Utility method to call ClearOnShutdown() on the main thread
static nsresult ClearCachedAppPathOnShutdown() {
MOZ_ASSERT(NS_IsMainThread());
ClearOnShutdown(&sCachedAppPath);
return NS_OK;
}
#if defined(MOZ_SANDBOX) || defined(__aarch64__)
// Get the path to the .app directory (aka bundle) for the parent process.
// When executing in the child process, this is the outer .app (such as
// Firefox.app) and not the inner .app containing the child process
@ -130,17 +201,22 @@ bool nsMacUtilsImpl::GetAppPath(nsCString& aAppPath) {
sCachedAppPath = new nsCString(aAppPath);
if (NS_IsMainThread()) {
ClearCachedAppPathOnShutdown();
nsMacUtilsImpl::ClearCachedAppPathOnShutdown();
} else {
NS_DispatchToMainThread(
NS_NewRunnableFunction("ClearCachedAppPathOnShutdown",
[] { ClearCachedAppPathOnShutdown(); }));
NS_DispatchToMainThread(NS_NewRunnableFunction(
"nsMacUtilsImpl::ClearCachedAppPathOnShutdown",
[] { nsMacUtilsImpl::ClearCachedAppPathOnShutdown(); }));
}
}
return true;
}
nsresult nsMacUtilsImpl::ClearCachedAppPathOnShutdown() {
MOZ_ASSERT(NS_IsMainThread());
ClearOnShutdown(&sCachedAppPath);
return NS_OK;
}
#endif /* MOZ_SANDBOX || __aarch64__ */
#if defined(MOZ_SANDBOX) && defined(DEBUG)
@ -204,7 +280,8 @@ bool nsMacUtilsImpl::IsTCSMAvailable() {
return (sTCSMStatus == TCSM_Available);
}
static nsresult EnableTCSM() {
/* static */
nsresult nsMacUtilsImpl::EnableTCSM() {
uint32_t newVal = 1;
int rv = sysctlbyname("kern.tcsm_enable", NULL, 0, &newVal, sizeof(newVal));
if (rv < 0) {
@ -213,15 +290,6 @@ static nsresult EnableTCSM() {
return NS_OK;
}
#if defined(DEBUG)
static bool IsTCSMEnabled() {
uint32_t oldVal = 0;
size_t oldValSize = sizeof(oldVal);
int rv = sysctlbyname("kern.tcsm_enable", &oldVal, &oldValSize, NULL, 0);
return (rv == 0) && (oldVal != 0);
}
#endif
/*
* Intentionally return void so that failures will be ignored in non-debug
* builds. This method uses new sysctls which may not be as thoroughly tested
@ -237,6 +305,16 @@ void nsMacUtilsImpl::EnableTCSMIfAvailable() {
}
}
#if defined(DEBUG)
/* static */
bool nsMacUtilsImpl::IsTCSMEnabled() {
uint32_t oldVal = 0;
size_t oldValSize = sizeof(oldVal);
int rv = sysctlbyname("kern.tcsm_enable", &oldVal, &oldValSize, NULL, 0);
return (rv == 0) && (oldVal != 0);
}
#endif
// Returns 0 on error.
/* static */
uint32_t nsMacUtilsImpl::GetPhysicalCPUCount() {
@ -352,6 +430,56 @@ nsresult nsMacUtilsImpl::GetObjDir(nsIFile** aObjDir) {
aObjDir);
}
/* static */
nsresult nsMacUtilsImpl::GetArchitecturesForBundle(uint32_t* aArchMask) {
MOZ_ASSERT(aArchMask);
*aArchMask = sBundleArchMaskAtomic;
if (*aArchMask != 0) {
return NS_OK;
}
CFBundleRef mainBundle = ::CFBundleGetMainBundle();
if (!mainBundle) {
return NS_ERROR_FAILURE;
}
CFArrayRef archList = ::CFBundleCopyExecutableArchitectures(mainBundle);
if (!archList) {
return NS_ERROR_FAILURE;
}
CFIndex archCount = ::CFArrayGetCount(archList);
for (CFIndex i = 0; i < archCount; i++) {
CFNumberRef arch =
static_cast<CFNumberRef>(::CFArrayGetValueAtIndex(archList, i));
int archInt = 0;
if (!::CFNumberGetValue(arch, kCFNumberIntType, &archInt)) {
::CFRelease(archList);
return NS_ERROR_FAILURE;
}
if (archInt == kCFBundleExecutableArchitecturePPC) {
*aArchMask |= base::PROCESS_ARCH_PPC;
} else if (archInt == kCFBundleExecutableArchitectureI386) {
*aArchMask |= base::PROCESS_ARCH_I386;
} else if (archInt == kCFBundleExecutableArchitecturePPC64) {
*aArchMask |= base::PROCESS_ARCH_PPC_64;
} else if (archInt == kCFBundleExecutableArchitectureX86_64) {
*aArchMask |= base::PROCESS_ARCH_X86_64;
} else if (archInt == kCFBundleExecutableArchitectureARM64) {
*aArchMask |= base::PROCESS_ARCH_ARM_64;
}
}
::CFRelease(archList);
sBundleArchMaskAtomic = *aArchMask;
return NS_OK;
}
/* static */
nsresult nsMacUtilsImpl::GetArchitecturesForBinary(const char* aPath,
uint32_t* aArchMask) {

View File

@ -7,6 +7,7 @@
#ifndef nsMacUtilsImpl_h___
#define nsMacUtilsImpl_h___
#include "nsIMacUtils.h"
#include "nsString.h"
#include "mozilla/Atomics.h"
#include "mozilla/Attributes.h"
@ -17,38 +18,90 @@ using mozilla::Atomic;
using mozilla::StaticAutoPtr;
using mozilla::StaticMutex;
class nsIFile;
class nsMacUtilsImpl final : public nsIMacUtils {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMACUTILS
namespace nsMacUtilsImpl {
nsMacUtilsImpl() {}
// Return the repo directory and the repo object directory respectively.
// These should only be used on Mac developer builds to determine the path
// to the repo or object directory.
nsresult GetRepoDir(nsIFile** aRepoDir);
nsresult GetObjDir(nsIFile** aObjDir);
// Return the repo directory and the repo object directory respectively.
// These should only be used on Mac developer builds to determine the path
// to the repo or object directory.
static nsresult GetRepoDir(nsIFile** aRepoDir);
static nsresult GetObjDir(nsIFile** aObjDir);
#if defined(MOZ_SANDBOX) || defined(__aarch64__)
bool GetAppPath(nsCString& aAppPath);
static bool GetAppPath(nsCString& aAppPath);
#endif /* MOZ_SANDBOX || __aarch64__ */
#if defined(MOZ_SANDBOX) && defined(DEBUG)
nsresult GetBloatLogDir(nsCString& aDirectoryPath);
nsresult GetDirectoryPath(const char* aPath, nsCString& aDirectoryPath);
static nsresult GetBloatLogDir(nsCString& aDirectoryPath);
static nsresult GetDirectoryPath(const char* aPath,
nsCString& aDirectoryPath);
#endif /* MOZ_SANDBOX && DEBUG */
void EnableTCSMIfAvailable();
bool IsTCSMAvailable();
uint32_t GetPhysicalCPUCount();
nsresult GetArchitecturesForBinary(const char* aPath, uint32_t* aArchMask);
static void EnableTCSMIfAvailable();
static bool IsTCSMAvailable();
static uint32_t GetPhysicalCPUCount();
static nsresult GetArchitecturesForBundle(uint32_t* aArchMask);
static nsresult GetArchitecturesForBinary(const char* aPath,
uint32_t* aArchMask);
#if defined(__aarch64__)
// Pre-translate binaries to avoid translation delays when launching
// x64 child process instances for the first time. i.e. on first launch
// after installation or after an update. Translations are cached so
// repeated launches of the binaries do not encounter delays.
int PreTranslateXUL();
int PreTranslateBinary(nsCString aBinaryPath);
// Pre-translate binaries to avoid translation delays when launching
// x64 child process instances for the first time. i.e. on first launch
// after installation or after an update. Translations are cached so
// repeated launches of the binaries do not encounter delays.
static int PreTranslateXUL();
static int PreTranslateBinary(nsCString aBinaryPath);
#endif
} // namespace nsMacUtilsImpl
private:
~nsMacUtilsImpl() {}
nsresult GetArchString(nsAString& aArchString);
// A string containing a "-" delimited list of architectures
// in our binary.
nsString mBinaryArchs;
#if defined(MOZ_SANDBOX) || defined(__aarch64__)
// Cache the appDir returned from GetAppPath to avoid doing I/O
static StaticAutoPtr<nsCString> sCachedAppPath
MOZ_GUARDED_BY(sCachedAppPathMutex);
// For thread safe setting/checking of sCachedAppPath
static StaticMutex sCachedAppPathMutex;
// Utility method to call ClearOnShutdown() on the main thread
static nsresult ClearCachedAppPathOnShutdown();
#endif
// The cached machine architectures of the .app bundle which can
// be multiple architectures for universal binaries.
static std::atomic<uint32_t> sBundleArchMaskAtomic;
#if defined(__aarch64__)
// Limit XUL translation to one attempt
static std::atomic<bool> sIsXULTranslated;
#endif
enum TCSMStatus { TCSM_Unknown = 0, TCSM_Available, TCSM_Unavailable };
static mozilla::Atomic<nsMacUtilsImpl::TCSMStatus> sTCSMStatus;
static nsresult EnableTCSM();
#if defined(DEBUG)
static bool IsTCSMEnabled();
#endif
};
// Global singleton service
// 697BD3FD-43E5-41CE-AD5E-C339175C0818
#define NS_MACUTILSIMPL_CID \
{ \
0x697BD3FD, 0x43E5, 0x41CE, { \
0xAD, 0x5E, 0xC3, 0x39, 0x17, 0x5C, 0x08, 0x18 \
} \
}
#define NS_MACUTILSIMPL_CONTRACTID "@mozilla.org/xpcom/mac-utils;1"
#endif /* nsMacUtilsImpl_h___ */

View File

@ -127,6 +127,7 @@
#ifdef MOZ_WIDGET_COCOA
# include "nsILocalFileMac.h"
# include "nsIMacUtils.h"
#endif
// xpcom/glue utility headers

View File

@ -255,4 +255,10 @@ if buildconfig.substs['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
'type': 'nsMacPreferencesReader',
'headers': ['mozilla/nsMacPreferencesReader.h'],
},
{
'cid': '{697bd3fd-43e5-41ce-ad5e-c339175c0818}',
'contract_ids': ['@mozilla.org/xpcom/mac-utils;1'],
'type': 'nsMacUtilsImpl',
'headers': ['/xpcom/base/nsMacUtilsImpl.h'],
},
]