<rdar://problem/29471922> Safari should switch from the legacy denap SPI to handling...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Jan 2019 01:50:45 +0000 (01:50 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Jan 2019 01:50:45 +0000 (01:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193992

Patch by Daniel Steffen <dsteffen@apple.com> on 2019-01-30
Reviewed by Geoffrey Garen.

The denap SPI is deprecated.
The new way of staying out of AppNap is through a voucher.

* Platform/IPC/mac/ConnectionMac.mm:
(IPC::readFromMachPort):
* Platform/IPC/mac/ImportanceAssertion.h:
(IPC::ImportanceAssertion::ImportanceAssertion):
(IPC::ImportanceAssertion::~ImportanceAssertion):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240745 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/Platform/IPC/mac/ConnectionMac.mm
Source/WebKit/Platform/IPC/mac/ImportanceAssertion.h

index a12012d..18483e8 100644 (file)
@@ -1,3 +1,19 @@
+2019-01-30  Daniel Steffen  <dsteffen@apple.com>
+
+        <rdar://problem/29471922> Safari should switch from the legacy denap SPI to handling vouchers
+        https://bugs.webkit.org/show_bug.cgi?id=193992
+
+        Reviewed by Geoffrey Garen.
+
+        The denap SPI is deprecated.
+        The new way of staying out of AppNap is through a voucher.
+
+        * Platform/IPC/mac/ConnectionMac.mm:
+        (IPC::readFromMachPort):
+        * Platform/IPC/mac/ImportanceAssertion.h:
+        (IPC::ImportanceAssertion::ImportanceAssertion):
+        (IPC::ImportanceAssertion::~ImportanceAssertion):
+
 2019-01-30  Chris Dumez  <cdumez@apple.com>
 
         Fix crashes when trying to ref the CallbackAggregator in NetworkProcess
index 50416b8..b98ac56 100644 (file)
@@ -476,7 +476,7 @@ static mach_msg_header_t* readFromMachPort(mach_port_t machPort, ReceiveBuffer&
     buffer.resize(receiveBufferSize);
 
     mach_msg_header_t* header = reinterpret_cast<mach_msg_header_t*>(buffer.data());
-    kern_return_t kr = mach_msg(header, MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_TIMEOUT, 0, buffer.size(), machPort, 0, MACH_PORT_NULL);
+    kern_return_t kr = mach_msg(header, MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_TIMEOUT | MACH_RCV_VOUCHER, 0, buffer.size(), machPort, 0, MACH_PORT_NULL);
     if (kr == MACH_RCV_TIMED_OUT)
         return nullptr;
 
@@ -485,7 +485,7 @@ static mach_msg_header_t* readFromMachPort(mach_port_t machPort, ReceiveBuffer&
         buffer.resize(header->msgh_size + MAX_TRAILER_SIZE);
         header = reinterpret_cast<mach_msg_header_t*>(buffer.data());
         
-        kr = mach_msg(header, MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_TIMEOUT, 0, buffer.size(), machPort, 0, MACH_PORT_NULL);
+        kr = mach_msg(header, MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_TIMEOUT | MACH_RCV_VOUCHER, 0, buffer.size(), machPort, 0, MACH_PORT_NULL);
         ASSERT(kr != MACH_RCV_TOO_LARGE);
     }
 
index f7687a7..d9765d1 100644 (file)
 
 #if PLATFORM(MAC)
 
-#if USE(APPLE_INTERNAL_SDK)
-#include <libproc_internal.h>
-#endif
-
-extern "C" int proc_denap_assertion_begin_with_msg(mach_msg_header_t*, uint64_t *);
-extern "C" int proc_denap_assertion_complete(uint64_t);
+#include <mach/message.h>
 
 namespace IPC {
 
@@ -42,18 +37,25 @@ class ImportanceAssertion {
 
 public:
     explicit ImportanceAssertion(mach_msg_header_t* header)
-        : m_assertion(0)
+        : m_voucher(0)
     {
-        proc_denap_assertion_begin_with_msg(header, &m_assertion);
+        if (MACH_MSGH_BITS_HAS_VOUCHER(header->msgh_bits)) {
+            m_voucher = header->msgh_voucher_port;
+            header->msgh_voucher_port = MACH_VOUCHER_NULL;
+            header->msgh_bits &= ~(MACH_MSGH_BITS_VOUCHER_MASK | MACH_MSGH_BITS_RAISEIMP);
+        }
     }
 
     ~ImportanceAssertion()
     {
-        proc_denap_assertion_complete(m_assertion);
+        if (m_voucher) {
+            kern_return_t kr = mach_voucher_deallocate(m_voucher);
+            ASSERT_UNUSED(kr, !kr);
+        }
     }
 
 private:
-    uint64_t m_assertion;
+    mach_voucher_t m_voucher;
 };
 
 }