WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-238596-20220331101909.patch (text/plain), 6.30 KB, created by
Zan Dobersek
on 2022-03-31 01:19:10 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Zan Dobersek
Created:
2022-03-31 01:19:10 PDT
Size:
6.30 KB
patch
obsolete
>Subversion Revision: 292141 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 4a728f0c6c2246322825705b6baa2a9b7672dff2..d60a4d5ddf1e95eaf20f1fb3ce63da246752cb7a 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,40 @@ >+2022-03-31 Zan Dobersek <zdobersek@igalia.com> >+ >+ [Linux] Implement IPC::Semaphore >+ https://bugs.webkit.org/show_bug.cgi?id=238596 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Provide a Linux implementation for IPC::Semaphore that's based on >+ eventfd mechanics. >+ >+ The IPC::Semaphore class now has a UNIX-specific file descriptor member >+ variable. For Linux, this file descriptor is an eventfd with semaphore >+ semantics (eventfd being Linux-specific). Signalling and waiting on >+ such semaphore is done through the read() and write() functions. >+ Non-Linux platforms are expected to provide something equivalent, if >+ possible. >+ >+ For encoding and decoding that's necessary to move these semaphores >+ across process boundaries, IPC::Attachment is used. For encoding the >+ eventfd is simply duplicated and pushed into the Attachment, and for >+ decoding the Attachment's file descriptor is taken and adopted by the >+ Semaphore object. >+ >+ * Platform/IPC/IPCSemaphore.h: >+ (IPC::Semaphore::operator bool const): >+ * Platform/IPC/unix/IPCSemaphoreUnix.cpp: >+ (IPC::Semaphore::Semaphore): >+ (IPC::Semaphore::~Semaphore): >+ (IPC::Semaphore::operator=): >+ (IPC::Semaphore::signal): >+ (IPC::waitImpl): >+ (IPC::Semaphore::wait): >+ (IPC::Semaphore::waitFor): >+ (IPC::Semaphore::encode const): >+ (IPC::Semaphore::decode): >+ (IPC::Semaphore::destroy): >+ > 2022-03-30 Sihui Liu <sihui_liu@apple.com> > > Regression: WebsiteDataStore fails to read experimental feature values from NSUserDefaults >diff --git a/Source/WebKit/Platform/IPC/IPCSemaphore.h b/Source/WebKit/Platform/IPC/IPCSemaphore.h >index 0c45c44d21a52641e28d184999305364464ae597..2d377ec6848a7353ae785b8c08976c38e8abba5a 100644 >--- a/Source/WebKit/Platform/IPC/IPCSemaphore.h >+++ b/Source/WebKit/Platform/IPC/IPCSemaphore.h >@@ -64,6 +64,10 @@ public: > explicit operator bool() const { return m_sendRight || m_semaphore != SEMAPHORE_NULL; } > #elif OS(WINDOWS) > explicit Semaphore(HANDLE); >+#elif USE(UNIX_DOMAIN_SOCKETS) >+ explicit Semaphore(int fd); >+ >+ explicit operator bool() const { return m_fd != -1; } > #else > explicit operator bool() const { return true; } > #endif >@@ -75,6 +79,8 @@ private: > semaphore_t m_semaphore { SEMAPHORE_NULL }; > #elif OS(WINDOWS) > HANDLE m_semaphoreHandle { nullptr }; >+#elif USE(UNIX_DOMAIN_SOCKETS) >+ int m_fd { -1 }; > #endif > }; > >diff --git a/Source/WebKit/Platform/IPC/unix/IPCSemaphoreUnix.cpp b/Source/WebKit/Platform/IPC/unix/IPCSemaphoreUnix.cpp >index 3a88ffc2df99deebd124243f90775f797cec1df3..8a00b37c0fefa1a111b5c1adb29743616620e7be 100644 >--- a/Source/WebKit/Platform/IPC/unix/IPCSemaphoreUnix.cpp >+++ b/Source/WebKit/Platform/IPC/unix/IPCSemaphoreUnix.cpp >@@ -26,47 +26,138 @@ > #include "config.h" > #include "IPCSemaphore.h" > >+#include <wtf/UniStdExtras.h> >+ >+#if OS(LINUX) >+#include <sys/eventfd.h> >+#endif >+ > namespace IPC { > > Semaphore::Semaphore() > { >- ASSERT_NOT_REACHED(); >+#if OS(LINUX) >+ m_fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK | EFD_SEMAPHORE); >+#endif >+} >+ >+Semaphore::Semaphore(int fd) >+ : m_fd(fd) >+{ } >+ >+Semaphore::Semaphore(Semaphore&& o) >+{ >+ m_fd = o.m_fd; >+ o.m_fd = -1; > } > >-Semaphore::Semaphore(Semaphore&&) >+Semaphore::~Semaphore() > { >- ASSERT_NOT_REACHED(); >+ destroy(); > } > >-Semaphore::~Semaphore() = default; >+Semaphore& Semaphore::operator=(Semaphore&& o) >+{ >+ if (&o == this) >+ return *this; > >-Semaphore& Semaphore::operator=(Semaphore&&) = default; >+ destroy(); >+ m_fd = o.m_fd; >+ o.m_fd = -1; >+ return *this; >+} > > void Semaphore::signal() > { >+ if (m_fd == -1) >+ return; >+ >+#if OS(LINUX) >+ // Matching waitImpl() and EFD_SEMAPHORE semantics, increment the semaphore value by 1. >+ uint64_t value = 1; >+ while (true) { >+ int ret = write(m_fd, &value, sizeof(uint64_t)); >+ if (LIKELY(ret != -1 || errno != EINTR)) >+ break; >+ } >+#endif > } > >+#if OS(LINUX) >+static bool waitImpl(int fd, int timeout) >+{ >+ struct pollfd pollfdValue { .fd = fd, .events = POLLIN, .revents = 0 }; >+ int ret = 0; >+ >+ // Iterate on polling while interrupts are thrown, otherwise bail out of the loop immediately. >+ while (true) { >+ ret = poll(&pollfdValue, 1, timeout); >+ if (LIKELY(ret != -1 || errno != EINTR)) >+ break; >+ } >+ >+ // Fail if the return value doesn't indicate the single file descriptor with only input events available. >+ if (ret != 1 || !!(pollfdValue.revents ^ POLLIN)) >+ return false; >+ >+ // There should be data for reading -- due to EFD_SEMAPHORE, it should be 1 packed into an 8-byte value. >+ uint64_t value = 0; >+ ret = read(fd, &value, sizeof(uint64_t)); >+ if (ret != sizeof(uint64_t) || value != 1) >+ return false; >+ >+ return true; >+} >+#endif >+ > bool Semaphore::wait() > { >+ if (m_fd == -1) >+ return false; >+ >+#if OS(LINUX) >+ return waitImpl(m_fd, -1); >+#else > return false; >+#endif > } > >-bool Semaphore::waitFor(Timeout) >+bool Semaphore::waitFor(Timeout timeout) > { >+ if (m_fd == -1) >+ return false; >+ >+#if OS(LINUX) >+ int timeoutValue = -1; >+ if (!timeout.isInfinity()) >+ timeoutValue = int(timeout.secondsUntilDeadline().milliseconds()); >+ return waitImpl(m_fd, timeoutValue); >+#else > return false; >+#endif > } > >-void Semaphore::encode(Encoder&) const >+void Semaphore::encode(Encoder& encoder) const > { >+ int duplicate = -1; >+ if (m_fd != -1) >+ duplicate = dupCloseOnExec(m_fd); >+ >+ encoder.addAttachment(Attachment(duplicate)); > } > >-std::optional<Semaphore> Semaphore::decode(Decoder&) >+std::optional<Semaphore> Semaphore::decode(Decoder& decoder) > { >- return Semaphore { }; >+ auto attachment = decoder.takeLastAttachment(); >+ if (!attachment) >+ return std::nullopt; >+ return std::optional<Semaphore> { std::in_place, attachment->releaseFileDescriptor() }; > } > > void Semaphore::destroy() > { >+ if (m_fd != -1) >+ closeWithRetry(m_fd); > } > > } // namespace IPC
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 238596
:
456214
|
456346