Commit graph

610 commits

Author SHA1 Message Date
Jason Ekstrand
61ac9c6849 server: Add aditional wl_resource accessors
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-06-14 15:56:08 -04:00
Kristian Høgsberg
bca4124045 server: Add wl_resource_get_id() 2013-06-07 01:00:30 -04:00
Jason Ekstrand
2d586a759e Remove incorrect sanity-check from wl_map_insert_at
I got a little over-eager with my sanity checks and didn't realize that the
client uses wl_map_insert_at to mark objects as zombies when they come from
the server-side.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-06-05 17:45:47 -04:00
Jason Ekstrand
8fd60c683a Change WL_ZOMBIE_OBJECT from 0x2 to an actual pointer
In order to use the second-lowest bit of each pointer in wl_map for the
WL_MAP_ENTRY_LEGACY flag, every pointer has to be a multiple of 4.  This
was a good assumption, except with WL_ZOMBIE_OBJECT.  This commit creates
an actual static variable to which WL_ZOMBIE_OBJECT now points.  Since
things are only every compared to WL_ZOMBIE_OBJECT with "==" or "!=", the
only thing that matters is that it is unique.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-06-05 17:45:36 -04:00
Jason Ekstrand
1488c96a5d Add accessor functions for wl_resource and deprecate wl_client_add_resource
This is the first step towards making wl_resource an opaque pointer type.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-06-05 00:59:08 -04:00
Jason Ekstrand
2c7468b868 Add support for flags in the wl_map API and add a WL_MAP_ENTRY_LEGACY flag
The implementation in this commit allows for one bit worth of flags.  If
more flags are desired at a future date, then the wl_map implementation
will have to change but the wl_map API will not.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-06-05 00:55:17 -04:00
Jason Ekstrand
28472970df Add a "side" field and some sanity checks to wl_map.
The original wl_map implementation did no checking to ensures that ids fell
on the correct side of the WL_SERVER_ID_START line.  This meant that a
client could send the server a server ID and it would happily try to use
it.  Also, there was no distinction between server-side and client-side in
wl_map_remove.  Because wl_map_remove added the entry to the free list
regardless of which side it came from, the following set of actions would
break the map:

1. Client creates a bunch of objects
2. Client deletes one or more of those objects
3. Client does something that causes the server to create an object

Because of the problem in wl_map_remove, the server would take an old
client-side id, apply the WL_SERVER_ID_START offset, and try to use it as a
server-side id regardless of whether or not it was valid.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-06-05 00:33:57 -04:00
Kristian Høgsberg
508dd69b56 server: Drop struct wl_surface
This struct was only defined in the server API for the purpose of the
input structs and helper functions.  Now that those are gone we can dro it.
2013-05-08 09:45:59 -04:00
Kristian Høgsberg
e920572e5c Remove input structs
Looking at the functionality in the server library, it's clear (in
hindsight) that there are two different "things" in there: 1) The IPC
API, that is, everything that concerns wl_display, wl_client,
wl_resource and 2) and half-hearted attempt at sharing input code and
focus logic that leaves a lot of problematic structs in the API
surface, only to share less than 1000 lines of code.

We can just move those input structs and helper functions into weston
and cut libwayland-server down to just the core server side IPC API.
In the short term, compositors can copy those structs and functions
into their source, but longer term, they're probably better off
reimplementing those objects and logic their native framework
(QObject, GObject etc).
2013-05-07 09:10:49 -04:00
Rob Bradford
9fbcc7ae7d wayland-client: Avoid null dereference when handling deletion
If an unknown id is deleted then the lookup in the map will return NULL and
so we should avoid dereferencing that.

As this is unexpected behaviour log a message about the problem too.
2013-04-04 12:39:57 -04:00
Giulio Camuffo
4e9892478b utils: const-ify some function arguments 2013-04-03 12:46:57 -04:00
Rob Bradford
db19b443cc wayland-server: Listen for pointer current surface destruction
Add a destroy listener so that when the current surface associated with the
pointer is destroyed we can reset the pointer to the current surface. In order
to achieve this add a wl_pointer_set_current() which handles assigning the
surface and creating the listener.

This resolves a use-after-free error triggered with nested popup surfaces

Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=696946
2013-04-03 12:46:57 -04:00
Kristian Høgsberg
858fcbde59 docs: Document non-blocking behaviour of wl_display_flush() 2013-04-02 21:31:02 -04:00
Giulio Camuffo
88d873ecb9 server: use void* instead of function pointer for wl_object.implementation
This is needed to make C++ programs that include wayland-server.h build:
C++ does not allow conversions from data pointers to function pointers.
2013-04-02 21:07:07 -04:00
Giulio Camuffo
6ca428edc8 server: use the right function pointer type in wl_signal_get
use the wl_notify_func type, and not void *, or else wl_signal_get
will not be usable by a c++ plugin because it will not cast
void * to a function pointer.
2013-04-02 17:11:44 -04:00
Rob Bradford
8680c67c47 wayland-server: Avoid deferencing a NULL pointer in error case
Reorder the error handling in the case that closure is NULL due to ENOMEM to
ensure that we can safely call wl_closure_lookup_objects on the second test.
Prior to this reordering the closure would be deferenced in the ENOMEM case
due to the invocation of the second half of the logical OR check.
2013-04-01 17:16:29 -04:00
Jason Ekstrand
bedc3432ff Add wl_resource_init and use it in libwayland implementations of data sharing and SHM
This commit adds a wl_resource_init function for initializing wl_resource
structures similar to wl_client_add_object.

From this commit forward, wl_resource structures should not be initialized
manually, but should use wl_resource_init.  In the event of a change to the
wl_resource structure, this allows us to protect against regressions by filling
in added fields with reasonable defaults.  In this way, while changing
wl_object or wl_resource still constitutes an ABI break, compositors following
this rule will only need to be recompiled in order to properly link against the
new version.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-03-18 23:04:32 -04:00
Jason Ekstrand
ca5b1946cb Change wl_closure_invoke to take an opcode instead of an actual function pointer
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-03-18 23:04:32 -04:00
Jonas Ådahl
cb73bffed5 client: Invoke new_id closure arguments as pointers instead of integers
This commit adds a flags parameter to wl_closure_invoke(). The so far
added flags are ment to specify if the invokation is client side or
server side. When on the server side, closure arguments of type 'new_id'
should be invoked as a integer id while on the client side they should
be invoked as a pointer to a proxy object.

This fixes a bug happening when the address of a client side 'new_id'
proxy object did not fit in a 32 bit integer.

krh: Squashed test suite compile fix from Jason Ekstrand.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-03-17 16:39:48 -04:00
Jonas Ådahl
e053a56251 client: Check reference count only for destroyed proxies
The llvm static analyzer tool reported "Use of memory after it is freed"
in dispatch_event() because the proxy is used after being freed if the
reference count reaches zero without the destroyed flag being set. This
would never happen in practice because the owner of the proxy object
always holds a reference until calling wl_proxy_destroy() which would
also set the destroyed flag.

Since this is the case, it is safe to do the reference count check only
if the destroyed flag is set, as it can never reach zero if not.

This commit doesn't change the behavior of the function, but makes the
static analyzer more happy.

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=61385

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2013-03-17 16:24:02 -04:00
Kristian Høgsberg
8f1386fb50 Stylistic nitpicking
No space between '!' and its argument, 	prefer i++ over ++i.
2013-02-26 13:40:38 -05:00
Jason Ekstrand
2fc248dc2c Clean up and refactor wl_closure and associated functions
The primary purpose of this patch is to clean up wl_closure and separate
closure storage, libffi, and the wire format.  To that end, a number of changes
have been made:

 - The maximum number of closure arguments has been changed from a magic number
   to a #define WL_CLOSURE_MAX_ARGS

 - A wl_argument union has been added for storing a generalized closure
   argument and wl_closure has been converted to use wl_argument instead of the
   combination of libffi, the wire format, and a dummy extra buffer.  As of
   now, the "extra" field in wl_closure should be treated as bulk storage and
   never direclty referenced outside of wl_connection_demarshal.

 - Everything having to do with libffi has been moved into wl_closure_invoke
   and the convert_arguments_to_ffi helper function.

 - Everything having to do with the wire format has been restricted to
   wl_connection_demarshal and the new static serialize_closure function.  The
   wl_closure_send and wl_closure_queue functions are now light wrappers around
   serialize_closure.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-02-26 11:31:55 -05:00
Pekka Paalanen
a51ed6d50f client: add wl_proxy_get_class()
This is a useful shorthand for client application debugging macros,
since you can ask the object class from the object itself.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-02-26 11:28:21 -05:00
Kristian Høgsberg
b581d13a7e scanner: Fix 'destroy)' typo in check for destroy request presence
This is there to enforce that we don't have interfaces with a destroy
request that isn't a destructor.  The check never worked because of the
typo, but we also don't have any interfaces like that.
2013-02-25 16:01:38 -05:00
Ran Benita
f53f42a1e7 scanner: remove list_length in favor of wl_list_length 2013-02-25 13:12:27 -05:00
Kristian Høgsberg
f02f82ef78 connection.c: Align pointer extra storage correctly
Most extra data are just pointers, but in case of fds we store an int in
the extra space.  That can cause un-aligned access to pointers on 64 bit
architectures.  Make sure we always align pointer storage correctly.
2013-02-04 07:07:17 -05:00
Kristian Høgsberg
dd7ef2e17d Match libtool version info in 1.0 branch
Master should always as old or older than the stable branch.  I didn't
copy over the libtool version bump when we bumped it in the 1.0 branch.
2013-01-28 15:27:38 -05:00
David Herrmann
142aa4a119 event-loop: fix returning the destroy-signal listener
We need to actually return the destroy-listener, otherwise the return
value is undefined.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2013-01-24 16:14:33 -05:00
Jason Ekstrand
2423497b99 Add a destroy signal to the wl_event_loop object 2013-01-15 14:05:27 -05:00
Jason Ekstrand
31511d0ea0 Added a destroy signal to the wl_display object.
Added a destroy signal to the wl_display object.
2013-01-11 15:52:39 -05:00
Pekka Paalanen
812bd4dd0f client: remove two unused function pointer typedefs
The need for wl_display_update_func_t was removed in

commit 53d24713a3
Author: Kristian Høgsberg <krh@bitplanet.net>
Date:   Thu Oct 4 16:54:22 2012 -0400

    Change filedescriptor API to be thread safe

and wl_callback_func_t does not seem to have ever been used in the first place.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-12-12 11:04:53 -05:00
Kristian Høgsberg
5940419626 client: Add \since tag for wl_display_dispatch_queue_pending() documentation 2012-11-30 14:05:32 -05:00
Quentin Glidic
92ca1a0e80 pkgconfig: Use configure provided directories
https://bugs.freedesktop.org/show_bug.cgi?id=57630
2012-11-27 20:35:50 -05:00
Ander Conselvan de Oliveira
00639de120 scanner: Fix wrong restriction on since field
The scanner would not allow two consecutive requests on an interface to
have the same since number, so if a new version of an interface added
two new request the version number would have to be increased by two.
2012-11-27 11:13:36 -05:00
Jonas Ådahl
d7a63fdbfb client: Don't cancel a roundtrip when any event is received
Since wl_display_dispatch() returns the number of processed events or -1
on error, only cancel the roundtrip if an -1 is returned.

This also fixes a potential memory corruption bug happening when
wl_display_roundtrip() does an early return and the callback later
writes to the then out of scope stack allocated `done' parameter.

Introduced by 33b7637b45.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2012-11-27 11:09:45 -05:00
Tiago Vignatti
5df752ab16 doc: Fix typos
Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
2012-11-23 22:51:51 -05:00
Ander Conselvan de Oliveira
fb20507881 client: Add an entry point for dispatching a queue without blocking
On the client side EGL, all the wl_buffer.release events need to be
processed before buffer allocation, otherwise a third buffer might
be allocated unnecessarily. However, the buffer allocation should
not block in the case no event was received. In order to do that, a
non-blocking queue dispatch function is needed.
2012-11-23 21:50:14 -05:00
Kristian Høgsberg
0f5d41e3bb debug: Allow WAYLAND_DEBUG=server/client for server/client side only debug
By default the server will dump protocol for both the server and its
clients when run with WAYLAND_DEBUG=1.  That's still the case, but it now
also understands WAYLAND_DEBUG=client or WAYLAND_DEBUG=server, which
will only enable debug dumping on either client or server side.
2012-11-21 17:14:55 -05:00
Martin Olsson
b46dab17f0 client: Fix source comment typos 2012-11-14 13:59:03 -05:00
Jonas Ådahl
e273c7cde3 client: Keep track of proxy validity and number of reference holders
When events are queued, the associated proxy objects (target proxy and
potentially closure argument proxies) are verified being valid. However,
as any event may destroy some proxy object, validity needs to be
verified again before dispatching. Before this change this was done by
again looking up the object via the display object map, but that did not
work because a delete_id event could be dispatched out-of-order if it
was queued in another queue, causing the object map to either have a new
proxy object with the same id or none at all, had it been destroyed in
an earlier event in the queue.

Instead, make wl_proxy reference counted and increase the reference
counter of every object associated with an event when it is queued. In
wl_proxy_destroy() set a flag saying the proxy has been destroyed by the
application and only free the proxy if the reference counter reaches
zero after decreasing it.

Before dispatching, verify that a proxy object still is valid by
checking that the flag set in wl_proxy_destroy() has not been set. When
dequeuing the event, all associated proxy objects are dereferenced and
free:ed if the reference counter reaches zero. As proxy reference counter
is initiated to 1, when dispatching an event it can never reach zero
without having the destroyed flag set.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2012-11-05 15:44:50 -05:00
Kristian Høgsberg
3b7d7b0c80 scanner: Preserve paragraph breaks in input XML
If we have a blank line in the incoming XML documentation, keep that in
the emitted doxygen comments.
2012-10-21 22:24:33 -04:00
Kristian Høgsberg
1bade73b6b scanner: Fix valgrind errors 2012-10-20 11:38:57 -04:00
Kristian Høgsberg
620d9edb25 Rename __wl_container_of macro to just wl_container_of
The _* namespace and identifiers with double underscore are reserved
by the C standard.  That makes __wl_container_of is double plus bad,
so lets just call it wl_container_of.
2012-10-19 23:26:45 -04:00
Kristian Høgsberg
7ec35d8e13 Move un-namespaced container_of into private header 2012-10-19 23:06:53 -04:00
Kristian Høgsberg
bdd272f024 Move ARRAY_LENGTH out of public headers
Exporting unprefixed symbols is a pretty bad idea so don't do that.
Instea of redefining it WL_ARRAY_LENGTH, we just move the define to
our private header.  The scanner generates code that uses ARRAY_LENGTH,
but we can just make it count the number elements and emit an integer
constant instead.
2012-10-19 17:08:38 -04:00
Ander Conselvan de Oliveira
818bb399b0 doc: Clarify documentation about dispatching event queues
Clarify on what cases each of the dispatching functions may block, what
is the main thread and add some real world examples.
2012-10-19 16:50:29 -04:00
Ander Conselvan de Oliveira
a4dace7e30 doc: Update wl_display_get_error() documentation 2012-10-17 17:29:04 -04:00
John Kåre Alsaker
0a6fabecd7 wayland-server: Fix up error handling with client creation. 2012-10-17 16:46:15 -04:00
Kristian Høgsberg
009d452432 wayland-egl: Drop ill-defined pixmap support
We don't have a use case for this and the actual semantics and
synchronization behavior of wl_egl_pixmap were never really well-defined.
It also doesn't provide the cross-process buffer sharing that make
window systems pixmaps useful in other window systems.
2012-10-16 15:30:56 -04:00
John Kåre Alsaker
4b6d0e65e7 connection: Dereference id completely for comparasion. 2012-10-16 11:24:31 -04:00