Commit Graph

2397 Commits

Author SHA1 Message Date
Joshua Watt
4a1f348c20 scanner: Add configure check for strndup
Some platforms may not have strndup() (e.g. MinGW), so provide a
equivalent implementation if it's not found.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
2019-11-05 08:59:58 -06:00
Jiayuan Ren
8e0513410d adding O_RDWR flag in the open()
According to the manual of open:
"The argument flags must include one of the following access modes:
O_RDONLY, O_WRONLY, or O_RDWR."
2019-10-24 22:31:56 +00:00
Simon Ser
4162863c41
tests: add a test for wl_global_remove
This test makes sure that after wl_global_remove:

* The global_remove event is sent to existing clients
* Binding to the removed global still works
* A new client will not see the removed global advertised

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-10-16 16:33:53 +03:00
Simon Ser
39852f1146
server: add wl_global_remove
This commit adds a new wl_global_remove function that just sends a global
remove event without destroying it. See [1] for details.

Removing a global is racy, because clients have no way to acknowledge they
received the removal event.

It's possible to mitigate the issue by sending the removal event, waiting a
little and then destructing the global for real. The "wait a little" part is
compositor policy.

[1]: https://gitlab.freedesktop.org/wayland/wayland/issues/10

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-10-16 16:32:17 +03:00
Emmanuel Gil Peyrot
11623e8fdd wayland-shm: Don’t set SIGBUS handlers on unshrinkable fd
If a client set the F_SEAL_SHRINK seal on the fd before passing it to
the compositor, the kernel will ensure this fd won’t be able to shrink,
ever.  This allows us to avoid setting up the SIGBUS handlers on such
file descriptors.

Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2019-10-14 21:49:08 +00:00
Simon Ser
d5055ad913 server: add wl_global_set_user_data
When implementing a workaround for [1], one needs to accept a global to be
bound even though it has become stale.

Often, a global's user data is free'd when the global needs to be destroyed.
Being able to set the global's user data (e.g. to NULL) can help preventing a
use-after-free.

(The alternative is to make the compositor responsible for keeping track of
stale user data objects via e.g. refcounting.)

[1]: https://gitlab.freedesktop.org/wayland/wayland/issues/10

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-09-27 09:14:52 +00:00
Mosè Giordano
766edf0243 Add $(RT_LIBS) to fixed-benchmark LD dependencies
`tests/fixed-benchmark.c` calls `clock_gettime`.
2019-09-17 16:38:28 +01:00
Marty E. Plummer
9f004d8b0f
scanner: prepend protocol name to types symbol
When doing unity builds via meson (example project:
https://github.com/swaywm/sway) multiple source files are glued together
via #include directives. Having every wayland-scanner generated source
file have an identifier named '*types[]' will lead to errors in these
unity builds if two or more of these are joined.

Signed-off-by: Marty E. Plummer <hanetzer@startmail.com>
2019-09-11 13:27:03 -05:00
Manuel Stoeckl
a89a5349af tests: Test that send overflow doesn't abort
The new display test runs a client that makes a very large number of
trivial requests. After responding to initial setup requests, the server
is paused, letting the trivial requests fill up the Unix socket buffer,
making further writes to the socket fail. The test then checks that the
client sets an appropriate error code, and does not abort or crash.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2019-09-10 07:59:50 -04:00
Manuel Stoeckl
8a831ac6ec client: Don't abort when sending a request fails
Instead, set a fatal display error which will let an application
using libwayland-client shutdown cleanly.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2019-09-10 07:59:50 -04:00
Manuel Stoeckl
6265dd4f07 client: Ignore new requests if display has a fatal error
Once there has been a fatal display error, any new object requests
potentially rely on invalid state. (For example, a failure to read
from the compositor could hide a important event.) The safest way to
handle the new requests is not to make them.

Proxies produced by the request are still created, to ensure that
any code using the library does not crash from an unexpected NULL
pointer.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2019-09-10 07:59:50 -04:00
Simon Ser
4c2b737561 protocol: invalid_method is sent on malformed request
Currently libwayland sends a wl_display.invalid_method when arguments provided
with a request are invalid (e.g. too short, see wl_client_connection_data).

Clarify the protocol by adding that invalid_method can be sent on malformed
request.

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-09-10 09:47:19 +00:00
Simon Ser
6e5cedc20a tests: test that binding to a global with an interface mismatch fails
This test creates a wl_seat global, then tries to bind to it with the wl_output
interface.

Signed-off-by: Simon Ser <simon.ser@intel.com>
2019-09-06 12:22:01 +00:00
Simon Ser
e18e3e195b server: check global interface on bind
The interface name provided by the client isn't used at all.

Check it matches the global's interface name to prevent object interface
mismatches between the client and the server. These are especially easy to get
when mixing up global names and other IDs in the client.

Signed-off-by: Simon Ser <simon.ser@intel.com>
Closes: https://gitlab.freedesktop.org/wayland/wayland/issues/113
2019-09-06 12:22:01 +00:00
Simon Ser
b69e547fa4 protocol: sync wl_shm.format with libdrm 2.4.99
This adds 42 new formats.

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-09-06 12:09:22 +00:00
Simon Ser
e771ca91d7 protocol: add a comment about the wl_shm.format script
Add a comment to wl_shm.format to advise contributors to use the automated
script (generate-shm-formats.py) instead of updating the list manually.

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-09-06 12:09:22 +00:00
Simon Ser
8854f64bae Add an automated script to update wl_shm.format
This prevents mismatches and missing formats between wl_shm.formats and
drm_fourcc.h.

The script collects DRM_FORMAT_* constants from drm_fourcc.h, compares the list
with the current wayland.xml entries (checking for any mismatch) and then
appends missing entries to wayland.xml.

Enum values are obtained by executing a generated C file which prints the
constants. There is no other reliable way to get these values as they are
defined via various macros.

There is no widespread Python library able to parse an XML file and format it
with all whitespace preserved. For this reason, we don't use an XML library to
create the new XML elements. Instead, we keep track of the line number of the
last wl_shm.format enum entry and add new entries right after. To be able to
read the line number of an element, we use lxml (the standard library doesn't
retain line number information).

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-09-06 12:09:22 +00:00
Simon Ser
cd9b3ef0cd Update .editorconfig for Python
This uses the idiomatic Python indentation rules.

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-09-06 12:09:22 +00:00
Simon Ser
a277cc6d52 client: check event opcode in queue_event
If the client binds to a global with an interface mismatch, it may receive an
event from the server with an unknown opcode. See [1].

Instead of crashing, print a more useful debug message and close the connection.

[1]: https://gitlab.freedesktop.org/wayland/wayland/issues/113

Signed-off-by: Simon Ser <simon.ser@intel.com>
2019-09-05 11:01:12 +00:00
Liu Wenlong
152c9ed968 server: Fix fake "Address already in use" error
In the current workflow, socket file will be deleted if it already exists.
However, if the socket file is a symbolic link and the file that it refers
to doesn't exist, we will got "Address already in use" because bind()
thinks the socket file exists and won't create it.

Now, use lstat() to determine whether the socket file exists.

Signed-off-by: Liu Wenlong <liuwl.fnst@cn.fujitsu.com>
2019-08-27 01:32:45 +08:00
Drew DeVault
17e49ba844 Improve description of wl_surface
The original text makes some assumptions about surfaces which may not be
true and fails to capture some details which are important to the
essential traits of a wl_surface.
2019-08-17 11:12:54 +00:00
Drew DeVault
790dd9da16 Add .editorconfig
This is copied from Weston
2019-08-05 08:43:45 +00:00
Drew DeVault
a2f1343b7e Document unusual wl_registry.bind new_id behavior
When wayland-scanner encounters a new_id field with no corresponding
interface name defined, instead of emitting a function whose signature
lines up with the usual case (a uint32_t ID), it adds the interface name
as a string and the version number so that the interface can be
identified from the protcol message.

Without docs, this was previously left for the interprid wire protocol
implementor (e.g. me an hour ago) to discover when Wayland clients send
them apparently bogus messages.

I would have preferred if a different primitive type were used here
(e.g. typed_new_id) to reflect the fact that the wire protocol is
different, but I felt it unwise to add a new primitive to wayland.xml in
$current_year.
2019-07-30 07:32:29 -04:00
Jonas Ådahl
493ab79bd2 proxy: Add API to tag proxy objects
When an application and a toolkit share the same Wayland connection,
it will receive events with each others objects. For example if the
toolkit manages a set of surfaces, and the application another set, if
both the toolkit and application listen to pointer focus events,
they'll receive focus events for each others surfaces.

In order for the toolkit and application layers to identify whether a
surface is managed by itself or not, it cannot only rely on retrieving
the proxy user data, without going through all it's own proxy objects
finding whether it's one of them.

By adding the ability to "tag" a proxy object, the toolkit and
application can use the tag to identify what the user data pointer
points to something known.

To create a tag, the recommended way is to define a statically allocated
constant char array containing some descriptive string. The tag will be
the pointer to the non-const pointer to the beginning of the array.

For example, to identify whether a focus event is for a surface managed
by the code in question:

	static const char *my_tag = "my tag";

	static void
	pointer_enter(void *data,
		      struct wl_pointer *wl_pointer,
		      uint32_t serial,
		      struct wl_surface *surface,
		      wl_fixed_t surface_x,
		      wl_fixed_t surface_y)
	{
		struct window *window;
		const char * const *tag;

		tag = wl_proxy_get_tag((struct wl_proxy *) surface);

		if (tag != &my_tag)
			return;

		window = wl_surface_get_user_data(surface);

		...
	}

	...

	static void
	init_window_surface(struct window *window)
	{
		struct wl_surface *surface;

		surface = wl_compositor_create_surface(compositor);
		wl_surface_set_user_data(surface, window);
		wl_proxy_set_tag((struct wl_proxy *) surface,
				 &my_tag);
	}

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2019-07-29 16:47:36 +00:00
Emmanuel Gil Peyrot
6908c8c85a cursor: Use memfd_create() when available
This (so-far) Linux-only API lets users create file descriptors purely
in memory, without any backing file on the filesystem and the race
condition which could ensue when unlink()ing it.

It also allows seals to be placed on the file, ensuring to every other
process that we won’t be allowed to shrink the contents, potentially
causing a SIGBUS when they try reading it.

This patch is best viewed with the -w option of git log -p.

Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Reviewed-by: Simon Ser <contact@emersion.fr>
2019-07-21 09:06:43 +00:00
Manuel Stoeckl
9d63c9ff84 connection: do not abort when dup(fd) fails
Instead, cleanly exit wl_closure_marshal and let the caller handler
the error. For wayland-client, the sole calling function will call
wl_abort() anyway. For wayland-server, the calling function will
cleanly shutdown the client.

This change ensures that compositors run with low file descriptor
limits or internal leaks need not crash suddenly (and sometimes
far from the problem) when space runs out.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2019-07-09 17:30:13 +00:00
Scott Anderson
a281783339 wayland.xml: Make releases for multiple 'wl_surface.attach' undefined
Fixes #46

The way wl_buffer is specified makes this situation inherently racy,
meaning there is no way this can be done unambiguously. Current real
compositor implementations already have differing behaviour for this, so
any client relying on it was already broken, if any such client exists.

This specifically only singles out wl_buffer.release as being undefined;
every other aspect of it should still be valid. This is so existing and
correct uses of multiple attaches are still valid, where a
"static"/immutable wl_buffer is being used (i.e. they don't care about
the release event).

Signed-off-by: Scott Anderson <scott.anderson@collabora.com>
2019-07-09 17:26:11 +00:00
Manuel Stoeckl
6dbf9f72b6 protocol: clarify wl_display.delete_id description
libwayland-server only sends wl_display.delete_id events when
it responds to a client's destruction of a client-allocated
object. server-allocated objects are silently removed, as per
`wl_resource_destroy`.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2019-07-05 19:42:24 -04:00
Michael Forney
678c8681e2 Avoid pointer arithmetic on void *
The pointer operand to the binary `+` operator must be to a complete
object type. Since we are working with byte sizes, use `char *` for
arithmetic instead.

Signed-off-by: Michael Forney <mforney@mforney.org>
2019-06-05 10:01:07 +00:00
Michael Forney
55d044810c Use wl_container_of internally
Rather than have two versions of the macro with slightly different
interfaces, just use wl_container_of internally.

This also removes use of statement expressions, a GNU C extension.

Signed-off-by: Michael Forney <mforney@mforney.org>
2019-06-05 09:58:14 +00:00
orbea
2485a5c274 Add a missing -pthread to fix compile with slibtool.
When compiling wayland with slibtool instead of GNU libtool
it will fail building libtest_runner with an undefined
reference to pthread_join@@GLIBC_2.2.5. This is because
-pthread (Or -lpthread) is missing from display_test. If its
added the build succeeds as expected with slibtool and
continues to work with libtool. Its likely that libtool is
hiding this failure by silently adding the missing flag which
is not uncommon...

Exposed in commit aa51a833eb.

Fixes https://gitlab.freedesktop.org/wayland/wayland/issues/91

Signed-off-by: orbea <orbea@riseup.net>
2019-05-31 08:38:50 -07:00
Antonio Borneo
294ed97e64 log: remove "%m" from format strings by using strerror(errno)
The printf() format specifier "%m" is a glibc extension to print
the string returned by strerror(errno). While supported by other
libraries (e.g. uClibc and musl), it is not widely portable.

In Wayland code the format string is often passed to a logging
function that calls other syscalls before the conversion of "%m"
takes place. If one of such syscall modifies the value in errno,
the conversion of "%m" will incorrectly report the error string
corresponding to the new value of errno.

Remove all the occurrences of the specifier "%m" in Wayland code
by using directly the string returned by strerror(errno).

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
2019-05-02 22:14:53 +02:00
Manuel Stoeckl
6db761d162 tests: Verify that wayland_scanner can catch bad identifiers
The test runs wayland_scanner on a set of XML protocol files which
have malformed element names, and confirms that an error is produced
and indicates the correct line.

Copyright notifications are not included in the test files, as
they are not code; of course, the project license still applies.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2019-05-02 17:42:59 +00:00
Manuel Stoeckl
6ce4bbb3dd scanner: error when element names will not compile
This change checks that the "name" fields of the various structures in
a Wayland protocol XML file will be converted into C identifiers that
can be successfully compiled.

For names which will be inserted as the prefix of an identifier
enforce a match with [_a-zA-Z][_0-9a-zA-Z]* . For types only inserted
as the suffix of an identifier (enum, entry), enforce a format of
[_0-9a-zA-Z]+ .

Unicode characters (and escape sequences like \u0394) are not allowed,
because most older and some newer C compilers do not support them by
default.

For sake of simplicity, this patch does not check for collisions
with reserved words or standard library names.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2019-05-02 17:42:59 +00:00
Simon Ser
3ab56ef8fa protocol: allow to send a zero output refresh rate
Fixed refresh rate doesn't always make sense for all outputs. In case
it's not available or not relevant, allow compositors to send zero.

For instance the can be the case for virtual outputs.

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-04-27 21:44:04 +00:00
Harish Krupo
ea11878d00 wayland.xml: document invalid_finish error in wl_data_offer.finish
Explicitly state that the invalid_finish protocol error would be raised
when wl_data_offer.finish request is sent for non drag-and-drop
operations.

Signed-off-by: Harish Krupo <harishkrupo@gmail.com>
2019-04-19 22:02:08 +05:30
Harish Krupo
b77cf86290 docs: Abort configure if docbook-xsl package is missing
The docbook-xsl package includes all the stylesheets required to build
the docs without internet access.

Test:
One way to emulate missing style sheets is to move /etc/xml/catalog file
to a different location. Doing so should cause configure to fail with
"checking for docbook stylesheets... no"

v2: add AC_MSG_RESULT (Pekka)

Signed-off-by: Harish Krupo <harishkrupo@gmail.com>
2019-04-19 19:34:09 +05:30
Simon Ser
de64489b95
releasing: fixup section numbers
Signed-off-by: Simon Ser <contact@emersion.fr>
2019-04-12 11:31:06 +03:00
Simon Ser
724bf08e2f
releasing: adapt for Wayland
Remove Weston-specific bits, strip off outdated instructions.

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-04-11 19:53:06 +03:00
Simon Ser
b8933d4688
Add releasing.txt
This file is imported from Weston (commit 53d7c243).

Signed-off-by: Simon Ser <contact@emersion.fr>
2019-04-11 19:53:06 +03:00
Pekka Paalanen
ca5a59ec4c configure.ac: reopen master for regular development
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-04-08 10:26:24 +03:00
Leonid Bobrov
dd3ba21457 configure: detect libdl and librt
Signed-off-by: Leonid Bobrov <mazocomp@disroot.org>
2019-04-06 19:53:25 +00:00
Derek Foreman
e091839dd0 configure.ac: bump to version 1.17.0 for the official release 2019-03-20 19:54:18 -05:00
Derek Foreman
cbdfa87ce3 configure.ac: bump version to 1.16.93 for the RC1 release 2019-03-13 21:27:59 -05:00
Derek Foreman
5935332a42 Merge branch 'mr/request-bad-size' into 'master'
Fix demarshal of invalid size in message header

Closes #52

See merge request wayland/wayland!2
2019-03-13 12:18:53 +00:00
Pekka Paalanen
bace3cd819 connection: fix demarshal of invalid header
The size argument to wl_connection_demarshal() is taken from the message by the
caller wl_client_connection_data(), therefore 'size' is untrusted data
controllable by a Wayland client. The size should always be at least the header
size, otherwise the header is invalid.

If the size is smaller than header size, it leads to reading past the end of
allocated memory. Furthermore if size is zero, wl_closure_init() changes
behaviour and leaves num_arrays uninitialized, leading to access of arbitrary
memory.

Check that 'size' fits at least the header. The space for arguments is already
properly checked.

This makes the request_bogus_size test free of errors under Valgrind.

Fixes: https://gitlab.freedesktop.org/wayland/wayland/issues/52

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
2019-03-13 12:39:16 +02:00
Pekka Paalanen
446047edf2 tests: add request_bogus_size
This attempts to reproduce the error conditions from
https://gitlab.freedesktop.org/wayland/wayland/issues/52 and make it crash.
While the crash was repeatable in my tests, it depends on garbage on stack
leading to access of invalid memory, which is not guaranteed.

This is a FAIL_TEST, so that the following fix commit can be verified.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
2019-03-13 12:39:16 +02:00
Pekka Paalanen
808bca8965 contributing: use Gitlab merge request workflow
The experience from Weston shows that the Gitlab merge request based workflow
works really well. Recently there have also been issues with the mailing list
that have made the email based workflow more painful than it used to be. Those
issues might have been temporary or occasional, but they probably are only
going to increase.

The MR workflow is different, it has its issues
(https://gitlab.freedesktop.org/freedesktop/freedesktop/issues/74) and we
likely lose the explicit Reviewed-by etc. tags from commit messages, but it is
also much easier to work with: no more whitespace damaged patches, lost email,
setting up git-send-email; we gain automated CI before any human reviewer even
looks at anything, and people can jump in to an ongoing discussion even if they
weren't subscribed before.

If you still want email, you can subscribe to that selectively(!) in Gitlab
yourself.

This text has been copied from Weston's CONTRIBUTING.md of the 5.0.91 release
and slightly altered for Wayland.

Fixes: https://gitlab.freedesktop.org/wayland/wayland/issues/49

v2: fixed two left-over mentions of Weston

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
v1 Reviewed-by: Simon Ser <contact@emersion.fr>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Scott Anderson <scott.anderson@collabora.com>
Acked-by: Ian Ray <ian.ray@ge.com>
Acked-by: Derek Foreman <derek.foreman.wayland@gmail.com>
2019-03-07 14:35:22 +02:00
Chris Billington
15cba8b074 wayland-util.h: add forward declaration for wl_object
The definition of wl_argument in wayland-util.h references wl_object,
so wl_object ought to be defined in wayland-util.h. This resolves
gitlab issue #78.

Fixes: https://gitlab.freedesktop.org/wayland/wayland/issues/78

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2019-03-07 11:33:26 +02:00
Derek Foreman
75bd70c0b3 configure.ac: bump to version 1.16.92 for the beta release 2019-03-05 17:22:24 -06:00