Commit graph

48 commits

Author SHA1 Message Date
Kristian Høgsberg
ad03a59f5c connection: Use uin32_t for circular buffer indexes
We rely on well-defined unsigned overflow behaviour so let's make the
index fields actually unsigned.  Signed ints aren't guaranteed to have the
behavior we want (could be either ones or twos complement).
2012-10-15 17:16:30 -04:00
David Herrmann
a9dd3badb5 connection: fix leaking FDs on buffer-overflow during read
If we read more FDs than we have room for, we currently leak FDs because
we overwrite previous still pending FDs. Instead, we do now close incoming
FDs if the buffer is full and return EOVERFLOW.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-15 16:25:19 -04:00
David Herrmann
0b399b8d68 connection: fix buffer-overflow in build_cmsg()
Same problem as we had with close_fds(). We cannot rely on the fds_out
buffer being filled with less than MAX_FDS_OUT file descriptors.
Therefore, write at most MAX_FDS_OUT file-descriptors to the outgoing
buffer.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-15 16:23:38 -04:00
David Herrmann
5bae0650ba connection: close pending incoming FDs on shutdown
Same problem as with outgoing FDs. We need to close these on shutdown,
otherwise we leak open file descriptors.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-15 16:16:24 -04:00
David Herrmann
9bd41ed6a9 connection: fix buffer-overflow in close_fds()
If we push two messages via wl_connection_write() and both messages
contain more than MAX_FDS_OUT file-descriptors combined, then
wl_connection_flush() will write only MAX_FDS_OUT of them, but close all
pending ones, too.

Furthermore, close_fds() will copy more FDs out of the buffer than it can
hold and cause a buffer overflow. Therefore, we simply pass a maximum
limit to close_fds().

During shutdown, we simply close all available FDs.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-15 16:15:41 -04:00
David Herrmann
cda89f3a42 connection: close pending outgoing fds on shutdown
When destroying a wl_connection object, there might still be data in the
queue. We would leak open file-descriptors so we must close them.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-15 16:12:46 -04:00
Kristian Høgsberg
9272fb8f5c connection: Print object id for new-id arguments in deubug output
We can't use the same behaviour in both the client and the server.  In the
client this is a wl_proxy pointer in the server it's a pointer to the
uint32_t object id.  This doesn't fix the problem, but it's a slightly
more useful default, since we typically use WAYLAND_DEBUG on the client.
2012-10-11 17:08:29 -04:00
Kristian Høgsberg
4f9cf6ec44 Fix typecheck in case of multiple instances of type meta data
In most cases the pointer equality test is sufficient.  However, in
some cases, depending on how things are split across shared objects,
we can end up with multiple instances of the interface metadata
constants.  So if the pointers match, the interfaces are equal, if
they don't match we have to compare the interface names.
2012-10-10 22:01:17 -04:00
Kristian Høgsberg
5d2b32b1fd connection: Move object lookup out of wl_connection_demarshal()
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.
2012-10-10 22:01:17 -04:00
Kristian Høgsberg
53d24713a3 Change filedescriptor API to be thread safe
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.
2012-10-10 20:59:00 -04:00
Rob Bradford
6685d19301 connection: Add missing free from error path
On the error codepath that errors out on ENOMEM we should free the allocated
closure.

Signed-off-by: Rob Bradford <rob@linux.intel.com>
2012-10-09 23:01:42 -04:00
Kristian Høgsberg
5495bcd15a connection: Drop unused static closures 2012-10-01 13:21:29 -04:00
Kristian Høgsberg
915cdeee29 connection: zero out string padding
We don't want to send random data to the client and this also keeps
valgrind happy.
2012-08-03 22:39:51 -04:00
Daniel Stone
3ec40512c7 More consistent ID printing
Use unsigned rather than signed for IDs, so they match up with what we
see in other prints.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-23 20:17:10 -04:00
Daniel Stone
db0add6d5e Make NEW_IDs nullable
The connection-handling code already allows this, so make it legal in
the protocol definition too.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-23 20:16:57 -04:00
Daniel Stone
efe23443d8 Unstatic arg_count_for_signature and get_next_argument
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>
2012-07-23 20:15:28 -04:00
Mathias Fiedler
0b8b397e34 connection: reserve id on incoming new object
If a new object id arrives ensure that there is an empty array entry
created, otherwise we might get out of sync for new ids if object isn't
created by interface implementation.
2012-07-22 14:09:51 -04:00
Christopher James Halse Rogers
161c690b55 protocol: Add explicit nullable types
Most of the time it does not make sense to pass a NULL object, string, or array
to a protocol request. This commit adds an explicit “allow-null” attribute
to mark the request arguments where NULL makes sense.

Passing a NULL object, string, or array to a protocol request which is not
marked as allow-null is now an error. An implementation will never receive
a NULL value for these arguments from a client.

Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
2012-07-02 13:53:02 -04:00
Kristian Høgsberg
9de9e39f87 Allocate client proxy automatically for new objects
When the server send a new object ID, the client used to have to allocate
the proxy manually and without type-safety.  We now allocate the proxy
in a client-side post-processing step on the incoming closure.
2012-06-28 22:01:58 -04:00
Kristian Høgsberg
8dc57f4dda connection: Set closure->start in demarshal too 2012-06-13 10:45:38 -04:00
Kristian Høgsberg
46f9745c10 connection: Always malloc closure
This lets us allocate the closure just big enough and is a first step towards
a message queue.
2012-06-13 10:45:34 -04:00
Kristian Høgsberg
f5df38959b Optimize wl_fixed_t to/from double conversion functions 2012-05-14 09:36:38 -04:00
Daniel Stone
c5aba11acc Add support for signed 24.8 decimal numbers
'fixed' is a signed decimal type which offers a sign bit, 23 bits of
integer precision, and 8 bits of decimal precision.  This is exposed as
an opaque struct with conversion helpers to and from double and int on
the C API side.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-05-08 14:40:39 -04:00
Pekka Paalanen
35d5053c62 os: wrap recvmsg(MSG_CMSG_CLOEXEC)
Some system C libraries do not have MSG_CMSG_CLOEXEC. This flag would
automatically set O_CLOEXEC flag on any received file descriptors.

Provide a fallback that does it manually. If setting CLOEXEC fails, the
file descriptor is closed immediately, which will lead to failures but
avoid leaks. However, setting CLOEXEC is not really expected to fail
occasionally.

Add tests for the wrapper. The setup is copied from connection-test.c.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-25 09:37:42 +03:00
Pekka Paalanen
1463a41f89 os: wrap F_DUPFD_CLOEXEC
Some system C libraries do not have F_DUPFD_CLOEXEC. Provide a fallback.

Add tests for the new wl_os_dupfd_cloexec() wrapper.

Add per-wrapper call counters in os_wrappers-test.c. Makes it easier to
determine the minimum required number of wrapped calls.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-25 09:32:58 +03:00
Kristian Høgsberg
243672cd3c connection: Make sure we can invoke closures built with wl_closure_vmarshal() 2012-04-22 14:17:20 -04:00
Kristian Høgsberg
1901d66ffc connection: Move closure object out of wl_connection 2012-04-22 13:49:35 -04:00
Kristian Høgsberg
0d6dea17b4 connection: Dont put fds in the connection until we send the closure 2012-04-21 23:50:13 -04:00
Pekka Paalanen
b7c7963f16 Fix printf format warnings
connection.c:530: warning: format '%lu' expects type 'long unsigned
int', but argument 2 has type 'unsigned int'

/connection.c:560: warning: format '%lu' expects type 'long unsigned
int', but argument 2 has type 'unsigned int'

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-17 15:02:15 -04:00
Kristian Høgsberg
3fb304bb3e connection.c: Fix signedness warnings 2012-03-30 10:43:32 -04:00
Kristian Høgsberg
ba32db9532 Move DIV_ROUNDUP out of public header, remove unused ALIGN 2012-03-30 10:28:39 -04:00
Kristian Høgsberg
1c5578e87f connection: Just look at buffer size and remove redundant n_fds_out
Instead of maintaining a count of the fds in the buffer, just compute
that from the buffer size.  That way we don't get out of sync.
2012-03-23 00:48:19 -04:00
Kristian Høgsberg
cab70c9e5d connection: Set n_fds_out to 0 when we send out the fds
This needs to happen always, not just when the fd buffer overflows.
2012-03-23 00:27:04 -04:00
Ander Conselvan de Oliveira
73d4a53672 Flush the connection if we have to many marshaled fds
The buffer used by wl_connection_data to receive a cmsg is 128 bytes
long. This can hold at most 28 fds but when a cmsg is generated for
sending the fds, there is no check for this limitation. The man page
for recvmsg does not show any way of recovering from MSG_CTRUNC, that
happens when the buffer supplied for cmsg is too short.

Fix this by flushing the data to be written instead of generating a
cmsg buffer longer than the maximum.
2012-03-10 16:01:46 -05:00
Kristian Høgsberg
ac80c54f18 connection: Export wl_connection_queue() so we can test it 2012-03-02 23:38:31 -05:00
Kristian Høgsberg
b26774da5b Don't block when flushing a full protocol buffer
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.
2012-02-29 11:07:48 -05:00
Kristian Høgsberg
1b31149f92 connection: Fix printf format warnings 2011-12-17 16:05:44 -05:00
Laszlo Agocs
34901868b8 Increase closure buffer size and fail gracefully for too big closures.
Buffer size changed from 256 to 1024 bytes. Marshalling will now stop
if the buffer is not big enough.
2011-12-17 16:02:05 -05:00
Kristian Høgsberg
eae3bcb4cc New drag and drop / selection protocol
This commit brings a big change to the DND and copy/paste interfaces.
Most importantly the functionality is now independent of wl_shell.
The wl_shell interface is intended for desktop style UI interaction and
an optional and experimental interface.

The new interface also allows receiving the DND data multiple times or
multiple times during the drag, and the mechanism for offering and receiving
data is now shared between DND and selections.
2011-11-23 16:05:58 -05:00
Kristian Høgsberg
190492b97c debug: Use unsigned for object IDs 2011-11-22 14:04:10 -05:00
Kristian Høgsberg
cf04b0a18f Move private definitions and prototypes to new wayland-private.h 2011-11-18 13:46:56 -05:00
Kristian Høgsberg
4abc56bd6d Introduce wl_resource_queue_event() for sending events later
Some events, such as the display.delete_id, aren't very urgent and we
would like to not always send them immdiately and cause an unnecessary
context switch.  The wl_resource_queue_event() function will place the
event in the connection output buffer but not request the main loop to
poll for writable.  The effect is that the event will just sit in the
output buffer until a more important event comes around and requires
flushing.
2011-11-17 17:52:01 -05:00
Kristian Høgsberg
3a1e6df39a Add display event to acknowledge ID deletion
We need to make sure the client doesn't reuse an object ID until the
server has seen the destroy request.  When a client destroys an ID
the server will now respond with the display.delete_id event, which lets
the client block reuse until it receives the event.
2011-11-17 17:37:52 -05:00
Benjamin Franzke
3f1063f92a connection: Check object types in message parameters 2011-10-31 11:13:13 -04:00
Kristian Høgsberg
c8147edc3a Store objects in wl_map data structure
The wl_map data structure is just an array with a free-list that lets the
client recycle unused client IDs and keep range of client IDs under control.
2011-08-27 12:06:11 -04:00
Paulo Zanoni
1648109c84 connection: fix libffi usage, our functions return void
All clients were segfaulting on my machine.

Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
2011-08-27 12:06:10 -04:00
Kristian Høgsberg
f6ede01b68 connection: Object ID 0 is not a valid new object ID 2011-08-16 22:33:36 -04:00
Kristian Høgsberg
4c260db68c Rename source subdir from wayland to src 2011-08-12 16:25:14 -04:00
Renamed from wayland/connection.c (Browse further)