Commit graph

381 commits

Author SHA1 Message Date
U. Artie Eoff
f97df69ee2 shm: assert sigbus_data is not NULL before member access
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-01-15 10:46:08 -08:00
chi ding
c102c20f01 Fix buffer overflow when serializing a closure object
Here is the JIRA page of this issue
https://bugs.tizen.org/jira/browse/TIVI-1889

Change-Id: I773a6d2d8f6fd02ff10c92450db1fa8a69544219
Signed-off-by: Chi Ding <chi.ding@mobica.com>
Closes: https://bugs.freedesktop.org/show_bug.cgi?id=65186
2014-01-09 14:27:52 -08:00
Adrian Negreanu
cd0dccd01e scanner: set errno=0 before strtol
POSIX says to set errno=0 before calling strtol since
the return value alne cannot tell a failure.

on ubuntu armel I get:

  ../src/wayland-scanner client-header < ../../protocol/wayland.xml > wayland-client-protocol.h
  <stdin>:1188: error: invalid integer (2)

Signed-off-by: Adrian Negreanu <adrian.m.negreanu@intel.com>
2013-12-17 10:57:52 -08:00
Kristian Høgsberg
1a58c7f211 client: Handle EINTR in wl_display_dispatch_queue()
Restart the poll() if we take a signal.  This is easily triggered in
an application that ends up blocking in eglSwapBuffers(), and causes EGL
to fail to allocate a back buffer.
2013-12-09 16:19:33 -08:00
Jonas Ådahl
09877f3231 doc: Fix spelling of parameters
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-12-09 15:50:01 -08:00
Jonas Ådahl
c30208f0b7 doc: Remove incorrect docmentation
The documentation was about wl_client_get_object(), not about
wl_resource_get_client().

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-12-09 15:43:04 -08:00
Neil Roberts
1521c62a31 client: Make wl_proxy_set_queue() with NULL revert to default queue
This will be useful in order to implement the
EGL_WL_create_wayland_buffer_from_image extension. The buffers created
within Mesa's Wayland platform are created using the the wl_drm object
as a proxy factory which means they will be set to use Mesa's internal
event queue. However, these buffers will be owned by the client
application so they ideally need to use the default event loop. This
function provides a way to set the proxy's event queue back to the
default.

krh: Edited from Neils original patch to just use wl_proxy_set_queue() with
a NULL argument instead of introducing a new function.
2013-12-04 17:01:01 -08:00
Kristian Høgsberg
5a019e38a1 Add -pthread to AM_CFLAGS to do the right thing when using threads
https://bugs.freedesktop.org/show_bug.cgi?id=71633
2013-11-23 12:24:43 -08:00
Lubomir Rintel
360dca517a connection: Error out if file descriptor was not received
Otherwise the tail of fds_in buffer would just shift beyond the beginning.
That confuses the actual request handler and results in a crash further on
due to corrupted tail.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
2013-11-21 22:01:48 -08:00
Jasper St. Pierre
40d057f2c9 wayland-server: Improve error messages for bad globals
A bug in Weston's toytoolkit gave me an hour of debugging headaches.
Improve the error messages that we send if a client requests an invalid
global, either by name or by version.
2013-11-19 13:26:32 -08:00
Kristian Høgsberg
853c24e699 client: Introduce functions to allocate and marshal proxies atomically
The server requires clients to only allocate one ID ahead of the previously
highest ID in order to keep the ID range tight.  Failure to do so will
make the server close the client connection.  However, the way we allocate
new IDs is racy.  The generated code looks like:

  new_proxy = wl_proxy_create(...);
  wl_proxy_marshal(proxy, ... new_proxy, ...);

If two threads do this at the same time, there's a chance that thread A
will allocate a proxy, then get pre-empted by thread B which then allocates
a proxy and then passes it to wl_proxy_marshal().  The ID for thread As
proxy will be one higher that the currently highest ID, but the ID for
thread Bs proxy will be two higher.  But since thread B prempted thread A
before it could send its new ID, B will send its new ID first, the server
will see the ID from thread Bs proxy first, and will reject it.

We fix this by introducing wl_proxy_marshal_constructor().  This
function is identical to wl_proxy_marshal(), except that it will
allocate a wl_proxy for NEW_ID arguments and send it, all under the
display mutex.  By introducing a new function, we maintain backwards
compatibility with older code from the generator, and make sure that
the new generated code has an explicit dependency on a new enough
libwayland-client.so.

A virtual Wayland merit badge goes to Kalle Vahlman, who tracked this
down and analyzed the issue.

Reported-by: Kalle Vahlman <kalle.vahlman@movial.com>
2013-11-15 20:49:36 -08:00
Lubomir Rintel
4a196570a3 shm: Avoid file descriptor leak upon unsuccessful mmap
It would be possible to make the compositor leak file descriptors by
passing descriptors of open unmmapable files to it, such as /dev/null.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
2013-11-15 16:21:45 -08:00
Neil Roberts
c2bba88ccd Add documentation for wl_shm_buffer_begin/end_access
It's not obvious that these functions are needed so it would be good
to have some documentation for them.
2013-11-15 14:46:48 -08:00
Kristian Høgsberg
a71cf48ce0 scanner: Add location to elements so we can give better errors/warnings 2013-11-15 14:44:39 -08:00
Kristian Høgsberg
5a4dd76495 scanner: Make fail() function use va_list and elaborate a few errors 2013-11-15 14:44:39 -08:00
Kristian Høgsberg
db8ae8903f scanner: Introduce struct location for tracking source locations 2013-11-15 14:44:39 -08:00
Kristian Høgsberg
3470fa17b5 scanner: Warn about requests with more than one new-id and don't generate stubs
The generated code only support one new-id per request, since the stubs
return the new proxy.  It's still possible to send requests with multiple
new-id arguments, but it must be done with
wl_proxy_marshal_array_constructor().
2013-11-15 14:44:39 -08:00
Kristian Høgsberg
b583b54560 server: Start documenting the server side API
This is now public, stable API, so it seems prudent to actually document it.
2013-11-13 21:11:17 -08:00
Neil Roberts
cf4f5995dc server: Add API to protect access to an SHM buffer
Linux will let you mmap a region of a file that is larger than the
size of the file. If you then try to read from that region the process
will get a SIGBUS signal. Currently the clients can use this to crash
a compositor because it can create a pool and lie about the size of
the file which will cause the compositor to try and read past the end
of it. The compositor can't simply check the size of the file to
verify that it is big enough because then there is a race condition
where the client may truncate the file after the check is performed.

This patch adds the following two public functions in the server API
which can be used wrap access to an SHM buffer:

void wl_shm_buffer_begin_access(struct wl_shm_buffer *buffer);
void wl_shm_buffer_end_access(struct wl_shm_buffer *buffer);

The first time wl_shm_buffer_begin_access is called a signal handler
for SIGBUS will be installed. If the signal is caught then the buffer
for the current pool is remapped to an anonymous private buffer at the
same address which allows the compositor to continue without crashing.
The end_access function will then post an error to the buffer
resource.

The current pool is stored as part of some thread-local storage so
that multiple threads can safely independently access separate
buffers.

Eventually we may want to add some more API so that compositors can
hook into the signal handler or replace it entirely if they also want
to do some SIGBUS handling.
2013-11-13 16:31:28 -08:00
Kristian Høgsberg
deddea6549 wayland: Be consistent about #include-guard names
We had a mix of inconsistent names, some of which were non-conformant.
Standardize on all-uppercase-and-underscore naming convention.

https://bugs.freedesktop.org/show_bug.cgi?id=70679
2013-10-21 14:39:06 -07:00
Kristian Høgsberg
bb6f6faaa2 scanner: Handle unrecognized invocation mode
Print usage if we don't recognize the invocation mode.  Also fixes
uninitialized variable warning.
2013-10-07 21:36:31 -07:00
Neil Roberts
799ea7206b client: Fix handling display->reader_count if poll fails
In wl_display_dispatch_queue, if poll fails then it would previously
return immediately and leak a reference in display->reader_count. Then
if the application ignores the error and tries to read again it will
block forever. This can happen for example if the poll fails with
EINTR which the application might consider to be a recoverable error.
This patch makes it cancel the read so the reader_count will be
decremented when poll fails.
2013-09-25 10:11:20 -07:00
Jason Ekstrand
ba90497b87 Export the Wayland protocol XML file
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-09-21 21:48:56 -07:00
Chang Liu
5cf31443c5 client: fix an inconsistency in documentation
The errno is set to EAGAIN when there are undispatched events, according
to L1066 of wayland-client.c.
2013-09-21 11:34:57 -07:00
Aaron Faanes
5a92553237 doc: Slight tweaks to wl_listener
Prefer \comment over // in code blocks for consistency's sake and keep
variable definitions separated by a line from the rest of the body.
2013-09-21 11:31:50 -07:00
Aaron Faanes
8267f283dc utils: Document wl_container_of 2013-09-21 11:31:41 -07:00
Aaron Faanes
5197aa30c8 wayland-server: Improve wording for wl_signal_get's doc
The old description was a bit vague; this commit hopefully improves
describing what is returned.
2013-09-16 21:59:28 -07:00
Aaron Faanes
fffcdb25de utils: Add doxygen for wayland-util.h
This is needed for doxygen to generate output for macro definitions, such
as wl_container_of, that are contained by this file. Classes like
wl_list would be documented regardless.
2013-09-16 21:59:12 -07:00
Aaron Faanes
bc30c5eb8a utils: Reference some useful methods in wl_signal's doxygen
This commit adds a bit more detail on the lifecycle of a signal.
2013-09-16 21:59:00 -07:00
Aaron Faanes
f8b2730039 wayland-server: Document wl_listener
This patch takes Kristian's comments into account, adding a demonstration and
giving a more thorough idea of how wl_listener is used.
2013-09-16 21:47:52 -07:00
Rob Bradford
656f3ea5b3 wayland-server: Add a wl_resource_for_each_safe macro
A version of wl_resource_for_each that is safe for iteration when items
in the list are removed.
2013-09-11 12:03:22 -07:00
Aaron Faanes
a27b730490 utils: tweak wl_list for better doxygen output 2013-09-11 10:53:39 -07:00
Aaron Faanes
660f2d7acc wayland-server: Document wl_signal 2013-09-11 10:52:41 -07:00
Aaron Faanes
cdea669858 wayland-server: Fix a uninitialized warning from clang
This warning is unnecessary, since the pointer in question is only used
for pointer arithmetic, but setting it explicitly to NULL doesn't hurt.
2013-09-11 10:42:37 -07:00
Kristian Høgsberg
b76a6968fc scanner: Emit wl_*_destroy stub even if interface has a destructor
If an interface has a destructor but no 'destroy' method we used to
not emit a destroy method.  Now with the fix for missing destroy
requests for wl_pointer etc we need to emit the local wl_*_destroy
always.
2013-08-30 15:53:55 -07:00
Jason Ekstrand
eb947e9408 Add support for client-side language bindings
This commit adds support for language bindings on the client half of the
library.  The idea is the same as for server-side dispatchers.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-08-19 16:23:08 -07:00
Jason Ekstrand
c44090908d Add support for server-side language bindings
This commit adds support for server-side languages bindings.  This is done
in two ways:

1. Adding a wl_resource_set_dispatcher function that corresponds to
wl_resource_set_interface.  The only difference between the two functions
is that the new version takes a dispatcher along with the implementation,
data, and destructor.  This allows for runtime calling of native language
functions for callbacks instead of having to generate function pointers.

2. Adding versions of wl_resource_post_event and wl_resource_queue_event
that take an array of wl_argument instead of a variable argument list.
This allows for easier run-time argument conversion and removes the need
for libffi-based calling of variadic functions.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-08-19 16:23:08 -07:00
Rob Bradford
4ad58fbb4a wayland-client: Add wl_proxy_get_listener
This is the mirror function to wl_proxy_add_listener and is useful
inside client libraries to differentiate events on listeners for which
multiple proxies have been created.
2013-08-12 16:26:36 -07:00
Rob Bradford
748c20c46f wayland-server: Add a wl_resource_for_each macro
This macro allows you to correctly iterate through a list of resources
handling the opaque nature of this type.
2013-08-12 16:26:36 -07:00
Bryce W. Harrington
65efa2ed3a client: Improve spelling and grammar in comments
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
2013-08-08 21:41:33 -07:00
Tomeu Vizoso
f26a322327 server: Release additional_shm_formats array at display destruction 2013-08-08 13:51:13 -07:00
Peter Hutterer
2b26edb877 scanner: expand help string
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-07 16:24:55 -07:00
Peter Hutterer
2d1ed470d9 scanner: support help and --help
wayland-scanner without arguments prints out usage. With help or --help it
waits for stdin to supply something which isn't quite as informative as
printing out the help.

This patch also moves the strcmp for args up to have all of them in one
location.
2013-08-07 16:24:44 -07:00
Kristian Høgsberg
81555350af Don't include wayland-server.h in wayland-private.h
We just declare struct wl_display manually instead.
2013-08-07 09:17:24 -07:00
Tomeu Vizoso
d9883a6be1 shm: Add API for renderers to register additional pixel formats 2013-08-06 16:48:02 -07:00
Kristian Høgsberg
dbeb5134fa server: Set client->error when we fail to send a closure
We we're using wl_event_loop_add_idle() here, but if we're failing
because of OOM, that will typically also fail.  Instead, use the
existing client->error flag, which will break out of the event
handling loop and shut down the client.
2013-08-06 10:16:46 -07:00
Kristian Høgsberg
1b0cabfc48 server: Handle OOM properly when we fail to allocate a send closure
If we can't allocate a closure, don't just silently continue.  Set
client->error so we shut down the client when we're done processing events.
2013-08-06 09:51:53 -07:00
Jiergir Ogoerg
c1fd097cd9 client: Simply wl_display_dispatch_queue_pending() and fix return value
We're supposed to return number of events dispatched on success, not 0.
Refactor to avoid goto and just return ret.
2013-07-29 16:50:44 -07:00
Kristian Høgsberg
e0579bfb61 wayland-client: Handle potential NULL-deref
Instead, return -1 on out-of-memory.  errno will be set to ENOMEM by
the failing malloc.
2013-07-13 00:42:14 -04:00
Kristian Høgsberg
8bd93c5c9d scanner: Fail more gracefully on out-of-memory
Failing with an error message and error code is little nicer.  I doubt we'll
hit this case much, but it makes the static analysis happy.
2013-07-13 00:35:21 -04:00