aboutsummaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Do not allow nullable `new_id`Ian Douglas Scott2022-07-142-3/+2
| | | | | | | | The usefulness of this is limited, and `libwayland-client` doesn't provide a way to pass a null `new_id` since the id is generated by the library and given to the caller as the return value. Signed-off-by: Ian Douglas Scott <idscott@system76.com>
* Do not allow nullable arrays, which were not correctly implementedIan Douglas Scott2022-07-142-3/+2
| | | | | | | | | | | Nullable arrays, which are not used anywhere, were marshalled the same way as an empty non-null array. The demarshalling logic did not recognize anything as a null array. Given this, it seems better to just explicitly not support it. Fixes https://gitlab.freedesktop.org/wayland/wayland/-/issues/306. Signed-off-by: Ian Douglas Scott <idscott@system76.com>
* util: set errno when hitting WL_MAP_MAX_OBJECTSSimon Ser2022-06-281-2/+7
| | | | | | | | | | | | Callers may check errno when wl_map_insert_* functions return an error (since [1]). Make sure it's always set to a meaningful value when returning an error, otherwise callers might end up checking an errno coming from a completely different function. [1]: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/205 Signed-off-by: Simon Ser <contact@emersion.fr> Fixes: b19488c7154b ("util: Limit size of wl_map")
* server: warn about global filtering consistencySimon Ser2022-06-151-0/+4
| | | | | | | | The filtering needs to be static given a client and a global, otherwise libwayland will misbehave. Signed-off-by: Simon Ser <contact@emersion.fr> References: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/241#note_1421888
* server: add PID race condition disclaimer to wl_client_get_credentialsSimon Ser2022-06-151-0/+3
| | | | | | | PIDs are re-used and cannot be used to reliably check the identity of a Wayland client. Signed-off-by: Simon Ser <contact@emersion.fr>
* server: check visibility before sending global/global_removeSimon Ser2022-06-151-7/+9
| | | | | | | | | | | See the previous discussion at [1]: libwayland incorrectly skips the visibility checks when sending global/global_remove events. The check is only performed when a client performs a wl_display.get_registry request. [1]: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/148 Signed-off-by: Simon Ser <contact@emersion.fr>
* client: Lock display when setting a proxy event queueAlexandros Frantzis2022-06-091-0/+4
| | | | | | | | | | | | | | | | | | | Assignments to a wl_proxy's queue member are currently not synchronized with potential reads of that member during event reading/queuing. Assuming atomic pointer value reads and writes (which is a reasonable assumption), and using the documented best practices to handle event queue changes, a queue change should still be safe to perform. That being said, such implicitly atomic accesses are difficult to assess for correctness, especially since they do not introduce memory barriers. To make the code more obviously correct, and handle any potential races we are not currently aware of, this commit updates wl_proxy_set_queue() to set the proxy's event queue under the display lock (all other proxy queue accesses are already done under the display lock). Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com> Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
* client: Document best practices for event queue changesAlexandros Frantzis2022-06-091-0/+13
| | | | | | | | | | | | Document the proper way to deal with event queue changes, in order to guarantee proper handing of all events which were queued before the queue change takes effect, especially in multi-threaded setups. Make a special note about queue changes of newly created proxies, which require the use of a proxy wrapper for thread safety. Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com> Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.com>
* Check that XDG base directories paths are absoluteAntonin Décimo2022-06-092-5/+6
| | | | | | | | | | | | | | | | | | | The [spec][1] reads: > All paths set in these environment variables must be absolute. If an > implementation encounters a relative path in any of these variables it should > consider the path invalid and ignore it. and > If $XDG_DATA_HOME is either not set or empty, a default equal to > $HOME/.local/share should be used. Testing that the path is absolute also entails that is is non-empty. [1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html Signed-off-by: Antonin Décimo <antonin.decimo@gmail.com>
* Meson: Override wayland-scanner if it can be runXavier Claessens2022-05-241-0/+4
| | | | | | | This allows projects to use Wayland as a Meson subproject and get the wayland-scanner executable when doing find_program('wayland-scanner'). Signed-off-by: Xavier Claessens <xavier.claessens@collabora.com>
* util: fix code block language in docsSimon Ser2022-05-231-1/+1
| | | | | | | | | Without {.xml}, Doxygen interprets the code as C. See [1] for details. [1]: https://www.doxygen.nl/manual/commands.html#cmdcode Signed-off-by: Simon Ser <contact@emersion.fr>
* server: add wl_global_get_versionSimon Ser2022-05-232-0/+17
| | | | | | | | | Add a helper to check the advertised version of a global. This can be handy when checking whether a compositor feature is supported, instead of having to store the version passed to wl_global_create separately. Signed-off-by: Simon Ser <contact@emersion.fr>
* util: Limit size of wl_mapDerek Foreman2022-05-162-2/+24
| | | | | | | | | | | | | | | | | | | | Since server IDs are basically indistinguishable from really big client IDs at many points in the source, it's theoretically possible to overflow a map and either overflow server IDs into the client ID space, or grow client IDs into the server ID space. This would currently take a massive amount of RAM, but the definition of massive changes yearly. Prevent this by placing a ridiculous but arbitrary upper bound on the number of items we can put in a map: 0xF00000, somewhere over 15 million. This should satisfy pathological clients without restriction, but stays well clear of the 0xFF000000 transition point between server and client IDs. It will still take an improbable amount of RAM to hit this, and a client could still exhaust all RAM in this way, but our goal is to prevent overflow and undefined behaviour. Fixes #224 Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
* build: sanity check optionsSimon Ser2022-05-101-0/+4
| | | | | | | | Fail when tests/documentation is enabled without libraries. Fail when neither scanner nor libraries is enabled, because we don't build anything in that case. Signed-off-by: Simon Ser <contact@emersion.fr>
* os: drop unnecessary memcpy in wl_os_mremap_maymoveSimon Ser2022-04-111-12/+13
| | | | | | | | | | | | | | FreeBSD doesn't support mremap [1], so we have a fallback implementation based on munmap+mmap. We memcpy from the old memory region to the new one, however this is unnecessary because the new mapping references the same file as the old one. Use msync to make sure any pending write is flushed to the underlying file before we map the new region. [1]: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=59912 Signed-off-by: Simon Ser <contact@emersion.fr>
* shm: Close file descriptors not neededOlivier Fourdan2022-04-051-0/+8
| | | | | | | | | | | | | | | | | | | | | | | Commit 5a981ee8 implemented a fallback path for platforms which do not support mremap() such as FreeBSD. To do so, the file descriptor for the mmap() is not closed immediately but instead kept as long as the pool exists. That induces more file descriptors kept open for longer, which in turn may cause problems as wl_shm may be using a lot of file descriptors, especially with Xwayland which can create a lot of pixmaps on behalf of its X11 clients. For platforms where mremap() is available, keeping those file descriptors opened is a bit of a waste and may cause exhaustion of file descriptors sooner that before commit 5a981ee8. Only keep the mmap() file descriptor open on platforms which do not implement mremap() and close it immediately as before on others. Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1283
* connection: change clen type in build_cmsg to size_tSigrid Solveig Haflínudóttir2022-04-031-2/+3
| | | | | | To avoid implicit conversion since msg_control's type is size_t. Signed-off-by: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
* connection: fix asan report on sendmsg callSigrid Solveig Haflínudóttir2022-04-031-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Initialiaze the entire msghdr struct to 0 before use. Example of the report fixed with this change: AddressSanitizer:DEADLYSIGNAL ================================================================= ==20035==ERROR: AddressSanitizer: SEGV on unknown address 0x2dad4dbffffa0d (pc 0x0055555c7488 bp 0x007fffffc760 sp 0x007fffffc760 T0) ==20035==The signal is caused by a READ memory access. #0 0x55555c7488 in read_msghdr(void*, __sanitizer::__sanitizer_msghdr*, long) (/home/ftrvx/w/_/uxn/bin/uxnemu+0x77488) #1 0x55555c810c in sendmsg (/home/ftrvx/w/_/uxn/bin/uxnemu+0x7810c) #2 0x7ff7f2db20 in wl_connection_flush /home/ftrvx/q/wayland/build/../src/connection.c:315:10 #3 0x7ff7f2d014 in wl_display_flush /home/ftrvx/q/wayland/build/../src/wayland-client.c:2154:9 #4 0x7ff7e80bc0 (/lib/libSDL2-2.0.so.0+0x104bc0) #5 0x7ff7e523b0 (/lib/libSDL2-2.0.so.0+0xd63b0) #6 0x7ff7e534e4 (/lib/libSDL2-2.0.so.0+0xd74e4) #7 0x7ff7e535e8 (/lib/libSDL2-2.0.so.0+0xd75e8) #8 0x7ff7daad54 (/lib/libSDL2-2.0.so.0+0x2ed54) #9 0x7ff7dab130 (/lib/libSDL2-2.0.so.0+0x2f130) #10 0x555565bb40 in main /home/ftrvx/w/_/uxn/src/uxnemu.c:519:2 #11 0x7ff7f62484 in libc_start_main_stage2 /builddir/musl-1.1.24/src/env/__libc_start_main.c:94:2 AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV (/home/ftrvx/w/_/uxn/bin/uxnemu+0x77488) in read_msghdr(void*, __sanitizer::__sanitizer_msghdr*, long) ==20035==ABORTING Signed-off-by: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
* server: introduce wl_signal_emit_mutableSimon Ser2022-03-282-0/+66
| | | | | | | | | | | | | | | wl_signal_emit doesn't handle well situations where a listener removes another listener. This can happen in practice: wlroots and Weston [1] both have private helpers to workaround this defect. wl_signal_emit can't be fixed without breaking the API. Instead, introduce a new function. Callers need to make sure to always remove listeners when they are free'd. [1]: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/457 Signed-off-by: Simon Ser <contact@emersion.fr> Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
* client, server: handle wl_map_insert_new() failuresAleksandr Mezin2022-03-252-3/+19
| | | | Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
* util: set errno in wl_map_insert_at()Aleksandr Mezin2022-03-253-9/+18
| | | | | | And add errno checks in callers, where it seems to be necessary. Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
* util: set errno in wl_map_reserve_new()Aleksandr Mezin2022-03-252-7/+17
| | | | | | And also fix wl_connection_demarshal() to pass through that errno. Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
* util: always check result of wl_array_add()Aleksandr Mezin2022-03-251-3/+7
| | | | | | | Not checking the result of wl_array_add() can cause writes past the end of the allocated buffer if realloc fails. Signed-off-by: Aleksandr Mezin <mezin.alexander@gmail.com>
* build: use get_variable(pkgconfig) instead of get_pkgconfig_variable()Simon Ser2022-03-251-1/+1
| | | | | | | We don't get a warning for it yet, but get_pkgconfig_variable() is deprecated. Signed-off-by: Simon Ser <contact@emersion.fr>
* connection: Make wl_closure_print output atomicAlexander Irion2022-03-081-16/+28
| | | | | | When multiple threads are used, output from different threads was intermixed in one line. That what breaking parsing of the log messages. Now, intermixing is prevented by using a memstream. Signed-off-by: Alexander Irion <alexander_irion@mentor.com>
* Use zalloc for structsSimon Ser2022-02-055-14/+14
| | | | | | | | When allocating memory for structs, use zalloc instead of malloc. This ensures the memory is zero-initialized, and reduces the risk of forgetting to initialize all struct fields. Signed-off-by: Simon Ser <contact@emersion.fr>
* meson: override dependencies to ease use as subprojectSimon Ser2021-12-081-0/+8
| | | | | | | | | | | | | Make it easier to use Wayland as a Meson subproject by overriding dependencies we define. This allows to easily build Wayland as a subproject like so: subproject('wayland', required: false, default_options: ['documentation=false']) After this statement, the wayland-* dependencies will use the subproject instead of the system if available. Signed-off-by: Simon Ser <contact@emersion.fr>
* wayland-shm: Check the size of sealed memory if ignoring SIGBUS handlersDuncan McIntosh2021-11-041-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | In 11623e8f, SIGBUS handlers aren't set if F_SEAL_SHRINK is configured on the memory. This helps avoid setting up handlers with cooperative clients; however, if an application gives an incorrect size, the compositor would access it anyways, figuring SIGBUS is impossible, and crash. This can be fixed by simply removing the seal-checking logic and always setting the signal handler. However, it seems that fstat can give the size of the memfd, so we can check that the size we were told is within the region. Since it's sealed to shrinking, it must never be shrunk in future, so we can really (hopefully) ignore SIGBUS. I was worried that fstat wasn't supported for this, but shm_overview(7) does mention that it is a possible use. The best solution would likely be avoiding SIGBUS entirely with MAP_NOSIGBUS, but that hasn't been merged yet and wouldn't help systems without it (e.g. with older kernels). A proof-of-concept of this crash is attached with the merge request. Running it with this patch gives an invalid-shm error, which is correct. Signed-off-by: Duncan McIntosh <duncan82013@live.ca>
* debug: Fix printing of new idsDerek Foreman2021-11-024-9/+29
| | | | | | | | | | | | | | | The client side closure traces have incorrect object ids for new server generated objects. This is because create_proxies() overwrites the id in 'n' type arguments by storing a pointer to the actual object in the 'o' field of the union. Getting back to an id from this pointer requires accessing a structure that isn't visible outside of wayland-client.c. Add a function pointer to fish the correct value out of the argument and pass it to wl_closure_print. Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
* build: Include the Wayland minor version in libraries' ABI versionsSimon McVittie2021-10-281-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ABI of a shared library on Linux is given by a major version, which is part of the SONAME and is incremented (rarely) on incompatible changes, and a minor version, which is part of the basename of the regular file to which the SONAME provides a symlink. Until now, the ABI minor version was hard-coded, which means we can't tell which of a pair of Wayland libraries is newer (and therefore likely to have more symbols and/or fewer bugs). libwayland-egl already had ABI major version 1, so we can use the "marketing" version number as the ABI major.minor version number directly, so Wayland 1.19.90 would produce libwayland-egl.so.1 -> libwayland-egl.so.1.19.90. libwayland-cursor and libwayland-server have ABI major version 0, and OS distributions don't like it when there's a SONAME bump for no good reason, so use their existing ABI major version together with the "marketing" minor version: libwayland-cursor.so.0 -> libwayland-cursor.so.0.19.90. If the Wayland major version number is incremented to 2, we'll have to rethink this, so add some error() to break the build if/when that happens. Assuming that Wayland 2.0 would involve breaking changes, the best way would probably to bump all the SONAMEs to libwayland-foo.so.2. Resolves: https://gitlab.freedesktop.org/wayland/wayland/-/issues/175 Signed-off-by: Simon McVittie <smcv@collabora.com>
* client: handle fcntl error on bad fd in wl_display_connectManuel Stoeckl2021-10-281-1/+3
| | | | | | | | This makes wl_display_connect fail immediately instead of succeeding when the integer provided by WAYLAND_SOCKET does not refer to a valid file descriptor. Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
* server: stop wl_display event loop from any contextDamian Hobson-Garcia2021-10-091-0/+44
| | | | | | | | | | | | | | | | | | | Calling wl_display_terminate() will exit the wl_display event loop at the start of the next loop iteration. This works fine when wl_display_terminate() is called after the event loop wakes up from polling on the added event sources. If, however, it is called before polling starts, the event loop will not exit until one or more event sources trigger. Depending on the types of event sources, they may never trigger (or may not trigger for a long time), so the event loop may never exit. Add an extra event source to the wl_display event loop that will trigger whenever wl_display_terminate() is called, so that the event loop will always exit. Fixes #201 Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
* shm: Relax shm_pool_create_buffer() validity checkOlivier Fourdan2021-09-161-1/+1
| | | | | | | | | | | | | | shm_pool_create_buffer() can raise a false WL_SHM_ERROR_INVALID_STRIDE error under some circumstances because of integer division. Fix this by using a strict comparison operator instead of lower or equal. Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Reviewed-by: Demi Marie Obenour <demi@invisiblethingslab.com> Reviewed-by: Simon Ser <contact@emersion.fr> Reviewed-by: Jonas Ådahl <jadahl@gmail.com> Closes: https://gitlab.freedesktop.org/wayland/wayland/-/issues/235
* Detect FreeBSD versions with broken MSG_CMSG_CLOEXECAlex Richardson2021-09-101-1/+10
| | | | | | | | If we are compiling against a version of FreeBSD where MSG_CMSG_CLOEXEC does not work, use the fallback directly. This was only fixed recently (in https://cgit.freebsd.org/src/commit/?id=6ceacebdf52211). Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
* shm: Add mmap+memmove fallback if mremap() does not existAlex Richardson2021-09-103-9/+73
| | | | | | | | | | Some operating systems (e.g. FreeBSD) do not implement mremap. In that case we can grow the mapping by trying to map adjacent memory. If that fails we can fall back to creating a new larger mapping and moving the old memory contents there. Co-authored-by: Koop Mast <kwm@rainbow-runner.nl> Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
* Support reading ucred from the socket on FreeBSDAlex Richardson2021-09-103-10/+61
| | | | | | | | | On FreeBSD we have to use getsockopt(fd, SOL_LOCAL, LOCAL_PEERCRED) instead. This change is based on a downstream patch in FreeBSD ports. Co-authored-by: Greg V <greg@unrelenting.technology> Co-authored-by: Koop Mast <kwm@rainbow-runner.nl> Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
* Use epoll-shim to emulate epoll(7) on FreeBSDAlex Richardson2021-09-101-2/+4
| | | | | | | | FreeBSD does not provide epoll(7) and instead requires an external library, epoll-shim, that implements epoll() using kqueue(2) Co-authored-by: Jan Beich <jbeich@FreeBSD.org> Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
* connection: Rename wl_bufferDerek Foreman2021-08-091-27/+27
| | | | | | | | | | | | | | struct wl_buffer has other meaning in wayland, thus making this a pretty confusing structure name. Function names like wl_buffer_put() just compound the confusion. Rename the struct and the associated functions (none of which are called from outside this file anyway). The struct retains a wl_ prefix, as is the custom for wayland internal data structures. The function names have not retained this prefix, as we have many static function that aren't prefixed. Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
* scanner: Use the new atomic marshal/destroy functionDerek Foreman2021-08-071-33/+30
| | | | | | | | | | | | | | | | Use the new flagged marshal+destroy function in generated code. It's intended as a replacement for all existing wl_proxy_marshal_* functions, so I've used it to replace them all. This results in a large update to the scanner test files as well. We now pass the new WL_MARSHAL_FLAG_DESTROY flag when appropriate, so the race condition in #86 caused by releasing the display mutex between marshalling the proxy and destroying the proxy is now gone. Fixes #86 Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
* client: Add new proxy marshalling functions with flagsDerek Foreman2021-08-072-2/+105
| | | | | | | | | | | | | | | | | There's a race when destroying wayland objects in a multi-threaded client. This occurs because we call: wl_proxy_marshal(foo); wl_proxy_destroy(foo); And each of these functions takes, and releases, the display mutex. Between the two calls, the display is not locked. In order to allow atomically marshalling the proxy and destroying the proxy without releasing the lock, add yet more wl_proxy_marshal_* functions. This time add flags and jam in all existing warts with the hope that we can make it future proof this time. Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
* client: Refactor wl_proxy_destroy critical sectionDerek Foreman2021-08-071-4/+17
| | | | | | | | | | | | | | | Split wl_proxy_destroy into two pieces, wl_proxy_destroy_unlocked which performs the critical section code with no locking, and wl_proxy_destroy which locks before calling that. We'll use the new unlocked variant later in code that already holds the lock. There is a slight functional change - an aborting check is now called with the lock held. This should be harmless as wl_abort() performs no locking. Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
* connection: print array sizeSimon Ser2021-07-311-1/+1
| | | | | | | This makes it easier to understand how an xdg_toplevel is configured for instance. Signed-off-by: Simon Ser <contact@emersion.fr>
* connection, client: Avoid locale-dependent float printingManuel Stoeckl2021-07-312-6/+15
| | | | | | | | | | | | | Specifically, in the log formed when WAYLAND_DEBUG is set, this commit ensures that floating point numbers are formatted using '.' instead of the locale-specific decimal separator. As the debug logs are not otherwise localized for end-users, and may be parsed by scripts, it is better to have consistent output here. The 24.8 fixed point numbers are now represented with 8 digits after the decimal, since this is both exact and simpler to compute. Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
* server: Fix undefined behavior in wl_socket_init_for_display_nameFergus Dall2021-07-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | This function constructs a socket path in sun_path using snprintf, which returns the amount of space that would have been used if the buffer was large enough. It then checks if this is larger then the actual buffer size and, if so, returns ENAMETOOLONG. This is correct. However, after calling snprintf and before checking that the length isn't too long, it tries to compute a pointer to the part of the path that matches the input name. It does this by adding the computed path length to the pointer to the start of the path buffer, which will take it to one-past the null terminator, and then walking backwards. If the path fits in the buffer, this will take it at most one-past-the-end of the allocation, which is allowed, but if the path is longer then the buffer then the pointer addition is undefined behavior. Fix this by moving the display name computation past the check that the path length is not too long. This is detected by the test socket_path_overflow_server_create under ubsan. Signed-off-by: Fergus Dall <sidereal@google.com>
* util: Avoid undefined behaviour in for_each_helperFergus Dall2021-07-211-6/+9
| | | | | | | | | | | | | | | | | for_each_helper tries to calculate a one-past-the-end pointer for its wl_array input. This is fine when the array has one or more entries, but we initialize arrays by setting wl_array.data to NULL. Pointer arithmetic is only defined when both the pointer operand and the result point to the same allocation, or one-past-the-end of that allocation. As NULL points to no allocation, no pointer arithmetic can be performed on it, not even adding 0, even if the result is never dereferenced. This is caught by clang's ubsan from version 10. Many tests already hit this case, but I added an explicit test for iterating over an empty wl_map. Signed-off-by: Fergus Dall <sidereal@google.com>
* client: print discarded events in debug logManuel Stoeckl2021-07-204-9/+29
| | | | | | | | | | | | | | | | | | | | | | | | Before this patch, setting WAYLAND_DEBUG=1 or WAYLAND_DEBUG=client made a program log all requests sent and events that it processes. However, some events received are not processed. This can happen when a Wayland server sends an event to an object that does not exist, or was recently destroyed by the client program (either before the event was decoded, or after being decoded but before being dispatched.) This commit prints all discarded messages in the debug log, producing lines like: [1234567.890] discarded [unknown]@42.[event 0](0 fd, 12 byte) [1234567.890] discarded wl_callback@3.done(34567) [1234567.890] discarded [zombie]@13.[event 1](3 fd, 8 byte) The first indicates an event to an object that does not exist; the second, an event to an object that was deleted after decoding, but before dispatch; the third, an event to an object that left a 'zombie' marker behind to indicate which events have associated file descriptors. Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
* wayland-util: avoid memcpy(NULL) in wl_array_copy()Pekka Paalanen2021-07-141-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | The problem was found running Weston, with both Weston and Wayland built with ASan: ../../git/wayland/src/wayland-util.c:150:2: runtime error: null pointer passed as argument 1, which is declared to never be null ../../git/wayland/src/wayland-util.c:150:2: runtime error: null pointer passed as argument 2, which is declared to never be null This turns out to be caused by copying an empty array into an empty array. That seems to be completely valid thing to do, and wl_array_init() initializes the pointers to NULL and size to zero. Copying initialized arrays must always be valid. The error are caused by calling memcpy() with NULL pointers. It doesn't explode, because also the size is zero. Fix the problem by calling memcpy() only if size is not zero. This should keep things like copying an empty array into a non-empty array work. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
* shm: document wl_shm_bufferSimon Ser2021-07-131-0/+9
| | | | | | | The main motivation is to make it clear when a wl_shm_buffer is destroyed. Signed-off-by: Simon Ser <contact@emersion.fr>
* scanner: Use descriptions in entriesJames Legg2021-07-071-1/+16
| | | | | | | | | | | | | | | entry may have a description according to the DTD. This is used in some protocols including xdg-shell. Fixes the code comment on an enum declaration using the description of the last enum that had one, adds the descriptions to the comments on enumerators, and avoids leaking the previously missing descriptions. Fixes #208 Signed-off-by: James Legg <lankyleggy@gmail.com> Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
* shm: add safety assertionsSimon Ser2021-06-291-1/+3
| | | | | | | | | | Catch any API mis-use with an assert. This should abort when the user calls unreferences the pool more times than it's referenced. Also change the refcount check to explicitly check for positive counts. That makes the condition more readable. Signed-off-by: Simon Ser <contact@emersion.fr>