Skip to content

Commit

Permalink
epoll-shim: new port in devel
Browse files Browse the repository at this point in the history
  • Loading branch information
barracuda156 committed Dec 2, 2024
1 parent 434debe commit 98df2d1
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 0 deletions.
47 changes: 47 additions & 0 deletions devel/epoll-shim/Portfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem 1.0
PortGroup cmake 1.1
PortGroup github 1.0
PortGroup legacysupport 1.1

# O_CLOEXEC
legacysupport.newest_darwin_requires_legacy 10

github.setup jiixyj epoll-shim 0.0.20240608 v
categories devel
license MIT
maintainers nomaintainer
description Small epoll implementation using kqueue
long_description ${description}. Includes all features \
needed for libinput/libevdev.

checksums rmd160 3cead7960ad43d9e03355753527024da0ceab0b5 \
sha256 8f5125217e4a0eeb96ab01f9dfd56c38f85ac3e8f26ef2578e538e72e87862cb \
size 104137
github.tarball_from archive

patch.pre_args-replace -p0 -p1

# https://github.com/jiixyj/epoll-shim/pull/57
patchfiles-append 0001-Use-EV_TRIGGER-as-a-fallback-for-NOTE_TRIGGER.patch \
0002-Define-MSG_NOSIGNAL-when-undefined.patch \
0003-timerfd-root-test-skip-on-macOS-10.12.patch

compiler.c_standard 2011

# Build tries to run test binaries during the build, which fails otherwise.
configure.pre_args-replace \
-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
-DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF

platform darwin powerpc {
depends_lib-append \
port:libdispatch-legacy
configure.cppflags-append \
-I${prefix}/libexec/dispatch/usr/include
configure.ldflags-append \
${prefix}/libexec/dispatch/usr/lib/libdispatch.a
}

test.run yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
From 9d6d02e25b415e971f968365c46b16f7bc689113 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Tue, 26 Nov 2024 23:10:54 +0800
Subject: [PATCH 1/3] Use EV_TRIGGER as a fallback for NOTE_TRIGGER

---
src/compat_ppoll.c | 7 ++++++-
src/epollfd_ctx.c | 13 +++++++++++--
src/kqueue_event.c | 13 +++++++++++--
3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/src/compat_ppoll.c b/src/compat_ppoll.c
index 44a579d..19b0c88 100644
--- a/src/compat_ppoll.c
+++ b/src/compat_ppoll.c
@@ -93,7 +93,7 @@ compat_ppoll_impl(struct pollfd fds[], nfds_t nfds,
goto out;
}

-#ifdef EVFILT_USER
+#if defined(EVFILT_USER) && (defined(NOTE_TRIGGER) || defined(EV_TRIGGER))
sigset_t pending;
if (sigpending(&pending) < 0) {
ec = errno;
@@ -103,8 +103,13 @@ compat_ppoll_impl(struct pollfd fds[], nfds_t nfds,
if (sigismember(&pending, (int)kevs[i].ident)) {
EV_SET(&kevs[0], 0, EVFILT_USER, /**/
EV_ADD | EV_ONESHOT, 0, 0, 0);
+#if defined(NOTE_TRIGGER)
EV_SET(&kevs[1], 0, EVFILT_USER, /**/
0, NOTE_TRIGGER, 0, 0);
+#elif defined(EV_TRIGGER)
+ EV_SET(&kevs[1], 0, EVFILT_USER, /**/
+ EV_TRIGGER, 0, 0, 0);
+#endif
if (kevent(kq, kevs, 2, NULL, 0, NULL) < 0) {
ec = errno;
goto out;
diff --git a/src/epollfd_ctx.c b/src/epollfd_ctx.c
index 0db5b01..08836a4 100644
--- a/src/epollfd_ctx.c
+++ b/src/epollfd_ctx.c
@@ -268,10 +268,15 @@ registered_fds_node_add_self_trigger(RegisteredFDsNode *fd2_node, int kq)
static void
registered_fds_node_trigger_self(RegisteredFDsNode *fd2_node, int kq)
{
-#ifdef EVFILT_USER
+#if defined(EVFILT_USER) && (defined(NOTE_TRIGGER) || defined(EV_TRIGGER))
struct kevent kevs[1];
+#if defined(NOTE_TRIGGER)
EV_SET(&kevs[0], (uintptr_t)fd2_node, EVFILT_USER, /**/
0, NOTE_TRIGGER, 0, fd2_node);
+#elif defined(EV_TRIGGER)
+ EV_SET(&kevs[0], (uintptr_t)fd2_node, EVFILT_USER, /**/
+ EV_TRIGGER, 0, 0, fd2_node);
+#endif
(void)kevent(kq, kevs, 1, NULL, 0, NULL);
#else
(void)kq;
@@ -792,10 +797,14 @@ epollfd_ctx__add_self_trigger(EpollFDCtx *epollfd, int kq)
static void
epollfd_ctx__trigger_self(EpollFDCtx *epollfd, int kq)
{
-#ifdef EVFILT_USER
+#if defined(EVFILT_USER) && (defined(NOTE_TRIGGER) || defined(EV_TRIGGER))
(void)epollfd;
struct kevent kevs[1];
+#if defined(NOTE_TRIGGER)
EV_SET(&kevs[0], 0, EVFILT_USER, 0, NOTE_TRIGGER, 0, 0);
+#elif defined(EV_TRIGGER)
+ EV_SET(&kevs[0], 0, EVFILT_USER, EV_TRIGGER, 0, 0, 0);
+#endif
(void)kevent(kq, kevs, 1, NULL, 0, NULL);
#else
assert(epollfd->self_pipe[0] >= 0);
diff --git a/src/kqueue_event.c b/src/kqueue_event.c
index e26816f..d06233e 100644
--- a/src/kqueue_event.c
+++ b/src/kqueue_event.c
@@ -16,13 +16,18 @@ kqueue_event_init(KQueueEvent *kqueue_event, struct kevent *kevs,
{
*kqueue_event = (KQueueEvent) { .self_pipe_ = { -1, -1 } };

-#ifdef EVFILT_USER
+#if defined(EVFILT_USER) && (defined(NOTE_TRIGGER) || defined(EV_TRIGGER))
EV_SET(&kevs[(*kevs_length)++], 0, /**/
EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, 0);

if (should_trigger) {
+#if defined(NOTE_TRIGGER)
EV_SET(&kevs[(*kevs_length)++], 0, /**/
EVFILT_USER, 0, NOTE_TRIGGER, 0, 0);
+#elif defined(EV_TRIGGER)
+ EV_SET(&kevs[(*kevs_length)++], 0, /**/
+ EVFILT_USER, EV_TRIGGER, 0, 0, 0);
+#endif
kqueue_event->is_triggered_ = true;
}

@@ -82,9 +87,13 @@ kqueue_event_trigger(KQueueEvent *kqueue_event, int kq)
return 0;
}

-#ifdef EVFILT_USER
+#if defined(EVFILT_USER) && (defined(NOTE_TRIGGER) || defined(EV_TRIGGER))
struct kevent kevs[1];
+#if defined(NOTE_TRIGGER)
EV_SET(&kevs[0], 0, EVFILT_USER, 0, NOTE_TRIGGER, 0, 0);
+#elif defined(EV_TRIGGER)
+ EV_SET(&kevs[0], 0, EVFILT_USER, EV_TRIGGER, 0, 0, 0);
+#endif

if (kevent(kq, kevs, 1, NULL, 0, NULL) < 0) {
return errno;
--
2.47.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 101ca2971aa2a7e1b12e64eca76f46e4e79e485b Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Tue, 26 Nov 2024 23:30:32 +0800
Subject: [PATCH 2/3] Define MSG_NOSIGNAL when undefined

---
test/epoll-test.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/test/epoll-test.c b/test/epoll-test.c
index f53ee97..64dfade 100644
--- a/test/epoll-test.c
+++ b/test/epoll-test.c
@@ -42,6 +42,11 @@
#define EPOLLRDHUP 0x2000
#endif

+/* macOS and Solaris do not have it */
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
static void
fd_pipe(int fds[3])
{
--
2.47.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From 182a55bfee38ab9d2804d86fd1e8bc43fcf08389 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <[email protected]>
Date: Wed, 27 Nov 2024 00:11:33 +0800
Subject: [PATCH 3/3] timerfd-root-test: skip on macOS < 10.12

---
test/CMakeLists.txt | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 2d04d2a..5f3c9f8 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -15,6 +15,14 @@ include(ATFTest)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

+if(APPLE)
+ exec_program(uname ARGS -v OUTPUT_VARIABLE DARWIN_VERSION)
+ string(REGEX MATCH "[0-9]+" DARWIN_VERSION ${DARWIN_VERSION})
+ if(DARWIN_VERSION LESS 16)
+ set(APPLE_LEGACY 1)
+ endif()
+endif()
+
#

macro(atf_test_impl _testname _suffix)
@@ -54,7 +62,9 @@ foreach(_target epoll-test epoll-test-interpose epoll-test-rdhup-linux-def)
endif()
endforeach()
atf_test(timerfd-test)
-atf_test(timerfd-root-test)
+if(NOT APPLE_LEGACY)
+ atf_test(timerfd-root-test)
+endif()
atf_test(timerfd-mock-test)
atf_test(signalfd-test)
atf_test(perf-many-fds)
--
2.47.1

0 comments on commit 98df2d1

Please sign in to comment.