Commit graph

2567 commits

Author SHA1 Message Date
Simon Ser
ad4ed17335 ci: bump Meson version to 0.57
Signed-off-by: Simon Ser <contact@emersion.fr>
2024-04-09 00:48:18 +00:00
Manuel Stoeckl
d074d52902 connection: Dynamically resize connection buffers
When using fixed size connection buffers, if either the client or the
server is sending requests faster than the other end can cope with, the
connection buffers will fill up, eventually killing the connection.

This can be a problem for example with Xwayland mapping a lot of
windows, faster than the Wayland compositor can cope with, or a
high-rate mouse flooding the Wayland client with pointer events.

To avoid the issue, resize the connection buffers dynamically when they
get full.

Both data and fd buffers are resized on demand.

The default max buffer size is controlled via the wl_display interface
while each client's connection buffer size is adjustable for finer
control.

The purpose is to explicitly have larger connection buffers for specific
clients such as Xwayland, or set a larger buffer size for the client
with pointer focus to deal with a higher input events rate.

v0: Manuel:
   Dynamically resize connection buffers - Both data and fd buffers are
   resized on demand.
v1: Olivier
1. Add support for unbounded buffers on the client side and growable
   (yet limited) connection buffers on the server side.
2. Add the API to set the default maximum size and a limit for a given
   client.
3. Add tests for growable connection buffers and adjustable limits.
v2: Additional fixes by John:
1. Fix the size calculation in ring_buffer_check_space()
2. Fix wl_connection_read() to return gracefully once it has read up to
   the max buffer size, rather than returning an error.
3. If wl_connection_flush() fails with EAGAIN but the transmit
   ring-buffer has space remaining (or can be expanded),
   wl_connection_queue() should store the message rather than
   returning an error.
4. When the receive ring-buffer is at capacity but more data is
   available to be read, wl_connection_read() should attempt to
   expand the ring-buffer in order to read the remaining data.
v3: Thomas Lukaszewicz <tluk@chromium.org>
   Add a test for unbounded buffers
v4: Add a client API as well to force bounded buffers (unbounded
    by default (Olivier)
v5: Simplify ring_buffer_ensure_space() (Sebastian)

Co-authored-by: Olivier Fourdan <ofourdan@redhat.com>
Co-authored-by: John Lindgren <john@jlindgren.net>
Co-authored-by: Sebastian Wick <sebastian@sebastianwick.net>
Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: John Lindgren <john@jlindgren.net>
Signed-off-by: Sebastian Wick <sebastian@sebastianwick.net>
Closes: https://gitlab.freedesktop.org/wayland/wayland/-/issues/237
2024-04-08 14:05:32 +00:00
Simon Ser
36cef8653f util: convert macros to inline functions
Functionally equivalent except the usual macro footguns are avoided
and type safety is increased.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-03-28 17:56:34 +01:00
Isaac Freund
4945f2664f wl_touch.cancel: document lack of frame event
This appears to be what at least wlroots-based compositors and kwin do
in practice. However, it's not abundantly clear from the protocol text
what the expected behavior here is. This patch fixes that.

Signed-off-by: Isaac Freund <mail@isaacfreund.com>
2024-03-28 13:27:54 +00:00
Simon Ser
2e0dbb7021 tests: add scanner test for enum-header
Signed-off-by: Simon Ser <contact@emersion.fr>
2024-03-28 13:21:28 +00:00
Simon Ser
fbd7460737 scanner: add new enum-header mode
This generates a header with only enum definitions. This is useful
to share enum headers between libraries and library users.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-03-28 13:21:28 +00:00
Jordan Williams
2621484037 egl: Disable symbols check for static builds
The symbols check only works for dynamic libraries.
When building statically, the test fails.
This is caused by the check filtering out non-dynamic symbols with nm.
This change skips the check when building only static libraries.

Signed-off-by: Jordan Williams <jordan@jwillikers.com>
2024-03-28 13:13:47 +00:00
David Benjamin
8a7ecd774c util: fix undefined behavior in wl_array_for_each
If a wl_array has size zero, wl_array_for_each computes NULL + 0 to get
to the end pointer. This should be fine, and indeed it would be fine in
C++. But the C specification has a mistake here and it is actually
undefined behavior. See
https://davidben.net/2024/01/15/empty-slices.html

Clang's -fsanitize=undefined flags this. I ran into this in Chromium's
build with wayland-scanner on one of our XML files.

../../third_party/wayland/src/src/scanner.c:1853:2: runtime error: applying zero offset to null pointer
    #0 0x55c979b8e02c in emit_code third_party/wayland/src/src/scanner.c:1853:2
    #1 0x55c979b89323 in main third_party/wayland/src/src/scanner.c
    #2 0x7f8dfdb8c6c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #3 0x7f8dfdb8c784 in __libc_start_main csu/../csu/libc-start.c:360:3
    #4 0x55c979b70f39 in _start (...)

An empty XML file is sufficient to hit this case, so I've added it as a
test. To reproduce, undo the fix and include only the test, then build
with:

  CC=clang CFLAGS="-fno-sanitize-recover=undefined" meson build/ -Db_sanitize=undefined -Db_lundef=false
  ninja -C build test

Signed-off-by: David Benjamin <davidben@google.com>
2024-03-24 20:00:01 -04:00
Simon Ser
aa2a6d560b protocol: document that color channels provide electrical values
Expand the work done in [1] to document that all channels store
electrical values. See the discussion in [2].

[1]: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/316
[2]: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/250#note_2311377

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-03-12 13:04:51 +00:00
Simon Ser
44b1c0c737 connection: use enum wl_arg_type in wl_message_count_arrays()
Missed it in 155dd63b58 ("Introduce enum wl_arg_type").

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-03-06 19:09:35 +01:00
Simon Ser
440defbd2b client: simplify create_proxies() loop
Decrease the indentation a bit. No functional change.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-03-06 14:18:37 +01:00
Simon Ser
7a1e7dd549 client: simplify create_outgoing_proxy() loop
Decrease the indentation a bit. No functional change.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-03-06 14:18:18 +01:00
Simon Ser
830883e5b2 connection: simplify wl_closure_lookup_objects() loop
Decrease the indentation a bit. No functional change.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-03-06 14:18:18 +01:00
Simon Ser
155dd63b58 Introduce enum wl_arg_type
This is less cryptic to read than letters, and allows the compiler
to check switch statements exhaustiveness.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-03-06 14:17:48 +01:00
Thomas Lukaszewicz
47de87263c Mitigate UAF crashes due to wl_client_destroy reentrancy
There are situations in which a call into wl_client_destroy() can
result in a reentrant call into wl_client_destroy() - which
results in UAF / double free crashes.

For example, this can occur in the following scenario.

1. Server receives a message notifying it that a client has
   disconnected (WL_EVENT_HANGUP [1])

2. This beings client destruction with a call to wl_client_destroy()

3. wl_client_destroy() kicks off callbacks as client-associated
   resources are cleaned up and their destructors and destruction
   signals are invoked.

4. These callbacks eventually lead to an explicit call to
   wl_display_flush_clients() as the server attempts to flush
   events to other connected clients.

5. Since the client has already begun destruction, when it is
   reached in the iteration the flush fails wl_client_destroy()
   is called again [2].

This patch guards against this reentrant condition by removing
the client from the display's client list when wl_client_destroy()
is first called. This prevents access / iteration over the client
after wl_client_destroy() is called.

In the example above, wl_display_flush_clients() will pass over
the client currently undergoing destruction and the reentrant
call is avoided.

[1] 8f499bf404/src/wayland-server.c (L342)

[2] 8f499bf404/src/wayland-server.c (L1512)

Signed-off-by: Thomas Lukaszewicz [thomaslukaszewicz@gmail.com](mailto:thomaslukaszewicz@gmail.com)
2024-02-23 00:40:32 +00:00
Sébastien Marie
d80bce5f1a build: fix build and provide compat for OpenBSD
- wayland-egl-abi-check: try to use llvm-nm first instead of BSD nm (incompatible options)
- avoid forcing _POSIX_C_SOURCE=200809L (SOCK_CLOEXEC become available)
- epoll(7) is provided by a userspace wrapper around kqueue(2) as FreeBSD
- when using SO_PEERCRED, the struct to use is `struct sockpeercred` instead of `struct ucred` on OpenBSD
- provide a compatibility layer for count_open_fds() using sysctl(2) as FreeBSD

Signed-off-by: Sebastien Marie <semarie@online.fr>
2024-02-21 15:46:41 +00:00
Sébastien Marie
791912c678 compat: prefer waitpid() over waitid()
while both are defined by POSIX, waitpid() is more common than waitid().

Signed-off-by: Sebastien Marie <semarie@online.fr>
2024-02-21 15:46:41 +00:00
Simon Ser
a74aa93394 protocol: mention wl_surface events from wl_output.{scale,transform}
The wl_output events should not be used anymore for guessing the
preferred scale and transform of a surface. We have explicit events
for that now.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-02-21 09:14:23 +00:00
Sebastian Wick
9c4213ed3e server: add wl_client_get_user_data/wl_client_set_user_data
The only way to attach some data to a wl_client seems to be setting up a
destroy listener and use wl_container_of. Let's make it straight forward
to attach some data.

Having an explicit destroy callback for the user data makes managing the
user data lifetime much more convenient. All other callbacks, be they
wl_resource request listeners, destroy listeners or destructors, or
wl_client destroy listeners, can assume that the wl_client user data
still exists if it was set. Otherwise making that guarantee would be
complicated.

Co-authored-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Signed-off-by: Sebastian Wick <sebastian@sebastianwick.net>
2024-02-15 10:53:21 +00:00
Kirill Primak
6a7284c632 event-loop: use wl_priv_signal for the destroy signal
Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
2024-02-08 17:18:28 +00:00
Thomas Lukaszewicz
d275bc7f84 Mitigate UAF crashes due to iteration over freed wl_resources
Currently it is possible to iterate over client-owned resources
during client destruction that have had their associated memory
released.

This can occur when client code calls wl_client_destroy(). The
following sequence illustrates how this may occur.

 1. The server initiates destruction of the connected client via
    call to wl_client_destroy().

 2. Resource destroy listeners / destructors are invoked and
    resource memory is freed one resource at a time [1].

 3. If a listener / destructor for a resource results in a call
    to wl_client_for_each_resource(), the iteration will proceed
    over resources that have been previously freed in step 2,
    resulting in UAFs / crashes.

The issue is that resources remain in the client's object map
even after they have had their memory freed, and are removed
from the map only after each individual resource has had its
memory released.

This patch corrects this by ensuring resource destruction first
invokes listeners / destructors and then removing them from the
client's object map before releasing the associated memory.

[1] https://gitlab.freedesktop.org/wayland/wayland/-/blob/main/src/wayland-server.c?ref_type=heads#L928

Signed-off-by: Thomas Lukaszewicz thomaslukaszewicz@gmail.com
2024-02-07 09:45:41 +00:00
Kirill Primak
8f499bf404 protocol: clarify pending wl_buffer destruction
This matches the current behavior of KWin, Mutter, and Weston.

References: https://gitlab.freedesktop.org/wayland/wayland/-/issues/387
Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
2024-01-27 15:17:28 +00:00
Mikhail Gusarov
88ece8a44d doc: Improve wording for packed IDs
"is incompatible with the implementation in libwayland" is a common
source of confusion as evidenced by repeated discussions in IRC
channel.

Improve the wording by making clear that
- packing IDs is a protocol requirement
- there are implementations (including libwayland) that enforce it

Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
2024-01-22 12:37:26 +00:00
Derek Foreman
b42218f790 client: Allow setting names for queues
Allow setting a name for an event queue. The queue is used only for
printing additional debug information.

Debug output can now show the name of the event queue an event is
dispatched from, or the event queue of a proxy when a request is made.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2024-01-22 12:34:14 +00:00
Erik Chen
2f17d480e8 connection: Spruce up logging for client errors.
Some code paths that lead to a client error and connection termination
have no associated logging, or insufficient logging. This makes it
difficult to understand what went wrong. This commit adds or supplements
logging for all these code paths.

Signed-off-by: Erik Chen <erikchen@chromium.org>
2024-01-19 15:51:33 +00:00
John Lindgren
9867bdb111 connection: Small simplification to wl_connection_write()
wl_connection_write() contained an exact copy of the logic in
wl_connection_queue().  Simplify things by just calling
wl_connection_queue() from wl_connection_write().

Signed-off-by: John Lindgren <john@jlindgren.net>
2024-01-19 15:25:54 +00:00
Andreas Cord-Landwehr
8c49ee3112 Consider pkgconfig sysroot for pkgdatadir
For libs/cflags this is done automatically, but not for manually accessed
variables. This matches what wayland-protocols does.

Signed-off-by: Andreas Cord-Landwehr <cordlandwehr@kde.org>
2024-01-19 15:18:23 +00:00
Simon Ser
fd42f70baf shm: implement version 2
This version adds a release request.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-01-19 15:12:29 +00:00
Simon Ser
f06736a8a0 protocol: add wl_shm.release request
Allows clients to cleanly release wl_shm objects. Useful for clients
using multiple wl_registry objects (e.g. via libraries).

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-01-19 15:12:29 +00:00
Simon Ser
9e233e31a2 shm: fix resource versions
This was hardcoded to 1 regardless of the version passed to the
callback or the version of the parent resource.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-01-19 15:12:29 +00:00
Ben Widawsky
8072ab0a50 protocol: clarify scale expecations
Since the positivity of zero is debatable, and, in some cases scale was simply
underspecified, clarify the situation.

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
2024-01-19 14:35:06 +00:00
Simon Ser
647398ead4 util: use C23 deprecated attribute
Signed-off-by: Simon Ser <contact@emersion.fr>
2024-01-19 14:21:59 +00:00
Simon Ser
56b9c92b98 util: use C23 typeof if available
Instead of using the non-standard __typeof__, prefer the standard
typeof operator introduced in C23.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-01-19 14:21:59 +00:00
Simon Ser
dc1da181db protocol: document wl_surface.offset for sub-surfaces
Document that the request is ignored, since this is the behavior
of most compositors.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-01-19 14:14:15 +00:00
Consolatis
6daa1b8713 cursor: add aliases for cursor name spec
The cursor name spec [1] describes how cursors should be named,
and is widely used. Add aliases so that users can pass these
names to libwayland-cursor without having to add fallbacks for
X11 cursor names.

[1]: https://www.freedesktop.org/wiki/Specifications/cursor-spec/

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-01-19 14:08:16 +00:00
Simon Ser
0e139cfbc7 build: add a gen-scanner-test target
This adds a command to re-generate the test data. This needs to be
done when either an XML source file or the scanner's output is
changed.

Signed-off-by: Simon Ser <contact@emersion.fr>
2024-01-15 14:29:10 +01:00
Julian Orth
6626d4d98c protocol: wl_subsurface will never be focused
The spec does not describe which actions cause the compositor to assign
keyboard focus to a surface, leaving this up to the compositor.
Compositors differ in their behavior when the user clicks on a
sub-surface. Some will move the keyboard focus to the subsurface whereas
others will only ever assign the keyboard focus to toplevel surfaces.
Some applications (e.g. firefox) seem to require the second behavior.

This patch specifies that sub-surfaces never get the keyboard focus.

Signed-off-by: Julian Orth <ju.orth@gmail.com>
2023-12-27 18:02:07 +00:00
Francesco Guastella
86588fbdeb build: define tests in egl/meson.build when the 'tests' option is enabled
Signed-off-by: Francesco Guastella <guastella.francesco@gmail.com>
2023-12-10 14:58:04 +00:00
Kirill Primak
82d8b21827 protocol: improve wl_subsurface.{set_position,place_above} description
Don't mention when the parent surface state is applied; the parent
surface isn't necessarily a sub-surface.

Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
2023-11-21 15:54:58 +00:00
Kirill Chibisov
8a19dc19a1 protocol: clarify defaults with wl_compositor@v6
This should be sufficient for clients to not decide to fallback to
output based logic to determine scaling/transform when compositor
doesn't send any of the v6 events.

Signed-off-by: Kirill Chibisov <contact@kchibisov.com>
2023-11-21 15:50:11 +00:00
Simon Ser
2a91f01d6c util: simplify wl_fixed_from_double()
Same as 0e0ae7e290 ("util: simplify wl_fixed_to_double()"), but
for the reverse function.

Signed-off-by: Simon Ser <contact@emersion.fr>
2023-11-21 15:47:13 +00:00
Simon Ser
3007718b0c gitlab: make issue template the default
The issue template is hard to notice because it's not the default.
Users have to explicitly select it from the easy-to-miss dropdown
to get the warning.

Make the template the default one, so that new users are less likely
to miss it.

Signed-off-by: Simon Ser <contact@emersion.fr>
2023-11-21 15:44:31 +00:00
Simon Ser
e4eb42d073 protocol: refer to wl_surface.offset in wl_data_device.start_drag
Passing an offset to wl_surface.attach is not supported in the
latest version of the interface.

Signed-off-by: Simon Ser <contact@emersion.fr>
2023-11-21 15:36:00 +00:00
David Benjamin
50ea9c5b1c connection: avoid calling memcpy on NULL, 0
Due to what is arguably a mistake in the C language specification,
passing NULL to memcpy and friends is undefined behavior (UB) even when
the count is 0. C additionally mistakenly leaves NULL + 0 and NULL -
NULL undefined. (C++ fixes this mistake.) These are very problematic
because (NULL, 0) is a natural representation of the empty slice.

Some details:
https://github.com/llvm/llvm-project/issues/49459
https://www.imperialviolet.org/2016/06/26/nonnull.html

Unfortunately, despite how clearly this is a mistake, glibc headers and
GCC now try to exploit this specification mistake and will miscompile
code, so C projects need to workaround this. In particular, UBSan from
Clang will flag this as a bug (although Clang itself has the good sense
to never lean on this bug). We've run into a few UBSan errors in
Chromium stemming from Wayland's memcpy calls. Add runtime guards as
needed to avoid these cases.

Note: Chromium's copy of wayland has
https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/188
applied. It is possible the ring_buffer_copy UB cases are only reachable
with that MR applied, I'm not sure. But it seemed simplest to just add
the fix to wayland as-is. Then when/if that MR lands, it will pick this
up.

Signed-off-by: David Benjamin <davidben@google.com>
2023-11-08 08:41:16 -05:00
David Edmundson
edb943dc64 client: Add method to get display for a given proxy
This can be useful for additional validation purposes when handling
proxies. This is similar to existing server side API
wl_global_get_display.

Signed-off-by: David Edmundson <david@davidedmundson.co.uk>
2023-08-07 13:38:01 +00:00
Simon Ser
379a6f6759 ci: upgrade FreeBSD to 13.2
Signed-off-by: Simon Ser <contact@emersion.fr>
2023-08-02 16:47:07 +02:00
Simon Ser
63b0050561 ci: upgrade Debian to bookworm
This is the current Debian stable release.

Signed-off-by: Simon Ser <contact@emersion.fr>
2023-08-02 16:47:07 +02:00
Simon Ser
a81f947aff ci: upgrade ci-templates
Newer ci-templates contains bugfixes.

While at it, stop using a GitLab YAML reference, because we only
use this value in one spot.

Signed-off-by: Simon Ser <contact@emersion.fr>
2023-08-02 16:47:07 +02:00
Simon Ser
7b27881cd1 cursor: check return value of snprintf()
Fixes a new warning in GCC 7:

    FAILED: cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o
    cc -Icursor/libwayland-cursor.so.0.22.90.p -Icursor -I../cursor -I. -I.. -Isrc -I../src -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=c99 -O3 -D_POSIX_C_SOURCE=200809L -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden -fPIC '-DICONDIR="/usr/share/X11/icons"' -MD -MQ cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o -MF cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o.d -o cursor/libwayland-cursor.so.0.22.90.p/xcursor.c.o -c ../cursor/xcursor.c
    ../cursor/xcursor.c: In function 'xcursor_load_theme':
    ../cursor/xcursor.c:596:39: error: '%s' directive output between 7 and 7 bytes may cause result to exceed 'INT_MAX' [-Werror=format-truncation=]
      596 |         snprintf(full, full_size, "%s/%s/%s", dir, subdir, file);
          |                                       ^~
    ......
      764 |                 full = xcursor_build_fullname(dir, "cursors", "");
          |                                                    ~~~~~~~~~
    ../cursor/xcursor.c:596:41: error: '/' directive output between 1 and 1 bytes may cause result to exceed 'INT_MAX' [-Werror=format-truncation=]
      596 |         snprintf(full, full_size, "%s/%s/%s", dir, subdir, file);
          |                                         ^
    cc1: all warnings being treated as errors

Signed-off-by: Simon Ser <contact@emersion.fr>
2023-08-02 16:47:07 +02:00
Simon Ser
72da004b3e protocol: fix whitespace
This file uses tabs instead of 8 spaces.

Signed-off-by: Simon Ser <contact@emersion.fr>
2023-07-19 11:01:17 +00:00