Index: head/graphics/wayland/Makefile =================================================================== --- head/graphics/wayland/Makefile (revision 526102) +++ head/graphics/wayland/Makefile (revision 526103) @@ -1,29 +1,29 @@ # Created by: kwm@FreeBSD.org # $FreeBSD$ PORTNAME= wayland -PORTVERSION= 1.17.0 +PORTVERSION= 1.18.0 CATEGORIES= graphics wayland MASTER_SITES= https://wayland.freedesktop.org/releases/ MAINTAINER= x11@FreeBSD.org COMMENT= Wayland composite "server" LICENSE= MIT LICENSE_FILE= ${WRKSRC}/COPYING LIB_DEPENDS= libexpat.so:textproc/expat2 \ libffi.so:devel/libffi \ libepoll-shim.so:devel/libepoll-shim CFLAGS+= "-I${LOCALBASE}/include/libepoll-shim" USES= autoreconf gmake gnome libtool localbase pathfix pkgconfig tar:xz USE_GNOME= libxslt:build USE_LDCONFIG= yes GNU_CONFIGURE= yes CONFIGURE_ARGS= --disable-documentation -CONFIGURE_ENV= ac_cv_func_posix_fallocate=no # EINVAL for many FS on 12.0 +CONFIGURE_ENV= ac_cv_func_posix_fallocate=no # EINVAL on ZFS since FreeBSD 12.0 INSTALL_TARGET= install-strip .include Index: head/graphics/wayland/distinfo =================================================================== --- head/graphics/wayland/distinfo (revision 526102) +++ head/graphics/wayland/distinfo (revision 526103) @@ -1,3 +1,3 @@ -TIMESTAMP = 1553129725 -SHA256 (wayland-1.17.0.tar.xz) = 72aa11b8ac6e22f4777302c9251e8fec7655dc22f9d94ee676c6b276f95f91a4 -SIZE (wayland-1.17.0.tar.xz) = 437680 +TIMESTAMP = 1581464763 +SHA256 (wayland-1.18.0.tar.xz) = 4675a79f091020817a98fd0484e7208c8762242266967f55a67776936c2e294d +SIZE (wayland-1.18.0.tar.xz) = 453968 Index: head/graphics/wayland/files/patch-Makefile.am =================================================================== --- head/graphics/wayland/files/patch-Makefile.am (revision 526102) +++ head/graphics/wayland/files/patch-Makefile.am (revision 526103) @@ -1,29 +1,29 @@ ---- Makefile.am.orig 2019-03-21 00:55:25 UTC +--- Makefile.am.orig 2020-02-11 23:46:03 UTC +++ Makefile.am -@@ -71,7 +71,7 @@ nodist_include_HEADERS = \ +@@ -73,7 +73,7 @@ nodist_include_HEADERS = \ protocol/wayland-client-protocol.h libwayland_server_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread --libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la libwayland-util.la -lrt -lm -+libwayland_server_la_LIBADD = $(FFI_LIBS) $(EPOLLSHIM_LIBS) libwayland-private.la libwayland-util.la -lrt -lm +-libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la libwayland-util.la $(RT_LIBS) -lm ++libwayland_server_la_LIBADD = $(FFI_LIBS) $(EPOLLSHIM_LIBS) libwayland-private.la libwayland-util.la $(RT_LIBS) -lm libwayland_server_la_LDFLAGS = -version-info 1:0:1 libwayland_server_la_SOURCES = \ src/wayland-server.c \ -@@ -83,7 +83,7 @@ nodist_libwayland_server_la_SOURCES = \ +@@ -85,7 +85,7 @@ nodist_libwayland_server_la_SOURCES = \ protocol/wayland-protocol.c libwayland_client_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread --libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la libwayland-util.la -lrt -lm -+libwayland_client_la_LIBADD = $(FFI_LIBS) $(EPOLLSHIM_LIBS) libwayland-private.la libwayland-util.la -lrt -lm +-libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la libwayland-util.la $(RT_LIBS) -lm ++libwayland_client_la_LIBADD = $(FFI_LIBS) $(EPOLLSHIM_LIBS) libwayland-private.la libwayland-util.la $(RT_LIBS) -lm libwayland_client_la_LDFLAGS = -version-info 3:0:3 libwayland_client_la_SOURCES = \ src/wayland-client.c -@@ -227,7 +227,7 @@ libtest_runner_la_LIBADD = \ +@@ -230,7 +230,7 @@ libtest_runner_la_LIBADD = \ libwayland-client.la \ libwayland-server.la \ libtest-helpers.la \ -- -lrt -ldl $(FFI_LIBS) -+ -lrt $(DL_LIBS) $(FFI_LIBS) $(EPOLLSHIM_LIBS) +- $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS) ++ $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS) $(EPOLLSHIM_LIBS) array_test_SOURCES = tests/array-test.c array_test_LDADD = libtest-runner.la Index: head/graphics/wayland/files/patch-configure.ac =================================================================== --- head/graphics/wayland/files/patch-configure.ac (revision 526102) +++ head/graphics/wayland/files/patch-configure.ac (revision 526103) @@ -1,51 +1,51 @@ ---- configure.ac.orig 2018-08-24 18:04:36 UTC +--- configure.ac.orig 2020-02-11 23:46:03 UTC +++ configure.ac -@@ -65,6 +65,25 @@ AC_SUBST(GCC_CFLAGS) - AC_CHECK_HEADERS([sys/prctl.h]) - AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) +@@ -71,6 +71,25 @@ WESTON_SEARCH_LIBS([DL], [dl], [dlsym]) + # OpenBSD doesn't have librt, but it has its functions in libc + WESTON_SEARCH_LIBS([RT], [rt], [clock_gettime]) +AC_CHECK_HEADERS([sys/signalfd.h sys/timerfd.h]) + +# Use epoll on Linux and epoll-shim (kqueue) on BSD +AC_CHECK_HEADERS([sys/epoll.h]) + +# Credential support on FreeBSD +AC_CHECK_HEADERS([sys/ucred.h]) + +# dlopen() +AC_CHECK_LIB([dl], [dlsym], [DL_LIBS=-ldl]) +AC_SUBST([DL_LIBS]) + +# Defines __FreeBSD__ if we're on FreeBSD +AC_CHECK_HEADERS([sys/param.h]) + +# waitid() and signal.h are needed for the test suite. +AC_CHECK_FUNCS([waitid]) +AC_CHECK_HEADERS([signal.h]) + AC_ARG_ENABLE([libraries], [AC_HELP_STRING([--disable-libraries], [Disable compilation of wayland libraries])], -@@ -100,16 +119,20 @@ AC_SUBST([ICONDIR]) +@@ -106,16 +125,20 @@ AC_SUBST([ICONDIR]) if test "x$enable_libraries" = "xyes"; then PKG_CHECK_MODULES(FFI, [libffi]) +dnl convert SFD_CLOEXEC and TFD_CLOEXEC to warning while figuring out how to do this. AC_CHECK_DECL(SFD_CLOEXEC,[], - [AC_MSG_ERROR("SFD_CLOEXEC is needed to compile wayland libraries")], + [AC_MSG_WARN("SFD_CLOEXEC is needed to compile wayland libraries")], [[#include ]]) AC_CHECK_DECL(TFD_CLOEXEC,[], - [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile wayland libraries")], + [AC_MSG_WARN("TFD_CLOEXEC is needed to compile wayland libraries")], [[#include ]]) AC_CHECK_DECL(CLOCK_MONOTONIC,[], [AC_MSG_ERROR("CLOCK_MONOTONIC is needed to compile wayland libraries")], [[#include ]]) fi + +EPOLLSHIM_LIBS="-lepoll-shim" +AC_SUBST(EPOLLSHIM_LIBS) PKG_CHECK_MODULES(EXPAT, [expat]) Index: head/graphics/wayland/files/patch-cursor_os-compatibility.c =================================================================== --- head/graphics/wayland/files/patch-cursor_os-compatibility.c (revision 526102) +++ head/graphics/wayland/files/patch-cursor_os-compatibility.c (revision 526103) @@ -1,60 +1,21 @@ ---- cursor/os-compatibility.c.orig 2019-03-21 00:55:25 UTC +--- cursor/os-compatibility.c.orig 2020-02-11 23:46:03 UTC +++ cursor/os-compatibility.c -@@ -23,6 +23,10 @@ - * SOFTWARE. - */ +@@ -34,7 +34,7 @@ + #include + #include -+#ifdef __FreeBSD__ -+#include -+#endif -+ - #define _GNU_SOURCE - - #include -@@ -59,6 +63,7 @@ err: - } +-#ifdef HAVE_MEMFD_CREATE ++#if defined(HAVE_MEMFD_CREATE) || defined(__FreeBSD__) + #include #endif -+#ifndef __FreeBSD__ - static int - create_tmpfile_cloexec(char *tmpname) - { -@@ -78,6 +83,7 @@ create_tmpfile_cloexec(char *tmpname) - - return fd; - } -+#endif - - /* - * Create a new, unique, anonymous file of the given size, and -@@ -103,11 +109,14 @@ create_tmpfile_cloexec(char *tmpname) - int - os_create_anonymous_file(off_t size) - { -+ int fd; -+ int ret; -+#ifdef __FreeBSD__ +@@ -132,6 +132,9 @@ os_create_anonymous_file(off_t size) + */ + fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL); + } else ++#elif defined(__FreeBSD__) + fd = shm_open(SHM_ANON, O_CREAT | O_RDWR | O_CLOEXEC, 0600); // shm_open is always CLOEXEC -+#else - static const char template[] = "/wayland-cursor-shared-XXXXXX"; - const char *path; - char *name; -- int fd; -- int ret; - - path = getenv("XDG_RUNTIME_DIR"); - if (!path) { -@@ -125,11 +134,12 @@ os_create_anonymous_file(off_t size) - fd = create_tmpfile_cloexec(name); - - free(name); -+#endif /* __FreeBSD__ */ - - if (fd < 0) - return -1; - --#ifdef HAVE_POSIX_FALLOCATE -+#if defined(HAVE_POSIX_FALLOCATE) && !defined(__FreeBSD__) - ret = posix_fallocate(fd, 0, size); - if (ret != 0) { - close(fd); ++ if (fd < 0) + #endif + { + path = getenv("XDG_RUNTIME_DIR"); Index: head/graphics/wayland/files/patch-src_event-loop.c =================================================================== --- head/graphics/wayland/files/patch-src_event-loop.c (nonexistent) +++ head/graphics/wayland/files/patch-src_event-loop.c (revision 526103) @@ -0,0 +1,562 @@ +Temporarily revert https://gitlab.freedesktop.org/wayland/wayland/commit/60a8d29ad852 +until https://github.com/jiixyj/epoll-shim/issues/15 is fixed + +--- src/event-loop.c.orig 2020-02-11 23:46:03 UTC ++++ src/event-loop.c +@@ -23,7 +23,6 @@ + * SOFTWARE. + */ + +-#include + #include + #include + #include +@@ -46,27 +45,6 @@ + + /** \cond INTERNAL */ + +-#define TIMER_REMOVED -2 +- +-struct wl_event_loop; +-struct wl_event_source_interface; +-struct wl_event_source_timer; +- +-struct wl_event_source { +- struct wl_event_source_interface *interface; +- struct wl_event_loop *loop; +- struct wl_list link; +- void *data; +- int fd; +-}; +- +-struct wl_timer_heap { +- struct wl_event_source base; +- /* pointers to the user-visible event sources */ +- struct wl_event_source_timer **data; +- int space, active, count; +-}; +- + struct wl_event_loop { + int epoll_fd; + struct wl_list check_list; +@@ -74,8 +52,6 @@ struct wl_event_loop { + struct wl_list destroy_list; + + struct wl_signal destroy_signal; +- +- struct wl_timer_heap timers; + }; + + struct wl_event_source_interface { +@@ -83,6 +59,13 @@ struct wl_event_source_interface { + struct epoll_event *ep); + }; + ++struct wl_event_source { ++ struct wl_event_source_interface *interface; ++ struct wl_event_loop *loop; ++ struct wl_list link; ++ void *data; ++ int fd; ++}; + + struct wl_event_source_fd { + struct wl_event_source base; +@@ -232,319 +215,31 @@ wl_event_source_fd_update(struct wl_event_source *sour + struct wl_event_source_timer { + struct wl_event_source base; + wl_event_loop_timer_func_t func; +- struct wl_event_source_timer *next_due; +- struct timespec deadline; +- int heap_idx; + }; + +-static int +-noop_dispatch(struct wl_event_source *source, +- struct epoll_event *ep) { +- return 0; +-} ++/** \endcond */ + +-struct wl_event_source_interface timer_heap_source_interface = { +- noop_dispatch, +-}; +- +-static bool +-time_lt(struct timespec ta, struct timespec tb) +-{ +- if (ta.tv_sec != tb.tv_sec) { +- return ta.tv_sec < tb.tv_sec; +- } +- return ta.tv_nsec < tb.tv_nsec; +-} +- + static int +-set_timer(int timerfd, struct timespec deadline) { +- struct itimerspec its; +- +- its.it_interval.tv_sec = 0; +- its.it_interval.tv_nsec = 0; +- its.it_value = deadline; +- return timerfd_settime(timerfd, TFD_TIMER_ABSTIME, &its, NULL); +-} +- +-static int +-clear_timer(int timerfd) +-{ +- struct itimerspec its; +- +- its.it_interval.tv_sec = 0; +- its.it_interval.tv_nsec = 0; +- its.it_value.tv_sec = 0; +- its.it_value.tv_nsec = 0; +- return timerfd_settime(timerfd, 0, &its, NULL); +-} +- +-static void +-wl_timer_heap_init(struct wl_timer_heap *timers, struct wl_event_loop *loop) +-{ +- timers->base.fd = -1; +- timers->base.data = NULL; +- wl_list_init(&timers->base.link); +- timers->base.interface = &timer_heap_source_interface; +- timers->base.loop = loop; +- +- loop->timers.data = NULL; +- loop->timers.active = 0; +- loop->timers.space = 0; +- loop->timers.count = 0; +-} +- +-static void +-wl_timer_heap_release(struct wl_timer_heap *timers) +-{ +- if (timers->base.fd != -1) { +- close(timers->base.fd); +- } +- free(timers->data); +-} +- +-static int +-wl_timer_heap_ensure_timerfd(struct wl_timer_heap *timers) +-{ +- struct epoll_event ep; +- int timer_fd; +- +- if (timers->base.fd != -1) +- return 0; +- +- memset(&ep, 0, sizeof ep); +- ep.events = EPOLLIN; +- ep.data.ptr = timers; +- +- timer_fd = timerfd_create(CLOCK_MONOTONIC, +- TFD_CLOEXEC | TFD_NONBLOCK); +- if (timer_fd < 0) +- return -1; +- +- if (epoll_ctl(timers->base.loop->epoll_fd, +- EPOLL_CTL_ADD, timer_fd, &ep) < 0) { +- close(timer_fd); +- return -1; +- } +- +- timers->base.fd = timer_fd; +- return 0; +-} +- +-static int +-wl_timer_heap_reserve(struct wl_timer_heap *timers) +-{ +- struct wl_event_source_timer **n; +- int new_space; +- +- if (timers->count + 1 > timers->space) { +- new_space = timers->space >= 8 ? timers->space * 2 : 8; +- n = realloc(timers->data, (size_t)new_space * sizeof(*n)); +- if (!n) { +- wl_log("Allocation failure when expanding timer list"); +- return -1; +- } +- timers->data = n; +- timers->space = new_space; +- } +- +- timers->count++; +- return 0; +-} +- +-static void +-wl_timer_heap_unreserve(struct wl_timer_heap *timers) +-{ +- struct wl_event_source_timer **n; +- +- timers->count--; +- +- if (timers->space >= 16 && timers->space >= 4 * timers->count) { +- n = realloc(timers->data, (size_t)timers->space / 2 * sizeof(*n)); +- if (!n) { +- wl_log("Reallocation failure when shrinking timer list"); +- return; +- } +- timers->data = n; +- timers->space = timers->space / 2; +- } +-} +- +-static int +-heap_set(struct wl_event_source_timer **data, +- struct wl_event_source_timer *a, +- int idx) +-{ +- int tmp; +- +- tmp = a->heap_idx; +- a->heap_idx = idx; +- data[a->heap_idx] = a; +- +- return tmp; +-} +- +-static void +-heap_sift_down(struct wl_event_source_timer **data, +- int num_active, +- struct wl_event_source_timer *source) +-{ +- struct wl_event_source_timer *child, *other_child; +- int cursor_idx; +- struct timespec key; +- +- cursor_idx = source->heap_idx; +- key = source->deadline; +- while (1) { +- int lchild_idx = cursor_idx * 2 + 1; +- +- if (lchild_idx >= num_active) { +- break; +- } +- +- child = data[lchild_idx]; +- if (lchild_idx + 1 < num_active) { +- other_child = data[lchild_idx + 1]; +- if (time_lt(other_child->deadline, child->deadline)) +- child = other_child; +- } +- +- if (time_lt(child->deadline, key)) +- cursor_idx = heap_set(data, child, cursor_idx); +- else +- break; +- } +- +- heap_set(data, source, cursor_idx); +-} +- +-static void +-heap_sift_up(struct wl_event_source_timer **data, +- struct wl_event_source_timer *source) +-{ +- int cursor_idx; +- struct timespec key; +- +- cursor_idx = source->heap_idx; +- key = source->deadline; +- while (cursor_idx > 0) { +- struct wl_event_source_timer *parent = +- data[(cursor_idx - 1) / 2]; +- +- if (time_lt(key, parent->deadline)) +- cursor_idx = heap_set(data, parent, cursor_idx); +- else +- break; +- } +- heap_set(data, source, cursor_idx); +-} +- +-/* requires timer be armed */ +-static void +-wl_timer_heap_disarm(struct wl_timer_heap *timers, +- struct wl_event_source_timer *source) +-{ +- struct wl_event_source_timer *last_end_evt; +- int old_source_idx; +- +- assert(source->heap_idx >= 0); +- +- old_source_idx = source->heap_idx; +- source->heap_idx = -1; +- source->deadline.tv_sec = 0; +- source->deadline.tv_nsec = 0; +- +- last_end_evt = timers->data[timers->active - 1]; +- timers->data[timers->active - 1] = NULL; +- timers->active--; +- +- if (old_source_idx == timers->active) +- return; +- +- timers->data[old_source_idx] = last_end_evt; +- last_end_evt->heap_idx = old_source_idx; +- +- /* Move the displaced (active) element to its proper place. +- * Only one of sift-down and sift-up will have any effect */ +- heap_sift_down(timers->data, timers->active, last_end_evt); +- heap_sift_up(timers->data, last_end_evt); +-} +- +-/* requires timer be disarmed */ +-static void +-wl_timer_heap_arm(struct wl_timer_heap *timers, +- struct wl_event_source_timer *source, +- struct timespec deadline) +-{ +- assert(source->heap_idx == -1); +- +- source->deadline = deadline; +- timers->data[timers->active] = source; +- source->heap_idx = timers->active; +- timers->active++; +- heap_sift_up(timers->data, source); +-} +- +- +-static int +-wl_timer_heap_dispatch(struct wl_timer_heap *timers) +-{ +- struct timespec now; +- struct wl_event_source_timer *root; +- struct wl_event_source_timer *list_cursor = NULL, *list_tail = NULL; +- +- clock_gettime(CLOCK_MONOTONIC, &now); +- +- while (timers->active > 0) { +- root = timers->data[0]; +- if (time_lt(now, root->deadline)) +- break; +- +- wl_timer_heap_disarm(timers, root); +- +- if (list_cursor == NULL) +- list_cursor = root; +- else +- list_tail->next_due = root; +- list_tail = root; +- } +- if (list_tail) +- list_tail->next_due = NULL; +- +- if (timers->active > 0) { +- if (set_timer(timers->base.fd, timers->data[0]->deadline) < 0) +- return -1; +- } else { +- if (clear_timer(timers->base.fd) < 0) +- return -1; +- } +- +- /* Execute precisely the functions for events before `now`, in order. +- * Because wl_event_loop_dispatch ignores return codes, do the same +- * here as well */ +- for (; list_cursor; list_cursor = list_cursor->next_due) { +- if (list_cursor->base.fd != TIMER_REMOVED) +- list_cursor->func(list_cursor->base.data); +- } +- +- return 0; +-} +- +-static int + wl_event_source_timer_dispatch(struct wl_event_source *source, + struct epoll_event *ep) + { +- struct wl_event_source_timer *timer; ++ struct wl_event_source_timer *timer_source = ++ (struct wl_event_source_timer *) source; ++ uint64_t expires; ++ int len; + +- timer = wl_container_of(source, timer, base); +- return timer->func(timer->base.data); ++ len = read(source->fd, &expires, sizeof expires); ++ if (!(len == -1 && errno == EAGAIN) && len != sizeof expires) ++ /* Is there anything we can do here? Will this ever happen? */ ++ wl_log("timerfd read error: %s\n", strerror(errno)); ++ ++ return timer_source->func(timer_source->base.data); + } + + struct wl_event_source_interface timer_source_interface = { + wl_event_source_timer_dispatch, + }; + +-/** \endcond */ +- + /** Create a timer event source + * + * \param loop The event loop that will process the new source. +@@ -565,30 +260,16 @@ wl_event_loop_add_timer(struct wl_event_loop *loop, + { + struct wl_event_source_timer *source; + +- if (wl_timer_heap_ensure_timerfd(&loop->timers) < 0) +- return NULL; +- + source = malloc(sizeof *source); + if (source == NULL) + return NULL; + + source->base.interface = &timer_source_interface; +- source->base.fd = -1; ++ source->base.fd = timerfd_create(CLOCK_MONOTONIC, ++ TFD_CLOEXEC | TFD_NONBLOCK); + source->func = func; +- source->base.loop = loop; +- source->base.data = data; +- wl_list_init(&source->base.link); +- source->next_due = NULL; +- source->deadline.tv_sec = 0; +- source->deadline.tv_nsec = 0; +- source->heap_idx = -1; + +- if (wl_timer_heap_reserve(&loop->timers) < 0) { +- free(source); +- return NULL; +- } +- +- return &source->base; ++ return add_source(loop, &source->base, WL_EVENT_READABLE, data); + } + + /** Arm or disarm a timer +@@ -610,51 +291,15 @@ wl_event_loop_add_timer(struct wl_event_loop *loop, + WL_EXPORT int + wl_event_source_timer_update(struct wl_event_source *source, int ms_delay) + { +- struct wl_event_source_timer *tsource = +- wl_container_of(source, tsource, base); +- struct wl_timer_heap *timers = &tsource->base.loop->timers; ++ struct itimerspec its; + +- if (ms_delay > 0) { +- struct timespec deadline; ++ its.it_interval.tv_sec = 0; ++ its.it_interval.tv_nsec = 0; ++ its.it_value.tv_sec = ms_delay / 1000; ++ its.it_value.tv_nsec = (ms_delay % 1000) * 1000 * 1000; ++ if (timerfd_settime(source->fd, 0, &its, NULL) < 0) ++ return -1; + +- clock_gettime(CLOCK_MONOTONIC, &deadline); +- +- deadline.tv_nsec += (ms_delay % 1000) * 1000000L; +- deadline.tv_sec += ms_delay / 1000; +- if (deadline.tv_nsec >= 1000000000L) { +- deadline.tv_nsec -= 1000000000L; +- deadline.tv_sec += 1; +- } +- +- if (tsource->heap_idx == -1) { +- wl_timer_heap_arm(timers, tsource, deadline); +- } else if (time_lt(deadline, tsource->deadline)) { +- tsource->deadline = deadline; +- heap_sift_up(timers->data, tsource); +- } else { +- tsource->deadline = deadline; +- heap_sift_down(timers->data, timers->active, tsource); +- } +- +- if (tsource->heap_idx == 0) { +- /* Only update the timerfd if the new deadline is +- * the earliest */ +- if (set_timer(timers->base.fd, deadline) < 0) +- return -1; +- } +- } else { +- if (tsource->heap_idx == -1) +- return 0; +- wl_timer_heap_disarm(timers, tsource); +- +- if (timers->active == 0) { +- /* Only update the timerfd if this was the last +- * active timer */ +- if (clear_timer(timers->base.fd) < 0) +- return -1; +- } +- } +- + return 0; + } + +@@ -838,17 +483,6 @@ wl_event_source_remove(struct wl_event_source *source) + source->fd = -1; + } + +- if (source->interface == &timer_source_interface && +- source->fd != TIMER_REMOVED) { +- /* Disarm the timer (and the loop's timerfd, if necessary), +- * before removing its space in the loop timer heap */ +- wl_event_source_timer_update(source, 0); +- wl_timer_heap_unreserve(&loop->timers); +- /* Set the fd field to to indicate that the timer should NOT +- * be dispatched in `wl_event_loop_dispatch` */ +- source->fd = TIMER_REMOVED; +- } +- + wl_list_remove(&source->link); + wl_list_insert(&loop->destroy_list, &source->link); + +@@ -900,8 +534,6 @@ wl_event_loop_create(void) + + wl_signal_init(&loop->destroy_signal); + +- wl_timer_heap_init(&loop->timers, loop); +- + return loop; + } + +@@ -924,7 +556,6 @@ wl_event_loop_destroy(struct wl_event_loop *loop) + wl_signal_emit(&loop->destroy_signal, loop); + + wl_event_loop_process_destroy_list(loop); +- wl_timer_heap_release(&loop->timers); + close(loop->epoll_fd); + free(loop); + } +@@ -975,7 +606,7 @@ wl_event_loop_dispatch_idle(struct wl_event_loop *loop + * + * \param loop The event loop whose sources to wait for. + * \param timeout The polling timeout in milliseconds. +- * \return 0 for success, -1 for polling (or timer update) error. ++ * \return 0 for success, -1 for polling error. + * + * All the associated event sources are polled. This function blocks until + * any event source delivers an event (idle sources excluded), or the timeout +@@ -997,29 +628,12 @@ wl_event_loop_dispatch(struct wl_event_loop *loop, int + struct epoll_event ep[32]; + struct wl_event_source *source; + int i, count; +- bool has_timers = false; + + wl_event_loop_dispatch_idle(loop); + + count = epoll_wait(loop->epoll_fd, ep, ARRAY_LENGTH(ep), timeout); + if (count < 0) + return -1; +- +- for (i = 0; i < count; i++) { +- source = ep[i].data.ptr; +- if (source == &loop->timers.base) +- has_timers = true; +- } +- +- if (has_timers) { +- /* Dispatch timer sources before non-timer sources, so that +- * the non-timer sources can not cancel (by calling +- * `wl_event_source_timer_update`) the dispatching of the timers +- * (Note that timer sources also can't cancel pending non-timer +- * sources, since epoll_wait has already been called) */ +- if (wl_timer_heap_dispatch(&loop->timers) < 0) +- return -1; +- } + + for (i = 0; i < count; i++) { + source = ep[i].data.ptr; Property changes on: head/graphics/wayland/files/patch-src_event-loop.c ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/graphics/wayland/files/patch-src_wayland-server.c =================================================================== --- head/graphics/wayland/files/patch-src_wayland-server.c (revision 526102) +++ head/graphics/wayland/files/patch-src_wayland-server.c (revision 526103) @@ -1,96 +1,96 @@ ---- src/wayland-server.c.orig 2018-04-09 17:19:26 UTC +--- src/wayland-server.c.orig 2020-02-11 23:46:03 UTC +++ src/wayland-server.c @@ -25,6 +25,8 @@ #define _GNU_SOURCE +#include "../config.h" + + #include #include #include - #include -@@ -43,6 +45,11 @@ +@@ -44,6 +46,11 @@ #include #include +#ifdef HAVE_SYS_UCRED_H +#include +#include +#endif + #include "wayland-util.h" #include "wayland-private.h" - #include "wayland-server.h" -@@ -77,7 +84,13 @@ struct wl_client { + #include "wayland-server-private.h" +@@ -79,7 +86,13 @@ struct wl_client { struct wl_list link; struct wl_map objects; struct wl_priv_signal destroy_signal; +#ifdef HAVE_SYS_UCRED_H + /* FreeBSD */ + struct xucred xucred; +#else + /* Linux */ struct ucred ucred; +#endif int error; struct wl_priv_signal resource_created_signal; }; -@@ -303,7 +316,13 @@ wl_resource_post_error(struct wl_resource *resource, +@@ -315,7 +328,13 @@ wl_resource_post_error(struct wl_resource *resource, static void destroy_client_with_error(struct wl_client *client, const char *reason) { +#ifdef HAVE_SYS_UCRED_H + /* FreeBSD */ + wl_log("%s\n", reason); +#else + /* Linux */ wl_log("%s (pid %u)\n", reason, client->ucred.pid); +#endif wl_client_destroy(client); } -@@ -517,10 +536,20 @@ wl_client_create(struct wl_display *display, int fd) +@@ -529,10 +548,20 @@ wl_client_create(struct wl_display *display, int fd) if (!client->source) goto err_client; +#if defined(SO_PEERCRED) + /* Linux */ len = sizeof client->ucred; if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &client->ucred, &len) < 0) goto err_source; +#elif defined(LOCAL_PEERCRED) + /* FreeBSD */ + len = sizeof client->xucred; + if (getsockopt(fd, SOL_SOCKET, LOCAL_PEERCRED, + &client->xucred, &len) < 0 || + client->xucred.cr_version != XUCRED_VERSION) + goto err_source; +#endif client->connection = wl_connection_create(fd); if (client->connection == NULL) -@@ -574,12 +603,23 @@ WL_EXPORT void +@@ -586,12 +615,23 @@ WL_EXPORT void wl_client_get_credentials(struct wl_client *client, pid_t *pid, uid_t *uid, gid_t *gid) { +#ifdef HAVE_SYS_UCRED_H + /* FreeBSD */ if (pid) + *pid = 0; /* FIXME: not defined on FreeBSD */ + if (uid) + *uid = client->xucred.cr_uid; + if (gid) + *gid = client->xucred.cr_gid; +#else + /* Linux */ + if (pid) *pid = client->ucred.pid; if (uid) *uid = client->ucred.uid; if (gid) *gid = client->ucred.gid; +#endif } /** Get the file descriptor for the client Index: head/graphics/wayland/files/patch-src_wayland-shm.c =================================================================== --- head/graphics/wayland/files/patch-src_wayland-shm.c (revision 526102) +++ head/graphics/wayland/files/patch-src_wayland-shm.c (revision 526103) @@ -1,147 +1,147 @@ ---- src/wayland-shm.c.orig 2018-04-09 17:19:26 UTC +--- src/wayland-shm.c.orig 2020-02-11 23:46:03 UTC +++ src/wayland-shm.c -@@ -30,6 +30,8 @@ +@@ -32,6 +32,8 @@ - #define _GNU_SOURCE + #include "config.h" +#include "../config.h" + #include #include #include -@@ -59,6 +61,9 @@ struct wl_shm_pool { - char *data; +@@ -64,6 +66,9 @@ struct wl_shm_pool { int32_t size; int32_t new_size; + bool sigbus_is_impossible; +#ifdef HAVE_SYS_UCRED_H + int fd; +#endif }; struct wl_shm_buffer { -@@ -76,15 +81,24 @@ struct wl_shm_sigbus_data { +@@ -81,15 +86,24 @@ struct wl_shm_sigbus_data { int fallback_mapping_used; }; +static void *mremap_compat_maymove(void *, size_t, size_t, int, int, int); + static void shm_pool_finish_resize(struct wl_shm_pool *pool) { void *data; + int fd = -1; if (pool->size == pool->new_size) return; - data = mremap(pool->data, pool->size, pool->new_size, MREMAP_MAYMOVE); +#ifdef HAVE_SYS_UCRED_H + fd = pool->fd; +#endif + + data = mremap_compat_maymove(pool->data, pool->size, pool->new_size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd); + if (data == MAP_FAILED) { wl_resource_post_error(pool->resource, WL_SHM_ERROR_INVALID_FD, -@@ -110,6 +124,10 @@ shm_pool_unref(struct wl_shm_pool *pool, bool external +@@ -115,6 +129,10 @@ shm_pool_unref(struct wl_shm_pool *pool, bool external if (pool->internal_refcount + pool->external_refcount) return; +#ifdef HAVE_SYS_UCRED_H + close(pool->fd); +#endif + munmap(pool->data, pool->size); free(pool); } -@@ -223,6 +241,73 @@ shm_pool_destroy(struct wl_client *client, struct wl_r +@@ -228,6 +246,73 @@ shm_pool_destroy(struct wl_client *client, struct wl_r wl_resource_destroy(resource); } +#ifdef HAVE_MREMAP +static void * +mremap_compat_maymove(void *old_address, size_t old_size, size_t new_size, + int old_prot, int old_flags, int old_fd) +{ + return mremap(old_address, old_size, new_size, MREMAP_MAYMOVE); +} +#else +static void * +mremap_compat_maymove(void *old_address, size_t old_size, size_t new_size, + int old_prot, int old_flags, int old_fd) +{ + /* FreeBSD doesn't support mremap() yet, so we have to emulate it. + * This assumes MREMAP_MAYMOVE is the only flag in use. */ + if (new_size == old_size) { + return old_address; + } else if (new_size < old_size) { + /* Shrinking: munmap() the spare region. */ + munmap(old_address + old_size, new_size - old_size); + return old_address; + } else { + void *ret; + + /* Growing. Try and mmap() the extra region at the end of + * our existing allocation. If that gets mapped in the + * wrong place, fall back to mmap()ing an entirely new + * region of new_size and copying the data across. */ + ret = mmap(old_address + old_size, new_size - old_size, + old_prot, old_flags, old_fd, 0); + +/* FIXME TODO: msync() before munmap()? */ + if (ret == MAP_FAILED) { + /* Total failure! */ + return ret; + } else if (ret == old_address + old_size) { + /* Success. */ + return old_address; + } else if (ret != old_address + old_size) { + /* Partial failure. Fall back to mapping an + * entirely new region. Unmap the region we + * just mapped first. */ + munmap(ret, new_size - old_size); + + /* Map an entirely new region. */ + ret = mmap(NULL, new_size, + old_prot, old_flags, old_fd, 0); + if (ret == MAP_FAILED) { + /* Total failure! */ + return ret; + } + + /* Copy the old data across. Implicit assumption + * that the old and new regions don't overlap. */ + memcpy(ret, old_address, old_size); + + /* Unmap the old region. */ + munmap(old_address, old_size); + + return ret; + } + } + + /* Unreachable. */ + return MAP_FAILED; +} +#endif + static void shm_pool_resize(struct wl_client *client, struct wl_resource *resource, int32_t size) -@@ -284,7 +369,14 @@ shm_create_pool(struct wl_client *client, struct wl_re - "failed mmap fd %d: %m", fd); +@@ -300,7 +385,14 @@ shm_create_pool(struct wl_client *client, struct wl_re + strerror(errno)); goto err_free; } + +#ifdef HAVE_SYS_UCRED_H + /* We need to keep the FD around on FreeBSD so we can implement + * mremap(). See: mremap_compat_maymove(). */ + pool->fd = fd; +#else close(fd); +#endif pool->resource = wl_resource_create(client, &wl_shm_pool_interface, 1, id); Index: head/graphics/wayland/files/patch-tests_event-loop-test.c =================================================================== --- head/graphics/wayland/files/patch-tests_event-loop-test.c (revision 526102) +++ head/graphics/wayland/files/patch-tests_event-loop-test.c (revision 526103) @@ -1,39 +1,44 @@ ---- tests/event-loop-test.c.orig 2017-08-08 18:20:52 UTC +--- tests/event-loop-test.c.orig 2020-02-11 23:46:03 UTC +++ tests/event-loop-test.c -@@ -167,10 +167,10 @@ TEST(event_loop_signal) +@@ -168,10 +168,10 @@ TEST(event_loop_signal) signal_callback, &got_it); assert(source); - wl_event_loop_dispatch(loop, 0); + assert(wl_event_loop_dispatch(loop, 0) == 0); assert(!got_it); - kill(getpid(), SIGUSR1); - wl_event_loop_dispatch(loop, 0); + assert(kill(getpid(), SIGUSR1) == 0); + assert(wl_event_loop_dispatch(loop, 0) == 0); assert(got_it == 1); wl_event_source_remove(source); -@@ -234,11 +234,19 @@ TEST(event_loop_timer) +@@ -235,11 +235,11 @@ TEST(event_loop_timer) - source = wl_event_loop_add_timer(loop, timer_callback, &got_it); - assert(source); -- wl_event_source_timer_update(source, 10); -- wl_event_loop_dispatch(loop, 0); -+ assert(wl_event_source_timer_update(source, 10) == 0); -+ assert(wl_event_loop_dispatch(loop, 0) == 0); - assert(!got_it); -- wl_event_loop_dispatch(loop, 20); -+ /* FreeBSD has a bug where it converts ms_timeout to ticks; it always adds 1 to the tick count. -+ * Consequently, we need to grossly overcompensate here. -+ * See: http://unix.derkeiler.com/Mailing-Lists/FreeBSD/hackers/2012-07/msg00319.html */ -+ assert(wl_event_loop_dispatch(loop, 50) == 0); + source1 = wl_event_loop_add_timer(loop, timer_callback, &got_it); + assert(source1); +- wl_event_source_timer_update(source1, 20); ++ assert(wl_event_source_timer_update(source1, 20) == 0); + + source2 = wl_event_loop_add_timer(loop, timer_callback, &got_it); + assert(source2); +- wl_event_source_timer_update(source2, 100); ++ assert(wl_event_source_timer_update(source2, 100) == 0); + + /* Check that the timer marked for 20 msec from now fires within 30 + * msec, and that the timer marked for 100 msec is expected to fire +@@ -248,11 +248,11 @@ TEST(event_loop_timer) + + wl_event_loop_dispatch(loop, 0); + assert(got_it == 0); +- wl_event_loop_dispatch(loop, 30); ++ assert(wl_event_loop_dispatch(loop, 30) == 0); assert(got_it == 1); -+ -+ /* Check it doesn't fire again. */ -+ got_it = 0; -+ assert(wl_event_loop_dispatch(loop, 20) == 0); -+ assert(!got_it); + wl_event_loop_dispatch(loop, 0); + assert(got_it == 1); +- wl_event_loop_dispatch(loop, 90); ++ assert(wl_event_loop_dispatch(loop, 90) == 0); + assert(got_it == 2); - wl_event_source_remove(source); - wl_event_loop_destroy(loop); + wl_event_source_remove(source1); Index: head/graphics/wayland/files/patch-tests_test-helpers.c =================================================================== --- head/graphics/wayland/files/patch-tests_test-helpers.c (revision 526102) +++ head/graphics/wayland/files/patch-tests_test-helpers.c (revision 526103) @@ -1,52 +1,52 @@ ---- tests/test-helpers.c.orig 2018-08-24 18:04:36 UTC +--- tests/test-helpers.c.orig 2020-02-11 23:46:03 UTC +++ tests/test-helpers.c @@ -25,6 +25,12 @@ #include "config.h" +#include "../config.h" + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + #include #include #include -@@ -40,6 +46,16 @@ +@@ -41,6 +47,16 @@ #include "test-runner.h" +#ifdef __FreeBSD__ +/* FreeBSD uses fdescfs (which must be mounted using: + * mount -t fdescfs fdescfs /dev/fd + * before the test suite can be run). */ +#define OPEN_FDS_DIR "/dev/fd" +#else +/* Linux. */ +#define OPEN_FDS_DIR "/proc/self/fd" +#endif + int count_open_fds(void) { -@@ -47,8 +63,8 @@ count_open_fds(void) +@@ -48,8 +64,8 @@ count_open_fds(void) struct dirent *ent; int count = 0; - dir = opendir("/proc/self/fd"); - assert(dir && "opening /proc/self/fd failed."); + dir = opendir(OPEN_FDS_DIR); + assert(dir && "opening " OPEN_FDS_DIR " failed."); errno = 0; while ((ent = readdir(dir))) { -@@ -57,7 +73,7 @@ count_open_fds(void) +@@ -58,7 +74,7 @@ count_open_fds(void) continue; count++; } - assert(errno == 0 && "reading /proc/self/fd failed."); + assert(errno == 0 && "reading " OPEN_FDS_DIR " failed."); closedir(dir); Index: head/graphics/wayland/files/patch-tests_test-runner.c =================================================================== --- head/graphics/wayland/files/patch-tests_test-runner.c (revision 526102) +++ head/graphics/wayland/files/patch-tests_test-runner.c (revision 526103) @@ -1,132 +1,132 @@ ---- tests/test-runner.c.orig 2019-03-21 00:55:25 UTC +--- tests/test-runner.c.orig 2020-02-11 23:46:03 UTC +++ tests/test-runner.c @@ -25,6 +25,12 @@ #define _GNU_SOURCE +#include "../config.h" + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + #include #include #include @@ -37,13 +43,23 @@ #include #include #include +#ifdef HAVE_SYS_PRCTL_H #include +#endif #ifndef PR_SET_PTRACER # define PR_SET_PTRACER 0x59616d61 #endif +#include #include "test-runner.h" +#ifdef __FreeBSD__ +/* XXX review ptrace() usage */ +#define PTRACE_ATTACH PT_ATTACH +#define PTRACE_CONT PT_CONTINUE +#define PTRACE_DETACH PT_DETACH +#endif + /* when set to 1, check if tests are not leaking opened files. * It is turned on by default. It can be turned off by * WAYLAND_TEST_NO_LEAK_CHECK environment variable. */ @@ -51,7 +67,7 @@ int fd_leak_check_enabled; /* when this var is set to 0, every call to test_set_timeout() is * suppressed - handy when debugging the test. Can be set by - * WAYLAND_TEST_NO_TIMEOUTS environment variable. */ + * WAYLAND_TESTS_NO_TIMEOUTS evnironment var */ static int timeouts_enabled = 1; /* set to one if the output goes to the terminal */ @@ -239,6 +255,8 @@ is_debugger_attached(void) return 0; } + +// xxx start here pid = fork(); if (pid == -1) { perror("fork"); @@ -259,13 +277,14 @@ is_debugger_attached(void) _exit(1); if (!waitpid(-1, NULL, 0)) _exit(1); - ptrace(PTRACE_CONT, NULL, NULL); + ptrace(PTRACE_CONT, ppid, NULL, NULL); ptrace(PTRACE_DETACH, ppid, NULL, NULL); _exit(0); } else { close(pipefd[0]); /* Enable child to ptrace the parent process */ +#if defined(HAVE_PRCTL) rc = prctl(PR_SET_PTRACER, pid); if (rc != 0 && errno != EINVAL) { /* An error prevents us from telling if a debugger is attached. @@ -275,7 +294,9 @@ is_debugger_attached(void) */ perror("prctl"); write(pipefd[1], "-", 1); - } else { + } else +#endif + { /* Signal to client that parent is ready by passing '+' */ write(pipefd[1], "+", 1); } @@ -293,7 +314,11 @@ int main(int argc, char *argv[]) const struct test *t; pid_t pid; int total, pass; +#ifdef HAVE_WAITID siginfo_t info; +#else + int status; +#endif if (isatty(fileno(stderr))) is_atty = 1; @@ -336,7 +361,8 @@ int main(int argc, char *argv[]) if (pid == 0) run_test(t); /* never returns */ - if (waitid(P_PID, pid, &info, WEXITED)) { +#ifdef HAVE_WAITID + if (waitid(P_PID, 0, &info, WEXITED)) { stderr_set_color(RED); - fprintf(stderr, "waitid failed: %m\n"); - stderr_reset_color(); -@@ -367,6 +393,25 @@ int main(int argc, char *argv[]) + fprintf(stderr, "waitid failed: %s\n", + strerror(errno)); +@@ -368,6 +394,25 @@ int main(int argc, char *argv[]) break; } +#else + if (waitpid(-1, &status, 0) == -1) { + fprintf(stderr, "waitpid failed: %s\n", + strerror(errno)); + abort(); + } + + fprintf(stderr, "test \"%s\":\t", t->name); + if (WIFEXITED(status)) { + fprintf(stderr, "exit status %d", WEXITSTATUS(status)); + if (WEXITSTATUS(status) == EXIT_SUCCESS) + success = 1; + } else if (WIFSIGNALED(status)) { + fprintf(stderr, "signal %d", WTERMSIG(status)); + } +#endif + + if (t->must_fail) + success = !success; if (success) { pass++;