123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
- From: Samuel Attard <[email protected]>
- Date: Mon, 4 Mar 2019 14:43:36 -0800
- Subject: mas: avoid usage of private macOS APIs
- Disable usage of the following private APIs in MAS builds:
- * abort_report_np
- * pthread_fchdir_np
- * pthread_chdir_np
- * SetApplicationIsDaemon
- * _LSSetApplicationLaunchServicesServerConnectionStatus
- * AreDeviceAndUserJoinedToDomain
- * _CFIsObjC
- * AudioDeviceDuck
- diff --git a/base/enterprise_util_mac.mm b/base/enterprise_util_mac.mm
- index fd14573e1617d397012e5bb54efb229415326cca..6d1f3ca0f81d8d79b0e6d436a3fdb741a2b8e7c3 100644
- --- a/base/enterprise_util_mac.mm
- +++ b/base/enterprise_util_mac.mm
- @@ -113,6 +113,13 @@ MacDeviceManagementState IsDeviceRegisteredWithManagement() {
- DeviceUserDomainJoinState AreDeviceAndUserJoinedToDomain() {
- static DeviceUserDomainJoinState state = [] {
- DeviceUserDomainJoinState state{false, false};
- +#if IS_MAS_BUILD()
- + return state;
- + }();
- +
- + return state;
- +}
- +#else
-
- @autoreleasepool {
- ODSession* session = [ODSession defaultSession];
- @@ -219,5 +226,6 @@ DeviceUserDomainJoinState AreDeviceAndUserJoinedToDomain() {
-
- return state;
- }
- +#endif
-
- } // namespace base
- diff --git a/base/process/launch_mac.cc b/base/process/launch_mac.cc
- index b267bc2272fa82334a70d897a900f1ea37b1a598..967e22699bf565368704972c021f9b425a570f08 100644
- --- a/base/process/launch_mac.cc
- +++ b/base/process/launch_mac.cc
- @@ -21,13 +21,18 @@
- #include "base/threading/scoped_blocking_call.h"
- #include "base/threading/thread_restrictions.h"
- #include "base/trace_event/base_tracing.h"
- +#if IS_MAS_BUILD()
- +#include <sys/syscall.h>
- +#endif
-
- extern "C" {
- // Changes the current thread's directory to a path or directory file
- // descriptor.
- +#if !IS_MAS_BUILD()
- int pthread_chdir_np(const char* dir);
-
- int pthread_fchdir_np(int fd);
- +#endif
-
- int responsibility_spawnattrs_setdisclaim(posix_spawnattr_t attrs,
- int disclaim);
- @@ -99,13 +104,27 @@ class PosixSpawnFileActions {
-
- #if !BUILDFLAG(IS_MAC)
- int ChangeCurrentThreadDirectory(const char* path) {
- +#if IS_MAS_BUILD()
- + #pragma clang diagnostic push
- + #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- + return syscall(SYS___pthread_chdir, path);
- + #pragma clang diagnostic pop
- +#else
- return pthread_chdir_np(path);
- +#endif
- }
-
- // The recommended way to unset a per-thread cwd is to set a new value to an
- // invalid file descriptor, per libpthread-218.1.3/private/private.h.
- int ResetCurrentThreadDirectory() {
- +#if IS_MAS_BUILD()
- + #pragma clang diagnostic push
- + #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- + return syscall(SYS___pthread_fchdir, -1);
- + #pragma clang diagnostic pop
- +#else
- return pthread_fchdir_np(-1);
- +#endif
- }
- #endif
-
- @@ -226,7 +245,7 @@ Process LaunchProcess(const std::vector<std::string>& argv,
- file_actions.Inherit(STDERR_FILENO);
- }
-
- -#if BUILDFLAG(IS_MAC)
- +#if 0
- if (options.disclaim_responsibility) {
- DPSXCHECK(responsibility_spawnattrs_setdisclaim(attr.get(), 1));
- }
- diff --git a/media/audio/mac/audio_low_latency_input_mac.cc b/media/audio/mac/audio_low_latency_input_mac.cc
- index 6e73be2bd964aa8cf743c1ae01ce8e188dbcac8e..58a7eb1e982a90d6197579ffdb9545340356a65c 100644
- --- a/media/audio/mac/audio_low_latency_input_mac.cc
- +++ b/media/audio/mac/audio_low_latency_input_mac.cc
- @@ -31,19 +31,23 @@
-
- namespace {
- extern "C" {
- +#if !IS_MAS_BUILD()
- // See:
- // https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/PAL/pal/spi/cf/CoreAudioSPI.h?rev=228264
- OSStatus AudioDeviceDuck(AudioDeviceID inDevice,
- Float32 inDuckedLevel,
- const AudioTimeStamp* __nullable inStartTime,
- Float32 inRampDuration) __attribute__((weak_import));
- +#endif
- }
-
- void UndoDucking(AudioDeviceID output_device_id) {
- +#if !IS_MAS_BUILD()
- if (AudioDeviceDuck != nullptr) {
- // Ramp the volume back up over half a second.
- AudioDeviceDuck(output_device_id, 1.0, nullptr, 0.5);
- }
- +#endif
- }
-
- } // namespace
- diff --git a/sandbox/mac/sandbox_logging.cc b/sandbox/mac/sandbox_logging.cc
- index f52f1d1da4d431505b1a55df4764f37a70e0b29d..2406f5d4342dafc0d2c398f03ac23907a55c929f 100644
- --- a/sandbox/mac/sandbox_logging.cc
- +++ b/sandbox/mac/sandbox_logging.cc
- @@ -32,9 +32,11 @@
- }
- #endif
-
- +#if !IS_MAS_BUILD()
- extern "C" {
- void abort_report_np(const char*, ...);
- }
- +#endif
-
- namespace sandbox::logging {
-
- @@ -71,9 +73,11 @@ void SendOsLog(Level level, const char* message) {
-
- os_log_with_type(log.get(), os_log_type, "%{public}s", message);
-
- +#if !IS_MAS_BUILD()
- if (level == Level::FATAL) {
- abort_report_np(message);
- }
- +#endif
- }
-
- // |error| is strerror(errno) when a P* logging function is called. Pass
- diff --git a/sandbox/mac/system_services.cc b/sandbox/mac/system_services.cc
- index 175cbb4a23a4ab5f86c4bfa8158f8e0ada5454ed..ce44db60ba61394bbadacc4b85c94643a6e0261f 100644
- --- a/sandbox/mac/system_services.cc
- +++ b/sandbox/mac/system_services.cc
- @@ -9,6 +9,7 @@
-
- #include "base/mac/mac_logging.h"
-
- +#if !IS_MAS_BUILD()
- extern "C" {
- OSStatus SetApplicationIsDaemon(Boolean isDaemon);
- void _LSSetApplicationLaunchServicesServerConnectionStatus(
- @@ -19,10 +20,12 @@ void _LSSetApplicationLaunchServicesServerConnectionStatus(
- // https://github.com/WebKit/WebKit/blob/24aaedc770d192d03a07ba4a71727274aaa8fc07/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm#L840
- void _CSCheckFixDisable();
- } // extern "C"
- +#endif
-
- namespace sandbox {
-
- void DisableLaunchServices() {
- + #if !IS_MAS_BUILD()
- // Allow the process to continue without a LaunchServices ASN. The
- // INIT_Process function in HIServices will abort if it cannot connect to
- // launchservicesd to get an ASN. By setting this flag, HIServices skips
- @@ -36,10 +39,13 @@ void DisableLaunchServices() {
- 0, ^bool(CFDictionaryRef options) {
- return false;
- });
- + #endif
- }
-
- void DisableCoreServicesCheckFix() {
- +#if !IS_MAS_BUILD()
- _CSCheckFixDisable();
- +#endif
- }
-
- } // namespace sandbox
|