Title: [286393] branches/safari-612-branch/Source/WebKit
- Revision
- 286393
- Author
- [email protected]
- Date
- 2021-12-01 16:17:51 -0800 (Wed, 01 Dec 2021)
Log Message
Cherry-pick r285138. rdar://problem/75139294
Avoid heap-allocating ImportanceAssertion
https://bugs.webkit.org/show_bug.cgi?id=232579
Reviewed by Alex Christensen.
Avoid heap-allocating ImportanceAssertion since this is just a wrapper around a
mach_port.
Also update the ImportanceAssertion destructor to null out the mach port as
hardening given <rdar://75139294>.
* Platform/IPC/Decoder.cpp:
(IPC::Decoder::setImportanceAssertion):
* Platform/IPC/Decoder.h:
* Platform/IPC/cocoa/ConnectionCocoa.mm:
(IPC::Connection::receiveSourceEventHandler):
* Platform/IPC/cocoa/ImportanceAssertion.h:
(IPC::ImportanceAssertion::ImportanceAssertion):
(IPC::ImportanceAssertion::operator=):
(IPC::ImportanceAssertion::~ImportanceAssertion):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@285138 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Diff
Modified: branches/safari-612-branch/Source/WebKit/ChangeLog (286392 => 286393)
--- branches/safari-612-branch/Source/WebKit/ChangeLog 2021-12-01 23:52:20 UTC (rev 286392)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog 2021-12-02 00:17:51 UTC (rev 286393)
@@ -1,3 +1,54 @@
+2021-12-01 Alan Coon <[email protected]>
+
+ Cherry-pick r285138. rdar://problem/75139294
+
+ Avoid heap-allocating ImportanceAssertion
+ https://bugs.webkit.org/show_bug.cgi?id=232579
+
+ Reviewed by Alex Christensen.
+
+ Avoid heap-allocating ImportanceAssertion since this is just a wrapper around a
+ mach_port.
+
+ Also update the ImportanceAssertion destructor to null out the mach port as
+ hardening given <rdar://75139294>.
+
+ * Platform/IPC/Decoder.cpp:
+ (IPC::Decoder::setImportanceAssertion):
+ * Platform/IPC/Decoder.h:
+ * Platform/IPC/cocoa/ConnectionCocoa.mm:
+ (IPC::Connection::receiveSourceEventHandler):
+ * Platform/IPC/cocoa/ImportanceAssertion.h:
+ (IPC::ImportanceAssertion::ImportanceAssertion):
+ (IPC::ImportanceAssertion::operator=):
+ (IPC::ImportanceAssertion::~ImportanceAssertion):
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@285138 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-11-01 Chris Dumez <[email protected]>
+
+ Avoid heap-allocating ImportanceAssertion
+ https://bugs.webkit.org/show_bug.cgi?id=232579
+
+ Reviewed by Alex Christensen.
+
+ Avoid heap-allocating ImportanceAssertion since this is just a wrapper around a
+ mach_port.
+
+ Also update the ImportanceAssertion destructor to null out the mach port as
+ hardening given <rdar://75139294>.
+
+ * Platform/IPC/Decoder.cpp:
+ (IPC::Decoder::setImportanceAssertion):
+ * Platform/IPC/Decoder.h:
+ * Platform/IPC/cocoa/ConnectionCocoa.mm:
+ (IPC::Connection::receiveSourceEventHandler):
+ * Platform/IPC/cocoa/ImportanceAssertion.h:
+ (IPC::ImportanceAssertion::ImportanceAssertion):
+ (IPC::ImportanceAssertion::operator=):
+ (IPC::ImportanceAssertion::~ImportanceAssertion):
+
2021-11-18 Russell Epstein <[email protected]>
Cherry-pick r285130. rdar://problem/85166839
Modified: branches/safari-612-branch/Source/WebKit/Platform/IPC/Decoder.cpp (286392 => 286393)
--- branches/safari-612-branch/Source/WebKit/Platform/IPC/Decoder.cpp 2021-12-01 23:52:20 UTC (rev 286392)
+++ branches/safari-612-branch/Source/WebKit/Platform/IPC/Decoder.cpp 2021-12-02 00:17:51 UTC (rev 286393)
@@ -147,7 +147,7 @@
}
#if PLATFORM(MAC)
-void Decoder::setImportanceAssertion(std::unique_ptr<ImportanceAssertion> assertion)
+void Decoder::setImportanceAssertion(ImportanceAssertion&& assertion)
{
m_importanceAssertion = WTFMove(assertion);
}
Modified: branches/safari-612-branch/Source/WebKit/Platform/IPC/Decoder.h (286392 => 286393)
--- branches/safari-612-branch/Source/WebKit/Platform/IPC/Decoder.h 2021-12-01 23:52:20 UTC (rev 286392)
+++ branches/safari-612-branch/Source/WebKit/Platform/IPC/Decoder.h 2021-12-02 00:17:51 UTC (rev 286393)
@@ -32,6 +32,10 @@
#include <wtf/OptionSet.h>
#include <wtf/Vector.h>
+#if PLATFORM(MAC)
+#include "ImportanceAssertion.h"
+#endif
+
#if HAVE(QOS_CLASSES)
#include <pthread/qos.h>
#endif
@@ -38,7 +42,6 @@
namespace IPC {
-class ImportanceAssertion;
enum class MessageFlags : uint8_t;
enum class ShouldDispatchWhenWaitingForSyncReply : uint8_t;
@@ -67,7 +70,7 @@
bool shouldMaintainOrderingWithAsyncMessages() const;
#if PLATFORM(MAC)
- void setImportanceAssertion(std::unique_ptr<ImportanceAssertion>);
+ void setImportanceAssertion(ImportanceAssertion&&);
#endif
static std::unique_ptr<Decoder> unwrapForTesting(Decoder&);
@@ -173,7 +176,7 @@
uint64_t m_destinationID;
#if PLATFORM(MAC)
- std::unique_ptr<ImportanceAssertion> m_importanceAssertion;
+ ImportanceAssertion m_importanceAssertion;
#endif
};
Modified: branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm (286392 => 286393)
--- branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm 2021-12-01 23:52:20 UTC (rev 286392)
+++ branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm 2021-12-02 00:17:51 UTC (rev 286393)
@@ -545,7 +545,7 @@
return;
#if PLATFORM(MAC)
- decoder->setImportanceAssertion(makeUnique<ImportanceAssertion>(header));
+ decoder->setImportanceAssertion(ImportanceAssertion { header });
#endif
if (decoder->messageName() == MessageName::InitializeConnection) {
Modified: branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/ImportanceAssertion.h (286392 => 286393)
--- branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/ImportanceAssertion.h 2021-12-01 23:52:20 UTC (rev 286392)
+++ branches/safari-612-branch/Source/WebKit/Platform/IPC/cocoa/ImportanceAssertion.h 2021-12-02 00:17:51 UTC (rev 286393)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,30 +32,44 @@
namespace IPC {
class ImportanceAssertion {
- WTF_MAKE_FAST_ALLOCATED;
- WTF_MAKE_NONCOPYABLE(ImportanceAssertion);
+public:
+ ImportanceAssertion() = default;
-public:
explicit ImportanceAssertion(mach_msg_header_t* header)
- : m_voucher(0)
{
if (MACH_MSGH_BITS_HAS_VOUCHER(header->msgh_bits)) {
- m_voucher = header->msgh_voucher_port;
- header->msgh_voucher_port = MACH_VOUCHER_NULL;
+ m_voucher = std::exchange(header->msgh_voucher_port, MACH_VOUCHER_NULL);
header->msgh_bits &= ~(MACH_MSGH_BITS_VOUCHER_MASK | MACH_MSGH_BITS_RAISEIMP);
}
}
+ ImportanceAssertion(ImportanceAssertion&& other)
+ : m_voucher(std::exchange(other.m_voucher, MACH_VOUCHER_NULL))
+ {
+ }
+
+ ImportanceAssertion& operator=(ImportanceAssertion&& other)
+ {
+ if (&other != this)
+ std::swap(m_voucher, other.m_voucher);
+ return *this;
+ }
+
+ ImportanceAssertion(const ImportanceAssertion&) = delete;
+ ImportanceAssertion& operator=(const ImportanceAssertion&) = delete;
+
~ImportanceAssertion()
{
- if (m_voucher) {
- kern_return_t kr = mach_voucher_deallocate(m_voucher);
- ASSERT_UNUSED(kr, !kr);
- }
+ if (!m_voucher)
+ return;
+
+ kern_return_t kr = mach_voucher_deallocate(m_voucher);
+ ASSERT_UNUSED(kr, !kr);
+ m_voucher = MACH_VOUCHER_NULL;
}
private:
- mach_voucher_t m_voucher;
+ mach_voucher_t m_voucher { MACH_VOUCHER_NULL };
};
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes