summaryrefslogtreecommitdiffstats
path: root/src/wayland-private.h
Commit message (Collapse)AuthorAgeFilesLines
* Move wl_priv_signal to wayland-server-private.hJoshua Watt2019-11-061-21/+1
| | | | | | | | | | | | Including wayland-server-core.h in wayland-private.h is problematic because wayland-private.h is included by wayland-scanner which should be able to build against non-POSIX platforms (e.g. MinGW). The only reason that wayland-server-core.h was included in wayland-private.h was for the wl_private_signal definitions, so move those to a wayland-server-private.h file that can be included by both wayland-server.c and the tests. Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
* Use wl_container_of internallyMichael Forney2019-06-051-4/+0
| | | | | | | | | 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>
* server: Add special case destroy signal emitterDerek Foreman2018-04-201-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | In the past much code (weston, efl/enlightenment, mutter) has freed structures containing wl_listeners from destroy handlers without first removing the listener from the signal. As the destroy notifier only fires once, this has largely gone unnoticed until recently. Other code does not (Qt, wlroots) - and removes itself from the signal before free. If somehow a destroy signal is listened to by code from both kinds of callers, those that free will corrupt the lists for those that don't, and Bad Things will happen. To avoid these bad things, remove every item from the signal list during destroy emit, and put it in a list all its own. This way whether the listener is removed or not has no impact on the following emits. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Simon Ser <contact@emersion.fr> Reviewed-by: Markus Ongyerth <wl@ongy.net>
* client: Consume file descriptors destined for zombie proxiesDerek Foreman2018-01-091-0/+3
| | | | | | | | | | We need to close file descriptors sent to zombie proxies to avoid leaking them, and perhaps more importantly, to prevent them from being dispatched in events on other objects (since they would previously be left in the buffer and potentially fed to following events destined for live proxies) Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
* client: Remove WL_ZOMBIE_OBJECT globalDerek Foreman2017-12-281-3/+0
| | | | | | | | | | | Since we now have the WL_MAP_ENTRY_ZOMBIE flag to determine whether or not a client-side object is a zombie, we can remove the faux object. [daniels: Extracted from Derek's bespoke-zombie patch as an intermediate step.] Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
* client: Add WL_MAP_ENTRY_ZOMBIE flagDerek Foreman2017-12-281-1/+2
| | | | | | | | | | | | | | | | Add a new map entry flag to indicate that the object received is valid, but a zombie. Previously this relied on a fixed object pointer, but future patches in this series will have map entries returning either NULL, or a different structure type entirely, for zombie objects. wl_object_is_zombie() now solely uses the new flag to determine whether or not the object is a zombie. [daniels: Extracted from Derek's bespoke-zombie patch as an intermediate step.] Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
* client: Add wl_object_is_zombie() helper functionDerek Foreman2017-12-281-0/+3
| | | | | | | | | | | Add a helper function which determines whether or not an object is a zombie. [daniels: Extracted from Derek's bespoke-zombie patch as an intermediate step.] Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
* util: Pass flags to map iteratorsDerek Foreman2017-12-271-1/+2
| | | | | | | | | On the client side we're going to need to know if an object from the map is a zombie before we attempt to dereference it, so we need to pass this to the iterator. Reviewed-by: Daniel Stone <daniels@collabora.com> Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
* server: add a safer signal type and port wl_display to itGiulio Camuffo2017-01-251-0/+18
| | | | | | | | | | | | | wl_list_for_each_safe, which is used by wl_signal_emit is not really safe. If a signal has two listeners, and the first one removes and re-inits the second one, it would enter an infinite loop, which was hit in weston on resource destruction, which emits a signal. This commit adds a new version of wl_signal, called wl_priv_signal, which is private in wayland-server.c and which does not have this problem. The old wl_signal cannot be improved without breaking backwards compatibility. Signed-off-by: Giulio Camuffo <giulio.camuffo@kdab.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* tests: Test wl_message_count_arraysYong Bakos2016-11-101-0/+3
| | | | | | | | | | message-test.c did not cover wl_message_count_arrays, so add one test that specifically tests this method. Note that this exposes wl_message_count_arrays in a private header (wayland-private.h), and removes the `static` modifier of the implementation. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* wl_array: Set data to invalid address after freeYong Bakos2016-10-181-0/+3
| | | | | | | | | | | | | | | | | Explicitly set the data member to an invalid memory address during wl_array_release, such that re-using a freed wl_array without re-initializing causes a crash. In addition, this pointer assignment makes wl_array_release testable. Define a constant for the invalid memory address, and add documentation about this behavior, starting at libwayland version 1.13. See https://lists.freedesktop.org/archives/wayland-devel/2016-September/031116.html Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com> [Pekka: remove the doc about crashing] Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* Add API to retrieve and iterate over the resources list of a clientGiulio Camuffo2016-08-121-1/+2
| | | | | | | | | | To complement on the new resource created signal, this allows to iterate over the existing resources of a client. Signed-off-by: Giulio Camuffo <giulio.camuffo@kdab.com> Reviewed-by: Jonas Ådahl <jadahl@gmail.com> [Pekka: added empty lines, init ret in for_each_helper()] Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* (multiple): Include stdint.hYong Bakos2016-07-251-0/+1
| | | | | | | | | | Some headers and source files have been using types such as uint32_t without explicitly including stdint.h. Explicitly include stdint.h where appropriate. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
* private: Remove unnecessary forward declarationsYong Bakos2016-05-111-4/+0
| | | | | | | | | | | Declarations for wl_connection and wl_closure are not needed here. wl_closure already has a complete definition. Removing these forward declarations results in a clean, warning-free compile. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com> [Updated to apply to trunk] Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
* connection: Move wl_interface_equal to utilYong Bakos2016-05-111-4/+4
| | | | | | | | | | | | | Move the wl_interface_equal prototype to the top of wayland-private, where it is not buried in the middle of map, connection and closure functions. Move the implementation out of connection and into util. This is a utility function, not specific to connections, and has call sites within connection, wayland-client and wayland-server. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
* server: Add an API to get the file descriptor for a clientSung-Jin Park2016-01-191-0/+3
| | | | | | | | | | | | | | | This adds an API to get the file descriptor for a client. The client file descriptor can be used for a wayland compositor to validate a request from a client if there are any additional information provided from the client's file descriptor. For instance, this will be helpful in some linux distributions, in which SELinux or SMACK is enabled. In those environments, each file (including socket) will have each security contexts in its inode as xattr member variable. A wayland compositor can validate a client request by getting the file descriptor of the client and by checking the security contexts associated with the file descriptor. Signed-off-by: Sung-Jin Park <input.hacker@gmail.com>
* server: Calculate remaining data size after a closure is processedJaeyoon Jung2016-01-121-0/+3
| | | | | | | | | | | When processing a closure, data in the connection can be consumed again if the closure itself invokes extra event dispatch. In that case the remaining data size is also altered, so the variable len should be updated after the closure is processed. Signed-off-by: Jaeyoon Jung <jaeyoon.jung@lge.com> Reviewed-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
* Use zalloc instead of malloc + memsetJonas Ådahl2016-01-121-0/+7
| | | | | | | Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
* add wl_abort private functionMarek Chalupa2015-11-161-0/+1
| | | | | | | | | On many places in the code we use wl_log + abort or wl_log + assert(0). Replace these with one call to wl_abort, so that we don't mix abort(), assert(0) and we'll save few lines Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
* cosmetic: fix inconsistent code style with header prototypes.Jon Cruz2015-10-261-21/+60
| | | | | | | | A few of the header files had function prototypes that were not following project conventions, sometimes even in the same file. Corrected these to follow as per wayland-os.h. Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
* src: Update boilerplate from MIT X11 license to MIT Expat licenseBryce Harrington2015-06-121-16/+19
| | | | | Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* connection: Leave fd open in wl_connection_destroyBenjamin Herr2014-11-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Calling close() on the same file descriptor that a previous call to close() already closed is wrong, and racy if another thread received that same file descriptor as a eg. new socket or actual file. There are two situations where wl_connection_destroy() would close its file descriptor and then another function up in the call chain would close the same file descriptor: * When wl_client_create() fails after calling wl_connection_create(), it will call wl_connection_destroy() before returning. However, its caller will always close the file descriptor if wl_client_create() fails. * wl_display_disconnect() unconditionally closes the display file descriptor and also calls wl_connection_destroy(). So these two seem to expect wl_connection_destroy() to leave the file descriptor open. The other caller of wl_connection_destroy(), wl_client_destroy(), does however expect wl_connection_destroy() to close its file descriptor, alas. This patch changes wl_connection_destroy() to indulge this majority of two callers by simply not closing the file descriptor. For the benefit of wl_client_destroy(), wl_connection_destroy() then returns the unclosed file descriptor so that wl_client_destroy() can close it itself. Since wl_connection_destroy() is a private function called from few places, changing its semantics seemed like the more expedient way to address the double-close() problem than shuffling around the logic in wl_client_create() to somehow enable it to always avoid calling wl_connection_destroy(). Signed-off-by: Benjamin Herr <ben@0x539.de> Reviewed-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
* Add support for server-side language bindingsJason Ekstrand2013-08-191-11/+3
| | | | | | | | | | | | | | | | | | 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>
* Don't include wayland-server.h in wayland-private.hKristian Høgsberg2013-08-071-1/+2
| | | | We just declare struct wl_display manually instead.
* shm: Add API for renderers to register additional pixel formatsTomeu Vizoso2013-08-061-0/+4
|
* Add version information to wl_message signatures.Jason Ekstrand2013-07-021-0/+3
| | | | | | | | | | | | This commit adds version information to wl_message signatures and a wl_message_get_since function to retrieve. The since version comes in the form of a (possible) integer at the begining of the message. If the message starts with an integer, then it specifies the "since" version of that message. Messages present in version one do not get this "since" information. In this way we can run-time detect the version information for a structure on a per-message basis. Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
* server: Make wl_object and wl_resource opaque structsKristian Høgsberg2013-07-021-0/+9
| | | | | | | | | | With the work to add wl_resource accessors and port weston to use them, we're ready to make wl_resource and wl_object opaque structs. We keep wl_buffer in the header for EGL stacks to use, but don't expose it by default. In time we'll remove it completely, but for now it provides a transition paths for code that still uses wl_buffer. Reviewed-by: Jason Ekstrand<jason@jlekstrand.net>
* Add a wl_resource_instance_of functionJason Ekstrand2013-06-211-0/+3
| | | | Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
* Change WL_ZOMBIE_OBJECT from 0x2 to an actual pointerJason Ekstrand2013-06-051-2/+3
| | | | | | | | | | | 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>
* Add support for flags in the wl_map API and add a WL_MAP_ENTRY_LEGACY flagJason Ekstrand2013-06-051-2/+11
| | | | | | | | 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>
* Add a "side" field and some sanity checks to wl_map.Jason Ekstrand2013-06-051-2/+3
| | | | | | | | | | | | | | | | | | | | 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>
* Change wl_closure_invoke to take an opcode instead of an actual function pointerJason Ekstrand2013-03-181-1/+1
| | | | Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
* client: Invoke new_id closure arguments as pointers instead of integersJonas Ådahl2013-03-171-1/+6
| | | | | | | | | | | | | | | 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>
* Clean up and refactor wl_closure and associated functionsJason Ekstrand2013-02-261-6/+25
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* client: Keep track of proxy validity and number of reference holdersJonas Ådahl2012-11-051-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Move un-namespaced container_of into private headerKristian Høgsberg2012-10-191-0/+4
|
* Move ARRAY_LENGTH out of public headersKristian Høgsberg2012-10-191-0/+2
| | | | | | | | 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.
* connection: Move object lookup out of wl_connection_demarshal()Kristian Høgsberg2012-10-101-0/+3
| | | | | | | | On the client side where we queue up multiple events before dispatching, we need to look up the receiving proxy and argument proxies immediately before calling the handler. Between queueing up multiple events and eventually invoking the handler, previous handlers may have destroyed some of the proxies.
* client: Split event handling into demarshal and dispatch stepsKristian Høgsberg2012-10-101-0/+1
| | | | | This lets us demarshal with a mutex held and then do dispatching after releasing the mutex.
* Change filedescriptor API to be thread safeKristian Høgsberg2012-10-101-10/+5
| | | | | | | | | | | | | | | | | | | | | The update callback for the file descriptors was always a bit awkward and un-intuitive. The idea was that whenever the protocol code needed to write data to the fd it would call the 'update' function. This function would adjust the mainloop so that it polls for POLLOUT on the fd so we can eventually flush the data to the socket. The problem is that in multi-threaded applications, any thread can issue a request, which writes data to the output buffer and thus triggers the update callback. Thus, we'll be calling out with the display mutex held and may call from any thread. The solution is to eliminate the udpate callback and just require that the application or server flushes all connection buffers before blocking. This turns out to be a simpler API, although we now require clients to deal with EAGAIN and non-blocking writes. It also saves a few syscalls, since the socket will be writable most of the time and most writes will complete, so we avoid changing epoll to poll for POLLOUT, then write and then change it back for each write.
* Unstatic arg_count_for_signature and get_next_argumentDaniel Stone2012-07-231-0/+11
| | | | | | | Expose these to other files using wayland-private.h, so wayland-client.c can walk NULLables properly. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* wayland-util: add method for reserving new object idMathias Fiedler2012-07-221-0/+1
| | | | | wl_map_reserve_new() ensures that new id is valid and will point to an empty array entry.
* connection: Always malloc closureKristian Høgsberg2012-06-131-6/+4
| | | | | This lets us allocate the closure just big enough and is a first step towards a message queue.
* Wayland: loggingMartin Minarik2012-05-311-0/+4
| | | | | | | | | | | The core libwayland libraries should not handle logging, only passing the error messages to subscribed functions. An application linked to libwayland-server or libwayland-client will be able to set own functions (one per library) to handle error messages. Change in this series: make the wl_log return int, because of compatibility with printf. It will return the number of bytes logged.
* connection: Move closure object out of wl_connectionKristian Høgsberg2012-04-221-6/+19
|
* connection: Export wl_connection_queue() so we can test itKristian Høgsberg2012-03-021-0/+2
|
* Don't block when flushing a full protocol bufferKristian Høgsberg2012-02-291-3/+3
| | | | | | | In case the client isn't responding, this will block the compositor. Instead we flush with MSG_DONTWAIT, which lets us fill up the kernel buffer as much as we can (after not returning EPOLLOUT anymore it still can take 80k more), and then disconnect the client if we get EAGAIN.
* Drop unused hash tableKristian Høgsberg2011-12-271-0/+2
| | | | | We now just use a table for looking up object IDs so we should drop the hash table.
* Add support for server allocated object IDsKristian Høgsberg2011-11-221-2/+7
| | | | | | | We set aside a range of the object ID space for use by the server. This allows the server to bind an object to an ID for a client and pass that object to the client. The client can use the object immediately and the server can emit events to the object immdiately.
* Move private definitions and prototypes to new wayland-private.hKristian Høgsberg2011-11-181-0/+86