Commit graph

893 commits

Author SHA1 Message Date
Jeremy Huddleston Sequoia
9b93dd87f0 darwin: Locate libexpat with cc.find_library() rather than dependency()
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2026-04-19 11:14:51 -07:00
Jeremy Huddleston Sequoia
8d62bfe3a4 darwin: Locate libffi with cc.find_library() rather than dependency()
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2026-04-19 11:14:51 -07:00
Jeremy Huddleston Sequoia
cb77e41fe7 shm: Avoid unused variable warning !HAVE_MEMFD_CREATE case
../src/wayland-shm.c:307:14: warning: unused variable 'statbuf' [-Wunused-variable]
        struct stat statbuf;
                    ^
../src/wayland-shm.c:308:6: warning: unused variable 'seals' [-Wunused-variable]
        int seals;
            ^
2 warnings generated.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2026-04-19 11:14:51 -07:00
Weijia Wang
46c205d08b os: Provide wl_os_socketpair_cloexec wrapper for systems without SOCK_CLOEXEC
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Signed-off-by: Weijia Wang <contact@weijia.wang>
2026-04-19 11:14:51 -07:00
Jeremy Huddleston Sequoia
d8e90f4a16 os: Use fallback implementations when *_CLOEXEC are unavailable at build time
On platforms without F_DUPFD_CLOEXEC, MSG_CMSG_CLOEXEC, or SOCK_CLOEXEC, we
should skip past their usage and just use the fcntl() fallback.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2026-04-19 11:14:51 -07:00
Jeremy Huddleston Sequoia
a77aa44f0e os: Add an implementation of wl_os_socket_peercred() for darwin
This adds an alternative implementation of wl_os_socket_peercred() using
getpeereid(3) and LOCAL_PEERPID, similar to changes I recently made to
xorg-server.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
2026-04-19 11:14:51 -07:00
Hannes Schulze
25da99a7e5 scanner: Remove now unused arg_count
Signed-off-by: Hannes Schulze <contact@haschu.me>
2026-04-14 15:11:51 +03:00
Hannes Schulze
b93a50abd9 scanner: Fix types emitted for new_id arguments
Previously, wayland-scanner would only emit one NULL entry in the
wl_message.types array for every argument, even though requests with
new_id arguments without an interface type additionally take a string
and a uint argument.

Signed-off-by: Hannes Schulze <contact@haschu.me>
2026-04-14 15:11:51 +03:00
YaoBing Xiao
74becc8761 scanner: drop redundant exit() after fail()
fail() already calls exit(), so the extra exit() is never reached.
Remove it to avoid dead code.

Signed-off-by: YaoBing Xiao <xiaoyaobing@uniontech.com>
2026-04-04 11:56:38 +08:00
YaNing Lu
e647f6304d util: fix use-after-free in for_each_helper
for_each_helper caches the entries->data pointer and array size before
iterating. If a compositor calls wl_client_for_each_resource() and the
provided callback triggers the creation of a new client object, the
underlying wl_array may be reallocated via realloc().

When this happens, the cached start pointer becomes dangling. Subsequent
iterations will read from the freed memory block, causing already-destroyed
resources to be destroyed a second time (e.g., leading to a double-free
crash in wl_list_remove()).

Fix this by dynamically re-fetching entries->data and entries->size on
every loop iteration, ensuring the iterator always accesses the valid
live array.

Signed-off-by: YaNing Lu <luyaning@uniontech.com>
2026-03-30 08:52:42 +08:00
Vlad Zahorodnii
44b26e34e5 Send wl_registry.global_remove to global's offer list
Since the globals track the registries that received global
announcements, we can use that instead of going through all present
registries and duplicate some filtering logic.

Signed-off-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
2026-03-24 13:45:00 +02:00
Vlad Zahorodnii
c048101ca9 Add wl_fixes.ack_global_remove()
The wl_global_remove() function was introduce to help mitigate clients
getting unintentionally disconnected if a global is added and removed in
a short burst.

The intended usage was:

 - the compositor calls wl_global_remove()
 - after a certain period of time, the compositor calls
   wl_global_destroy()

Unfortunately, it did not fully fix the issue due to the way monotonic
clock works on Linux. Specifically, it can tick even during sleep.

This change adds a slightly better way to handle global removal. With
the proposed changes, the clients need to signal to the compositor that
they won't bind the global anymore.

After all clients have acknowledged a wl_registry.global_remove, the
compositor can finally destroy the global.

Signed-off-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
2026-03-24 13:45:00 +02:00
Kirill Primak
13d906a629 server: improve wl_registry.bind error messages
- Consistently use PRIu32 for global names (uint32_t)
- Use expected/got instead of have/wanted (which were used differently anyway)

Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
2026-03-05 17:34:24 +00:00
Kirill Primak
69aabecd18 server: don't disclose the existence of invisible globals
Otherwise, a client iterate over a range of names binding with deliberately
incorrect interfaces and receive error messages with expected interfaces
regardless of global visibility.

Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
2026-03-05 17:34:24 +00:00
Isaac Freund
c0a6e73606 scanner: enforce frozen attribute
Signed-off-by: Isaac Freund <mail@isaacfreund.com>
2026-03-05 12:00:35 +00:00
Kirill Primak
4d13366fcc server: improve version mismatch error message
"1 < 2" is obviously true but not very useful information by itself. Provide a
bit more context.

Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
2026-03-05 11:18:53 +00:00
Simon Ser
fe3a02c18a util: assert alloc is consistent with data in wl_array_add()
struct wl_array may be constructed by users manually from a
foreign data pointer:

    uint32_t states[] = {1, 2, 3};
    struct wl_array arr = {
        .data = states,
        .size = sizeof(states) / sizeof(states[0]),
    };

This is useful to avoid the need to allocate when sending Wayland
messages.

Users need to be careful not to use wl_array_add() on such arrays:
the function will misbehave by leaving garbage at the start of the
new buffer when reallocating.

Add an assert to guard against wl_array_add() calls in this
situation, to have a clear crash instead of undefined behavior.

Signed-off-by: Simon Ser <contact@emersion.fr>
2026-03-03 11:31:53 +02:00
Loïc Yhuel
cd4e6a1451 client: fix crash when creating proxies with no queue
Before, it worked if the client did set a queue on the proxy before any event was received.
Now we have the "warning: queue xxx destroyed while proxies still attached", then a crash if one of
the proxies is used to create a proxy.

Fixes: 674145dc3f ("client: Track the proxies attached to a queue")
Fixes: 0ba650202e ("client: Warn when a queue is destroyed with attached proxies")
Signed-off-by: Loïc Yhuel <loic.yhuel@softathome.com>
2026-03-01 01:03:37 +00:00
Sebastian Wick
f72e3fae4a server: document protocol logger callback function
This fixes a validation error in the documentation which are not fatal.

The idea is the same as in 12ec67a ("server: document listener fields
and a vfunc"), which seems to have missed the reference to the
wl_protocol_logger_func_t from the note in wl_log_func_t.

Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2026-01-03 15:16:50 +01:00
Pekka Paalanen
12ec67aed5 server: document listener fields and a vfunc
Adding these simple documentation comments allows us to have meaningful
link targets in the generated API documentation. That will help getting
rid of broken links which cause XML validation to fail.

Signed-off-by: Pekka Paalanen <pq@iki.fi>
2025-12-29 16:27:14 +02:00
Pekka Paalanen
d1b8f352c3 server: fix wl_signal_add Doxygen warning
$ meson compile -C build -v xml-Server-doc
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C /home/pq/git/wayland/build -v doc/doxygen/xml/Server/combine.xslt doc/doxygen/xml/Server/index.xml
ninja: Entering directory `/home/pq/git/wayland/build'
[1/1] /home/pq/git/wayland/doc/doxygen/gen-doxygen.py --builddir=doc/doxygen/xml/Server --section=Server --output-format=xml doc/doxygen/wayland.doxygen ../doc/doxygen/../../src/wayland-util.h ../doc/doxygen/../../src/event-loop.c ../doc/doxygen/../../src/wayland-server.c ../doc/doxygen/../../src/wayland-server.h ../doc/doxygen/../../src/wayland-server-core.h ../doc/doxygen/../../src/wayland-shm.c
/home/pq/git/wayland/src/wayland-server-core.h:394: warning: explicit link request to 'wl_signal_add' could not be resolved

I don't know why, but the "explicit link" mark-up fails, while the
automatic link mark-up works. This warning disappears.

Signed-off-by: Pekka Paalanen <pq@iki.fi>
2025-12-29 11:19:01 +02:00
Sebastian Wick
c8a0996703 build: Bump to meson version 0.64.0
This version will be required in the next commit.

Bumps the CI image to get the required version from the debian package
instead of from pip.

Removes the bindir builtin directory from pkgconfig.generate() which is
deprecated since 0.62.0. It will be automatically included when
referenced.

Use `meson setup` everywhere instead of relying on deprecated automatic
detection of the setup command.

Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-11-27 17:39:11 +02:00
Isaac Freund
d81525a235 client: add wl_display_dispatch_pending_single
As well as wl_display_dispatch_queue_pending_single.

The motivation is writing libwayland bindings for a dynamic language
with exceptions/non-local returns. Since it is invalid for a
wl_dispatcher_func_t callback provided to libwayland to not return,
there is no way to prevent dispatching of further events in the case of
an exception in the dynamic language event handler.

Furthermore, since creating/destroying Wayland objects in an event
handler affects the dispatching of subsequent events by libwayland,
it is not possible to collect Wayland events in a queue outside
libwayland and dispatch them one-by-one after
wl_display_dispatch_pending() returns.

Adding libwayland API to dispatch at most one pending event solves this
problem cleanly. The bindings can have libwayland dispatch a single
event, wait for wl_display_dispatch_pending_single() to return, run the
dynamic language event handler (which may longjmp away), and continue
the loop for as long as there are more events to dispatch.

References: https://codeberg.org/ifreund/janet-wayland
Signed-off-by: Isaac Freund <mail@isaacfreund.com>
2025-09-16 11:48:33 +03:00
Kyle Brenneman
4673ef7e9c connection: Add a thread ID to WAYLAND_DEBUG output.
If WAYLAND_DEBUG contains the token "thread_id", and gettid() is
available, then include the current thread ID in the output from
wl_closure_print.

If multiple threads are sending requests, then those requests can get
interleaved. That's usually fine, but for wl_surface requests and
commits, that can cause problems ranging from incorrect behavior to
protocol errors.

Being able to see which requests are sent by different threads would
make such problems much easier to diagnose.

Signed-off-by: Kyle Brenneman <kbrenneman@nvidia.com>
2025-09-15 14:45:53 +01:00
Kyle Brenneman
77730f10a0 connection: Add a function to parse WAYLAND_DEBUG tokens
Add a new function, wl_check_env_token, to scan for a token in a
comma-separated string.

Change wl_display_create in wayland-server.c and
wl_display_connect_to_fd in wayland-client.c to use that instead of a
simple substring search.

This means that WAYLAND_DEBUG will accept a value like "client,server"
but not "clientserver". But, this will make it easier to add other
tokens without worrying about overlap between them.

Signed-off-by: Kyle Brenneman <kbrenneman@nvidia.com>
2025-09-15 14:45:53 +01:00
Demi Marie Obenour
adf84614ca connection: Do not busy-loop if a message exceeds the buffer size
If the length of a message exceeds the maximum length of the buffer, the
buffer size will reach its maximum value and stay there forever, with no
message ever being successfully processed.  Since libwayland uses
level-triggered epoll, this will cause the compositor to loop forever
and consume CPU time.  In libwayland 1.22 and below, there was an
explicit check that caused messages exceeding 4096 bytes to result in an
EOVERFLOW error, preventing the loop.  However, this check was removed
between d074d52902 ("connection: Dynamically resize connection buffers").

To prevent this problem, always limit the size of messages to 4096 bytes.
Since the default and minimum buffer size is 4096 bytes, this ensures
that a single message will always fit in the buffer.  It would be
possible to allow larger messages if the buffer size was larger, but the
maximum size of a message should not depend on the buffer size chosen by
the compositor.

Rejecting messages that exceed 4092 bytes seems to have the advantage of
reserving 4 bits, not 3, in the size field for future use.  However,
message sizes in the range [0x0, 0x7] are invalid, so one can obtain a
fourth bit by negating the meaning of bit 12 if bits 0 through 11
(inclusive) are 0.  Allowing 4096-byte messages provides the far more
important advantage that regressions compared to 1.22 are impossible
and regressions compared to 1.23 are extremely unlikely.  The only case
where a regression is possible is:

- The receiving side is using libwayland 1.23.
- The sending side is either using libwayland 1.23 or is not using
  libwayland.
- The sender sends a message exceeding 4096 bytes.
- If the sender of the large message is the client, the server has
  increased the buffer size from the default value.

This combination is considered extremely unlikely, as libwayland 1.22
and below would disconnect upon receiving such a large message.
4096-byte messages, however, have always worked, so there was no reason
to avoid sending them.

Fixes: d074d52902 ("connection: Dynamically resize connection buffers").
Fixes: #494
Signed-off-by: Demi Marie Obenour <demi@invisiblethingslab.com>
2025-06-21 11:29:04 +00:00
Manuel Stoeckl
387adc6a79 server: Document wl_display_add_socket_auto
The exact sequence of names tried has de facto become part of the API.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2025-06-08 16:20:35 +00:00
Kirill Primak
6281ccbd3d client: fix conversion specifier in the discarded event log message
Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
2025-06-01 14:56:34 +03:00
Caitlyn
ecff0ee10c debug: Colorize output for easier reading
Signed-off-by: Caitlyn <caitlynrosestewart@gmail.com>
2025-06-01 11:21:36 +00:00
Caitlyn Stewart
827d0c30ad connection: fix segfault in wl_closure_invoke()
Signed-off-by: Caitlyn Stewart <caitlynrosestewart@gmail.com>
2025-05-27 14:45:32 +01:00
Tobias Stoeckmann
cc06c3825f Fix typos
Typos found with codespell and during code audit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-20 20:49:32 +00:00
Isaac Freund
8cad6f7b82 server: add wl_resource_get_interface()
This is useful for the wayland bindings/scanner I'm working on for a
dynamically typed language.

Signed-off-by: Isaac Freund <mail@isaacfreund.com>
2025-05-20 20:31:16 +00:00
Isaac Freund
4497232102 client: add wl_proxy_get_interface()
This is useful for the wayland bindings/scanner I'm working on for a
dynamically typed language.

Signed-off-by: Isaac Freund <mail@isaacfreund.com>
2025-05-20 20:31:16 +00:00
Simon Ser
66fc3f007d shm: linkify function references in docs
Parentheses make it so the generated HTML documentation contains
links, which makes navigation easier.

Signed-off-by: Simon Ser <contact@emersion.fr>
2025-05-20 20:14:52 +00:00
Simon Ser
9dd1b2d7e3 shm: fix comment about wl_shm_buffer_begin_access() safety
The paragraph later says that accessing different buffers is
allowed. The function checks whether the same pool is accessed.

Signed-off-by: Simon Ser <contact@emersion.fr>
2025-05-20 20:14:52 +00:00
Sebastian Wick
d2a3d33063 shm: Generate an error when shm access failed even without a resource
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-05-20 21:50:22 +02:00
Sebastian Wick
9367c4da76 shm: Add wl_shm_buffer ref and unref functions
Shared memory buffers are currently tied to the lifetime of their
underlying wl_buffer resource. This becomes problematic when the client
destroys the resource after committing new state which references the
wl_buffer because a compositor might have to defer applying the commit.

This commit adds methods to keep the wl_shm_buffer alive longer than the
underlying resource. This implicitly also keeps the buffer pool alive
and because the wl_shm_buffer uses offsets into the pool, it even works
when the underlying storage gets remapped somewhere else, which can
happen when the client resizes the pool.

Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-05-20 21:50:22 +02:00
Sebastian Wick
af453f876e shm: Remove refcount check which cannot be triggered
If the pool refcount reaches zero, it is freed, so accessing its members
is UB which ASan would catch.

Also simplify check for negative refcounts.

Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-05-20 21:50:09 +02:00
Sebastian Wick
9ec01ab2dc shm: Linkify wl_shm_pool_unref in the ref_pool documentation
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-05-20 21:30:56 +02:00
Julian Orth
7033e74857 client: document get_listener behavior for dispatchers
This seems to have been the case since 2013.

This is useful for wrappers that need two pointers to identify proxies.
One pointer (stored in the user data) pointing to a singleton object to
identify that the proxy has a known structure. And one pointer (stored
in the dispatcher data) pointing to per-proxy data.

Signed-off-by: Julian Orth <ju.orth@gmail.com>
2025-03-15 23:07:39 +00:00
Simon Ser
dbfa8d784e scanner: use separate guards for validator functions
Generated XXX_is_valid() functions for enums are guarded behind the
same #define as the enum itself. This worked fine until recently,
but since fbd7460737 ("scanner: add new enum-header mode") we're
also generating enum-only headers.

When including the enum-only header first, and then the server
header, the validator functions are missing.

Define a separate guard to fix this.

Signed-off-by: Simon Ser <contact@emersion.fr>
2025-02-23 23:38:15 +01:00
Vlad Zahorodnii
1ab6b693b1 Forward declarate timespec struct
The `timespec` struct is defined in `time.h` header but only if
`_POSIX_C_SOURCE` is set or when using the C11 standard.

Signed-off-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
2025-02-06 10:18:17 +00:00
David Redondo
afd498b6f5 Also use [[deprecated]] when compiling with at least C++14
Signed-off-by: David Redondo <kde@david-redondo.de>
2025-02-05 09:43:21 +01:00
David Redondo
7c2ffb0d71 Make wayland-util.h -Wundef safe when compiled by a C++ compiler
Fixes #522
Signed-off-by: David Redondo <kde@david-redondo.de>
2025-02-05 09:21:43 +01:00
Daniel Stone
02ad102e2d build: Add -lm to pkg-config dependencies
Now that wl_fixed_from_double() calls round() from a function declared
in a header, our users need to explicitly pick that dependency up in
order to avoid build errors.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Closes: wayland/weston#991
2025-02-05 06:52:53 +00:00
Sebastian Wick
00dcf6b323 client: Add wl_display_dispatch_timeout
A variant of wl_display_dispatch_queue_timeout for the default queue.

Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-02-04 14:09:51 +00:00
Sebastian Wick
ddd348da7e client: Add wl_display_dispatch_queue_timeout
For dispatching messages on a queue with a timeout.

This slightly changes the samantics of wl_display_dispatch. Previously
it was possible for it to return even though there wasn't a single
dispatched event. The function correctly returned 0 in this case but it
is now used to indicate a timeout.

Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-02-04 14:09:51 +00:00
Sebastian Wick
ff8b885523 event-loop: Use timespec utils instead of hand-rolling our own
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-02-04 14:09:51 +00:00
Sebastian Wick
893e4fc46d timespec: Implement saturating timespec substraction
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-02-04 14:09:51 +00:00
Sebastian Wick
9d5de6062b timespec: Pull in timespec_after and timespec_add from mesa
Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com>
2025-02-04 14:09:51 +00:00