From 2376a31c20a74947dba0ede4680579421d2f30e6 Mon Sep 17 00:00:00 2001 From: Torrekie Date: Sat, 20 Apr 2024 18:28:46 +0800 Subject: [PATCH] Re-enable os-wrappers-test.c on Darwin, fix errors Signed-off-by: Torrekie Gen --- egl/wayland-egl-symbols-check | 2 +- src/event-loop.c | 8 ++++++++ tests/os-wrappers-test.c | 23 +++++++++++++++-------- tests/queue-test.c | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/egl/wayland-egl-symbols-check b/egl/wayland-egl-symbols-check index 39f80cd1..82b9499d 100755 --- a/egl/wayland-egl-symbols-check +++ b/egl/wayland-egl-symbols-check @@ -20,7 +20,7 @@ if [ "$(uname)" == "Darwin" ]; then else NM_DYNSYM_TABLE="-D" SYMBOL_PREFIX="" -endif +fi AVAIL_FUNCS="$($NM ${NM_DYNSYM_TABLE} --format=bsd --defined-only $LIB | awk '{print $3}')" diff --git a/src/event-loop.c b/src/event-loop.c index 45222f71..1986939a 100644 --- a/src/event-loop.c +++ b/src/event-loop.c @@ -45,6 +45,14 @@ #include "wayland-server-private.h" #include "wayland-os.h" +#ifdef __APPLE__ +/* epoll-shim should provide this by design */ +struct itimerspec { + struct timespec it_interval; + struct timespec it_value; +}; +#endif + /** \cond INTERNAL */ #define TIMER_REMOVED -2 diff --git a/tests/os-wrappers-test.c b/tests/os-wrappers-test.c index 55067485..d9cd7c40 100644 --- a/tests/os-wrappers-test.c +++ b/tests/os-wrappers-test.c @@ -23,8 +23,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - /* This test should be skipped on Darwin (as of 2024) */ -#ifndef __APPLE__ #include "../config.h" #define _GNU_SOURCE @@ -62,12 +60,12 @@ static int socket_wrapper(int domain, int type, int protocol) { wrapped_calls_socket++; - +#ifdef SOCK_CLOEXEC if (fall_back && (type & SOCK_CLOEXEC)) { errno = EINVAL; return -1; } - +#endif return socket(domain, type, protocol); } @@ -111,11 +109,12 @@ static ssize_t recvmsg_wrapper(int sockfd, struct msghdr *msg, int flags) { wrapped_calls_recvmsg++; - +#ifdef MSG_CMSG_CLOEXEC if (fall_back && (flags & MSG_CMSG_CLOEXEC)) { errno = EINVAL; return -1; } +#endif return recvmsg(sockfd, msg, flags); } @@ -160,8 +159,11 @@ do_os_wrappers_socket_cloexec(int n) * Must have 2 calls if falling back, but must also allow * falling back without a forced fallback. */ +#ifdef SOCK_CLOEXEC assert(wrapped_calls_socket > n); - +#else + assert(wrapped_calls_socket == 1); +#endif exec_fd_leak_check(nr_fds); } @@ -234,8 +236,14 @@ struct marshal_data { static void setup_marshal_data(struct marshal_data *data) { +#ifdef SOCK_CLOEXEC assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, data->s) == 0); +#else + assert(socketpair(AF_UNIX, SOCK_STREAM, 0, data->s) == 0); + assert(set_cloexec_or_close(data->s[0]) != -1); + assert(set_cloexec_or_close(data->s[1]) != -1); +#endif data->read_connection = wl_connection_create(data->s[0], WL_BUFFER_DEFAULT_MAX_SIZE); @@ -325,7 +333,7 @@ do_os_wrappers_recvmsg_cloexec(int n) struct marshal_data data; data.nr_fds_begin = count_open_fds(); -#if HAVE_BROKEN_MSG_CMSG_CLOEXEC +#if HAVE_BROKEN_MSG_CMSG_CLOEXEC || !defined(MSG_CMSG_CLOEXEC) /* We call the fallback directly on FreeBSD versions with a broken * MSG_CMSG_CLOEXEC, so we don't call the local recvmsg() wrapper. */ data.wrapped_calls = 0; @@ -389,5 +397,4 @@ TEST(os_wrappers_epoll_create_cloexec_fallback) init_fallbacks(1); do_os_wrappers_epoll_create_cloexec(2); } -#endif /* __APPLE__ */ /* FIXME: add tests for wl_os_accept_cloexec() */ diff --git a/tests/queue-test.c b/tests/queue-test.c index cb61a85b..014c5de1 100644 --- a/tests/queue-test.c +++ b/tests/queue-test.c @@ -23,7 +23,26 @@ * SOFTWARE. */ +#ifndef __APPLE__ #define _GNU_SOURCE /* For memrchr */ +#else +#include +/* No memrchr() on Darwin, borrow one from OpenBSD */ +static void * +memrchr(const void *s, int c, size_t n) +{ + const unsigned char *cp; + + if (n != 0) { + cp = (unsigned char *)s + n; + do { + if (*(--cp) == (unsigned char)c) + return((void *)cp); + } while (--n != 0); + } + return(NULL); +} +#endif #include #include #include