summaryrefslogtreecommitdiff
path: root/src/wayland-shm.c
AgeCommit message (Collapse)AuthorFilesLines
2016-11-10shm: Make shm_pool_interface static constYong Bakos1-1/+1
Add static const modifiers to the shm_pool_interface definition, making it consistent with the other wl_*_interface definitions and mundanely safer. Note that this does not affect the ABI, according to abi-dumper and abi-compliance-checker[1]; and weston and its shm-backed clients still run as expected. [1]: http://lvc.github.io/abi-compliance-checker/ Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Tested-by: Yong Bakos <ybakos@humanoriented.com> Acked-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-07-25(multiple): Include stdint.hYong Bakos1-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>
2016-06-07wayland-shm: Include wayland-util.hYong Bakos1-0/+1
wayland-shm.c uses WL_EXPORT and wl_array, which are defined in wayland-util.h. Include wayland-util.h explicitly, rather than transitively through wayland-server.h. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Sam Spilsbury <smspillaz@gmail.com>
2016-03-08shm: Log a warning if a shm buffer address is requested when it may be invalidDerek Foreman1-0/+5
If wl_shm_buffer_get_data() is called on a shm pool that has an external reference and a pending resize, then the buffer may be outside the pool's current mapping. Log a warning if this happens. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2016-03-08shm: Defer wl_shm_pool_resize if a pool has external referencesDerek Foreman1-12/+35
If a compositor is rendering in one thread while dispatching wayland events in another, a wl_shm_pool_resize() could change the memory mappings it's rendering from and cause a crash. Now we defer wl_shm_pool_resize() if the compositor has references on a pool, and perform the actual resize when it drops those references. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2016-03-08shm: Split pool reference counting into external and internal referencesDerek Foreman1-12/+19
This is a preliminary step towards deferring shm resize operations until after the compositor has released all external references on a pool. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2016-03-08server: Fix shm_create_pool size fail path fd leakSergi Granell1-10/+10
If the client passed a size <= 0 to shm_create_pool, it would go to err_free, which wouldn't close the fd, and thus leave it opened. We can also move the size check before the struct wl_shm_pool malloc, so in case the client passes a wrong size, it won't do an unnecessary malloc and then free. Reviewed-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-02-04cosmetic: add an space after ifSergi Granell1-1/+1
2016-01-12doc: Fix incorrect parameter nameJonas Ådahl1-1/+1
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>
2016-01-12Use zalloc instead of malloc + memsetJonas Ådahl1-3/+1
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>
2015-11-06shm: wl_shm_buffer_get_data() requires a valid pool.Derek Foreman1-4/+6
There's no situation where a shm buffer without a pool makes sense, so we enforce the pool's existence a little more rigidly. Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com>
2015-11-06shm: Move deprecated function to the bottom of the fileDerek Foreman1-8/+17
In wayland-server.c we group the deprecated functions and disable doxygen for them. Do that here too. Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com>
2015-11-06shm: Deprecate wl_shm_buffer_create()Derek Foreman1-28/+1
From irc: <pq> it creates a wl_buffer object in a way that no client can ever access the storage. So, let's replace it with return NULL; and mark it with attribute deprecated in the header. Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com>
2015-10-21shm: Add shm_buffer ref and shm_pool unref functionsDerek Foreman1-0/+42
Sometimes the compositor wants to make sure a shm pool doesn't disappear out from under it. For example, in Enlightenment, rendering happens in a separate thread while the main thread can still dispatch events. If a client is destroyed during rendering, all its resources are cleaned up and its shm pools are unmapped. This causes the rendering thread to segfault. This patch adds a way for the compositor to increment the refcount of the shm pool so it can't disappear, and decrement it when it's finished. The ref/unref are asymmetrical (ref returns the pool) because it's possible the buffer itself will be gone when you need to unref the pool. Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
2015-06-12src: Update boilerplate from MIT X11 license to MIT Expat licenseBryce Harrington1-16/+19
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-04cosmetic: convert some function returns from int to boolDerek Foreman1-4/+5
[Pekka Paalanen: change is_nullable_type() return value to bool.] Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-09-11shm: fix error in commentDerek Foreman1-1/+1
2014-04-07shm: Disallow shrinking shm poolsKristian Høgsberg1-2/+8
Unused shm space will be automatically reclaimed if unused or can be explicitly returned by using fallocate FALLOC_FL_PUNCH_HOLE. https://bugs.freedesktop.org/show_bug.cgi?id=74632
2014-01-15shm: assert sigbus_data is not NULL before member accessU. Artie Eoff1-1/+1
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2013-11-15shm: Avoid file descriptor leak upon unsuccessful mmapLubomir Rintel1-1/+1
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-15Add documentation for wl_shm_buffer_begin/end_accessNeil Roberts1-0/+64
It's not obvious that these functions are needed so it would be good to have some documentation for them.
2013-11-13server: Add API to protect access to an SHM bufferNeil Roberts1-0/+131
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-08-06shm: Add API for renderers to register additional pixel formatsTomeu Vizoso1-13/+32
2013-07-09Replace two remaining wl_display_add_gloavl() occurencesKristian Høgsberg1-1/+1
2013-07-02wayland-server: Remove error event posting from wl_resource_createKristian Høgsberg1-4/+25
The wl_client_add/new_object() functions sends out an NO_MEMORY error if the allocation fails. This was convenient in a couple of places where that was all the error handling that was needed. Unfortunately that looks like out-of-memory isn't handled at the call site and set a bad precedent for not cleaning up properly or not handling at all. As we're introducing wl_resource_create() as a replacement for those two functions, let's remove the automatic error event posting and require the caller to do that if necessary. This commit also introduces a new helper, wl_client_post_no_memory() to make it possible to send NO_MEMORY events from bind where we don't have a wl_resource.
2013-07-02Add wl_resource_create() and a version field to wl_resourceJason Ekstrand1-14/+17
A new function, wl_resource_create(), lets the compositor create a wl_resource for a given version of the interface. Passing 0 for the object ID will allocate a new ID. The implementation, user data and destructor can be set with wl_resource_set_implementation(). These two functions deprecates wl_client_add/new_object and the main difference and motivation is the ability to provide a version number for the resource. This lets the compositor track which version of the interface a client has created and we'll use that to verify incoming requests. Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-07-02server: Make wl_object and wl_resource opaque structsKristian Høgsberg1-0/+3
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>
2013-06-21Change wl_shm_buffer to use a resource pointerJason Ekstrand1-33/+18
This commit also has the effect of making wl_shm_buffer no longer a wl_buffer derivative. Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-06-21Change SHM wl_buffer functions to use the wl_shm_buffer structureJason Ekstrand1-21/+15
This commit does not break ABI. It merely changes the types of some things and adds a wl_shm_buffer_get function. Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-06-05Add accessor functions for wl_resource and deprecate wl_client_add_resourceJason Ekstrand1-16/+19
This is the first step towards making wl_resource an opaque pointer type. Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-03-18Add wl_resource_init and use it in libwayland implementations of data ↵Jason Ekstrand1-18/+6
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>
2012-10-19Move un-namespaced container_of into private headerKristian Høgsberg1-0/+1
2012-08-16Add wl_shm_buffer_create()Kristian Høgsberg1-1/+45
2012-07-20wayland-shm: Commit the width/height getters that actually compileKristian Høgsberg1-4/+4
2012-07-20shm: Add shm_buffer getters for width and heightKristian Høgsberg1-0/+16
2012-07-09wayland-shm: Add return before we hit the error clean-up pathKristian Høgsberg1-0/+2
Regression in c94c0946db694ec29b5aebb94a8be0501bacfbc7
2012-07-09shm: Plug leak in shm_create_pool()Martin Olsson1-6/+9
2012-05-23shm: use mremap on pool resizeAnder Conselvan de Oliveira1-7/+5
2012-05-22shm: Zero busy count for allocated buffersRob Bradford1-0/+1
This avoids a valgrind error like: ==31496== Conditional jump or move depends on uninitialised value(s) ==31496== at 0x407620: weston_buffer_post_release (compositor.c:928) ==31496== by 0x406AEB: weston_surface_attach (compositor.c:725) ==31496== by 0x409EB8: pointer_attach (compositor.c:2009) ==31496== by 0x34ECE05D63: ffi_call_unix64 (unix64.S:75) ==31496== by 0x34ECE05784: ffi_call (ffi64.c:486) ==31496== by 0x5674C4D: wl_closure_invoke (connection.c:770) ==31496== by 0x566ECCB: wl_client_connection_data (wayland-server.c:255) ==31496== by 0x56722F9: wl_event_source_fd_dispatch (event-loop.c:79) ==31496== by 0x5672C99: wl_event_loop_dispatch (event-loop.c:410) ==31496== by 0x56705FF: wl_display_run (wayland-server.c:1004) ==31496== by 0x40C775: main (compositor.c:2937) ==31496== Uninitialised value was created by a heap allocation ==31496== at 0x4A074CD: malloc (vg_replace_malloc.c:236) ==31496== by 0x5670EA7: shm_pool_create_buffer (wayland-shm.c:113) ==31496== by 0x34ECE05D63: ffi_call_unix64 (unix64.S:75) ==31496== by 0x34ECE05784: ffi_call (ffi64.c:486) ==31496== by 0x5674C4D: wl_closure_invoke (connection.c:770) ==31496== by 0x566ECCB: wl_client_connection_data (wayland-server.c:255) ==31496== by 0x56722F9: wl_event_source_fd_dispatch (event-loop.c:79) ==31496== by 0x5672C99: wl_event_loop_dispatch (event-loop.c:410) ==31496== by 0x56705FF: wl_display_run (wayland-server.c:1004) ==31496== by 0x40C775: main (compositor.c:2937)
2012-05-22shm: Add request for resizing poolsAnder Conselvan de Oliveira1-5/+30
2012-04-11Switch protocol to using serial numbers for ordering events and requestsKristian Høgsberg1-2/+2
The wayland protocol, as X, uses timestamps to match up certain requests with input events. The problem is that sometimes we need to send out an event that doesn't have a corresponding timestamped input event. For example, the pointer focus surface goes away and new surface needs to receive a pointer enter event. These events are normally timestamped with the evdev event timestamp, but in this case, we don't have a evdev timestamp. So we have to go to gettimeofday (or clock_gettime()) and then we don't know if it's coming from the same time source etc. However for all these cases we don't need a real time timestamp, we just need a serial number that encodes the order of events inside the server. So we introduce a serial number mechanism that we can use to order events. We still need real-time timestamps for actual input device events (motion, buttons, keys, touch), to be able to reason about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp. The serial number also give us a mechanism to key together events that are "logically the same" such as a unicode event and a keycode event, or a motion event and a relative event from a raw device.
2012-04-03shm: Allocate shm buffers through new wl_shm_pool interfaceKristian Høgsberg1-41/+99
There's a big cost to setting up and tearing down a mmap and faulting in the pages to back it. For cases where we're continuously reallocating shm wl_buffers (resizing a surface, typically) it is a big performance improvement to be able to reuse a mmap area. This change makes the shm buffer allocation a two step process: first allocate a wl_shm_pool, then allocate a buffer from the pool. The wl_shm_pool encapsulate the shared memory pool, and lets clients allocate wl_buffers backed by chunks of that memory. Buffers are allocated at an offset into the pool, so it's possible to create multiple buffers from one pool, for example for icons or cursor images.
2012-03-30shm: Fix stride signedness in protocolKristian Høgsberg1-1/+1
Make stride argument of wl_shm.create_buffer a signed integer.
2012-03-30shm: fix cosmetic gcc warningsPekka Paalanen1-2/+2
Fix warning: 'static' is not at beginning of declaration Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-03-26Remove wl_buffer.damage and simplify shm implementationKristian Høgsberg1-51/+7
2012-03-02server: use the event sending wrappersPekka Paalanen1-4/+2
This exposes some type mismatches that are fixed in the next commit. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-01-11shm: Drop non-premul format, use less ambiguous ARGB8888 naming conventionKristian Høgsberg1-6/+5
This also matches the new wl_drm format names.
2011-09-01server: Make error posting functions take a resource instead of a clientKristian Høgsberg1-11/+11
2011-08-31Remove the wl_visual interfaceKristian Høgsberg1-12/+31
The visual interface was meant to be a generic mechanism for specifying the content of a buffer. It goes back to before we had the buffer factory interfaces (like wl_drm and wl_shm) and we wanted to keep it open-ended enough that yuv, png or even svg buffer or so would be possible. Now that we have the buffer abstraction, we can add different buffer types by introducing new interfaces that create buffers. It only makes sense to leave it to those interfaces to specify the contents of the buffers. For wl_shm, this means that we now just specify the pixel format using an enum. For EGL buffers, the exact pixel formats are controlled by the implementation (part of wl_drm and similar), and from the client point of view, everything is controlled using EGLConfigs.
2011-08-29shm: Compare resource interface when validating visualKristian Høgsberg1-1/+1