mas_avoid_usage_of_private_macos_apis.patch 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Samuel Attard <[email protected]>
  3. Date: Mon, 4 Mar 2019 14:43:36 -0800
  4. Subject: mas: avoid usage of private macOS APIs
  5. Disable usage of the following private APIs in MAS builds:
  6. * abort_report_np
  7. * pthread_fchdir_np
  8. * pthread_chdir_np
  9. * SetApplicationIsDaemon
  10. * _LSSetApplicationLaunchServicesServerConnectionStatus
  11. * AreDeviceAndUserJoinedToDomain
  12. * _CFIsObjC
  13. * AudioDeviceDuck
  14. diff --git a/base/enterprise_util_mac.mm b/base/enterprise_util_mac.mm
  15. index fd14573e1617d397012e5bb54efb229415326cca..6d1f3ca0f81d8d79b0e6d436a3fdb741a2b8e7c3 100644
  16. --- a/base/enterprise_util_mac.mm
  17. +++ b/base/enterprise_util_mac.mm
  18. @@ -113,6 +113,13 @@ MacDeviceManagementState IsDeviceRegisteredWithManagement() {
  19. DeviceUserDomainJoinState AreDeviceAndUserJoinedToDomain() {
  20. static DeviceUserDomainJoinState state = [] {
  21. DeviceUserDomainJoinState state{false, false};
  22. +#if IS_MAS_BUILD()
  23. + return state;
  24. + }();
  25. +
  26. + return state;
  27. +}
  28. +#else
  29. @autoreleasepool {
  30. ODSession* session = [ODSession defaultSession];
  31. @@ -219,5 +226,6 @@ DeviceUserDomainJoinState AreDeviceAndUserJoinedToDomain() {
  32. return state;
  33. }
  34. +#endif
  35. } // namespace base
  36. diff --git a/base/process/launch_mac.cc b/base/process/launch_mac.cc
  37. index b267bc2272fa82334a70d897a900f1ea37b1a598..967e22699bf565368704972c021f9b425a570f08 100644
  38. --- a/base/process/launch_mac.cc
  39. +++ b/base/process/launch_mac.cc
  40. @@ -21,13 +21,18 @@
  41. #include "base/threading/scoped_blocking_call.h"
  42. #include "base/threading/thread_restrictions.h"
  43. #include "base/trace_event/base_tracing.h"
  44. +#if IS_MAS_BUILD()
  45. +#include <sys/syscall.h>
  46. +#endif
  47. extern "C" {
  48. // Changes the current thread's directory to a path or directory file
  49. // descriptor.
  50. +#if !IS_MAS_BUILD()
  51. int pthread_chdir_np(const char* dir);
  52. int pthread_fchdir_np(int fd);
  53. +#endif
  54. int responsibility_spawnattrs_setdisclaim(posix_spawnattr_t attrs,
  55. int disclaim);
  56. @@ -99,13 +104,27 @@ class PosixSpawnFileActions {
  57. #if !BUILDFLAG(IS_MAC)
  58. int ChangeCurrentThreadDirectory(const char* path) {
  59. +#if IS_MAS_BUILD()
  60. + #pragma clang diagnostic push
  61. + #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  62. + return syscall(SYS___pthread_chdir, path);
  63. + #pragma clang diagnostic pop
  64. +#else
  65. return pthread_chdir_np(path);
  66. +#endif
  67. }
  68. // The recommended way to unset a per-thread cwd is to set a new value to an
  69. // invalid file descriptor, per libpthread-218.1.3/private/private.h.
  70. int ResetCurrentThreadDirectory() {
  71. +#if IS_MAS_BUILD()
  72. + #pragma clang diagnostic push
  73. + #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  74. + return syscall(SYS___pthread_fchdir, -1);
  75. + #pragma clang diagnostic pop
  76. +#else
  77. return pthread_fchdir_np(-1);
  78. +#endif
  79. }
  80. #endif
  81. @@ -226,7 +245,7 @@ Process LaunchProcess(const std::vector<std::string>& argv,
  82. file_actions.Inherit(STDERR_FILENO);
  83. }
  84. -#if BUILDFLAG(IS_MAC)
  85. +#if 0
  86. if (options.disclaim_responsibility) {
  87. DPSXCHECK(responsibility_spawnattrs_setdisclaim(attr.get(), 1));
  88. }
  89. diff --git a/media/audio/mac/audio_low_latency_input_mac.cc b/media/audio/mac/audio_low_latency_input_mac.cc
  90. index 6e73be2bd964aa8cf743c1ae01ce8e188dbcac8e..58a7eb1e982a90d6197579ffdb9545340356a65c 100644
  91. --- a/media/audio/mac/audio_low_latency_input_mac.cc
  92. +++ b/media/audio/mac/audio_low_latency_input_mac.cc
  93. @@ -31,19 +31,23 @@
  94. namespace {
  95. extern "C" {
  96. +#if !IS_MAS_BUILD()
  97. // See:
  98. // https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/PAL/pal/spi/cf/CoreAudioSPI.h?rev=228264
  99. OSStatus AudioDeviceDuck(AudioDeviceID inDevice,
  100. Float32 inDuckedLevel,
  101. const AudioTimeStamp* __nullable inStartTime,
  102. Float32 inRampDuration) __attribute__((weak_import));
  103. +#endif
  104. }
  105. void UndoDucking(AudioDeviceID output_device_id) {
  106. +#if !IS_MAS_BUILD()
  107. if (AudioDeviceDuck != nullptr) {
  108. // Ramp the volume back up over half a second.
  109. AudioDeviceDuck(output_device_id, 1.0, nullptr, 0.5);
  110. }
  111. +#endif
  112. }
  113. } // namespace
  114. diff --git a/sandbox/mac/sandbox_logging.cc b/sandbox/mac/sandbox_logging.cc
  115. index f52f1d1da4d431505b1a55df4764f37a70e0b29d..2406f5d4342dafc0d2c398f03ac23907a55c929f 100644
  116. --- a/sandbox/mac/sandbox_logging.cc
  117. +++ b/sandbox/mac/sandbox_logging.cc
  118. @@ -32,9 +32,11 @@
  119. }
  120. #endif
  121. +#if !IS_MAS_BUILD()
  122. extern "C" {
  123. void abort_report_np(const char*, ...);
  124. }
  125. +#endif
  126. namespace sandbox::logging {
  127. @@ -71,9 +73,11 @@ void SendOsLog(Level level, const char* message) {
  128. os_log_with_type(log.get(), os_log_type, "%{public}s", message);
  129. +#if !IS_MAS_BUILD()
  130. if (level == Level::FATAL) {
  131. abort_report_np(message);
  132. }
  133. +#endif
  134. }
  135. // |error| is strerror(errno) when a P* logging function is called. Pass
  136. diff --git a/sandbox/mac/system_services.cc b/sandbox/mac/system_services.cc
  137. index 175cbb4a23a4ab5f86c4bfa8158f8e0ada5454ed..ce44db60ba61394bbadacc4b85c94643a6e0261f 100644
  138. --- a/sandbox/mac/system_services.cc
  139. +++ b/sandbox/mac/system_services.cc
  140. @@ -9,6 +9,7 @@
  141. #include "base/mac/mac_logging.h"
  142. +#if !IS_MAS_BUILD()
  143. extern "C" {
  144. OSStatus SetApplicationIsDaemon(Boolean isDaemon);
  145. void _LSSetApplicationLaunchServicesServerConnectionStatus(
  146. @@ -19,10 +20,12 @@ void _LSSetApplicationLaunchServicesServerConnectionStatus(
  147. // https://github.com/WebKit/WebKit/blob/24aaedc770d192d03a07ba4a71727274aaa8fc07/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm#L840
  148. void _CSCheckFixDisable();
  149. } // extern "C"
  150. +#endif
  151. namespace sandbox {
  152. void DisableLaunchServices() {
  153. + #if !IS_MAS_BUILD()
  154. // Allow the process to continue without a LaunchServices ASN. The
  155. // INIT_Process function in HIServices will abort if it cannot connect to
  156. // launchservicesd to get an ASN. By setting this flag, HIServices skips
  157. @@ -36,10 +39,13 @@ void DisableLaunchServices() {
  158. 0, ^bool(CFDictionaryRef options) {
  159. return false;
  160. });
  161. + #endif
  162. }
  163. void DisableCoreServicesCheckFix() {
  164. +#if !IS_MAS_BUILD()
  165. _CSCheckFixDisable();
  166. +#endif
  167. }
  168. } // namespace sandbox