Merge branch 'darwin-basedon-Torrekie' into 'main'

Add Darwin support - updated

Closes #545 and #310

See merge request wayland/wayland!481
This commit is contained in:
Liang Qi 2026-03-22 14:28:43 +00:00
commit 745a0a3511
15 changed files with 238 additions and 20 deletions

View file

@ -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

View file

@ -38,7 +38,6 @@
#include <sys/un.h>
#include <ctype.h>
#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
#include "wayland-util.h"
@ -2055,7 +2054,7 @@ wl_display_poll(struct wl_display *display,
timespec_sub_saturate(&result, &deadline, &now);
remaining_timeout = &result;
}
ret = ppoll(pfd, 1, remaining_timeout, NULL);
ret = wl_os_ppoll(pfd, 1, remaining_timeout, NULL);
} while (ret == -1 && errno == EINTR);
return ret;

View file

@ -39,6 +39,9 @@
#ifdef HAVE_SYS_UCRED_H
#include <sys/ucred.h>
#endif
#if defined(__APPLE__) && !defined(EPOLL_SHIM_DISABLE_WRAPPER_MACROS)
#include <epoll-shim/detail/poll.h>
#endif
#include "wayland-os.h"
@ -74,18 +77,20 @@ int
wl_os_socket_cloexec(int domain, int type, int protocol)
{
int fd;
#if !defined(__APPLE__)
/* It is ok to bypass this logic on Darwin,
FD_CLOEXEC will be set by set_cloexec_or_close() */
fd = wl_socket(domain, type | SOCK_CLOEXEC, protocol);
if (fd >= 0)
return fd;
if (errno != EINVAL)
return -1;
#endif
fd = wl_socket(domain, type, protocol);
return set_cloexec_or_close(fd);
}
#if defined(__FreeBSD__)
#if defined(LOCAL_PEERCRED)
int
wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid)
{
@ -101,6 +106,14 @@ wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid)
#if HAVE_XUCRED_CR_PID
/* Since https://cgit.freebsd.org/src/commit/?id=c5afec6e895a */
*pid = ucred.cr_pid;
#elif defined(LOCAL_PEERPID)
/* Try LOCAL_PEERPID if no cr_pid in xucred */
size_t pid_size;
pid_t peerpid;
if (getsockopt(sockfd, SOL_LOCAL, LOCAL_PEERPID, &peerpid, &pid_size))
*pid = peerpid;
else
*pid = 0;
#else
*pid = 0;
#endif
@ -178,13 +191,16 @@ recvmsg_cloexec_fallback(int sockfd, struct msghdr *msg, int flags)
ssize_t
wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags)
{
#if HAVE_BROKEN_MSG_CMSG_CLOEXEC
#if HAVE_BROKEN_MSG_CMSG_CLOEXEC || defined(__APPLE__)
/*
* FreeBSD had a broken implementation of MSG_CMSG_CLOEXEC between 2015
* and 2021, so we have to use the non-MSG_CMSG_CLOEXEC fallback
* directly when compiling against a version that does not include the
* fix (https://cgit.freebsd.org/src/commit/?id=6ceacebdf52211).
*/
/*
* Darwin has no MSG_CMSG_CLOEXEC, so use fallback too.
*/
#pragma message("Using fallback directly since MSG_CMSG_CLOEXEC is broken.")
#else
ssize_t len;
@ -220,7 +236,7 @@ wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
int fd;
#ifdef HAVE_ACCEPT4
#if defined(HAVE_ACCEPT4) && !defined(__APPLE__)
fd = accept4(sockfd, addr, addrlen, SOCK_CLOEXEC);
if (fd >= 0)
return fd;
@ -260,3 +276,18 @@ wl_os_mremap_maymove(int fd, void *old_data, ssize_t *old_size,
return result;
}
int
wl_os_ppoll(struct pollfd *fds, nfds_t nfds,
const struct timespec *timeout_ts, const sigset_t *sigmask)
{
#if defined(__APPLE__)
#ifndef EPOLL_SHIM_DISABLE_WRAPPER_MACROS
return epoll_shim_ppoll(fds, nfds, timeout_ts, sigmask);
#else
return -1;
#endif
#endif
return ppoll(fds, nfds, timeout_ts, sigmask);
}

View file

@ -28,6 +28,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <poll.h>
int
wl_os_socket_cloexec(int domain, int type, int protocol);
@ -51,6 +52,9 @@ void *
wl_os_mremap_maymove(int fd, void *old_data, ssize_t *old_size,
ssize_t new_size, int prot, int flags);
int
wl_os_ppoll(struct pollfd *fds, nfds_t nfds,
const struct timespec *timeout_ts, const sigset_t *sigmask);
/*
* The following are for wayland-os.c and the unit tests.