Commit Graph

562 Commits

Author SHA1 Message Date
Fabiano Fidêncio
bc73df4e47 coverity: avoid use after free
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-04-25 08:34:14 +02:00
Pavel Grunt
739a859d79 Define canvas_fix_alignment when is used
It is used in canvas_get_lz4() which is guarded by USE_LZ4, and
in canvas_get_lz() which is guarded by SW_CANVAS_CACHE.
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-04-19 13:49:50 +02:00
Lin Ma
2eaf7c9572 build-sys: Define opengl GL_LIBS and GL_CFLAGS in generated Makefile.in
SPICE_COMMON_{CFLAGS,LIBS} references '$(GL_{CFLAGS,LIBS)', so these
variables are going to be expanded at 'make' time rather than at
'configure' time.
The linker flag and the compiler flag won't be substituted in the
generated Makefile without AC_SUBST.
It causes spice-gtk building failure with --enable-opengl option.

The patch fixes this issue.

Signed-off-by: Lin Ma <lma@suse.com>
2016-04-18 10:59:07 +02:00
Frediano Ziglio
5603961ffa fix 16 bpp LZ image decompression
LZ image decompression was broken for 16 bpp:
- stride was computed not computed correctly (as width*4). This caused
  also a buffer underflow;
- stride in pixman is always multiple of 4 bytes (so for 16 bpp is
  ALIGN(width*2, 4)) so image decompressed by lz_decode as some missing
  bytes to be fixed.

The alignment code is reused from LZ4 function.

This fix also https://bugzilla.redhat.com/show_bug.cgi?id=1285469.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-04-15 14:25:58 +01:00
Christophe Fergeau
2a4bf49edd log: Make sure glib threading is initialized
While testing spice-server on EL6, I was getting random crashes in the
glib logging code because g_logv was called recursively even though this
was not visible in a backtrace.

It turns out on older glib versions (EL6 has 2.28), g_logv is not
thread-safe unless g_thread_init() is called first. If g_thread_init()
is not called, the GMutex/GPrivate calls g_logv makes are turned into
no-ops, which is going to cause the recursion issue I was seeing.

This commit adds a call to g_thread_init() for these older glib
versions.

(gdb) bt
    0x7fff9f9fb110 "item.type: 114", unused_data=0x0) at gmessages.c:863
    format=0x7ffff50e72ac "item.type: %d", args1=0x7fff9f9fb640) at gmessages.c:517
    SPICE_LOG_LEVEL_DEBUG, strloc=0x7ffff50e72ba "dcc.c:1652", function=
    0x7ffff50e7320 "release_item_before_push", format=0x7ffff50e72ac "item.type: %d", args=
    0x7fff9f9fb640) at log.c:163
    SPICE_LOG_LEVEL_DEBUG, strloc=0x7ffff50e72ba "dcc.c:1652", function=
    0x7ffff50e7320 "release_item_before_push", format=0x7ffff50e72ac "item.type: %d") at log.c:195
    at dcc.c:1652
    at dcc.c:1719
    at dcc-send.c:2450
    at red-channel.c:578
    at red-channel.c:1587
    at event-loop.c:122
    0x7ffff4fb2ef2 <watch_func>, user_data=0x7fff980244e0) at giounix.c:166
    0x7ffff86ec770) at gmain.c:3092
2016-04-05 15:38:18 +02:00
Christophe Fergeau
8473d0ae71 log: Use SPICE_CONSTRUCTOR_FUNC
This was done through a GOnce called every time spice_log() is called,
now it will always be called at spice-server startup.

This means the unit test needs to be updated as SPICE_DEBUG/ABORT_LEVEL
must now be set before the process starts up rather than before the
first spice_log call, and the deprecation warning these environment
variables trigger cannot be caught using g_test_expect_message() as
they are output before g_test_init() is called.
2016-04-05 15:38:17 +02:00
Christophe Fergeau
6a65f470d1 log: Clamp SPICE_DEBUG_LEVEL if it's too high
This matches how SPICE_DEBUG_LEVEL behaved before switching to glib
logging.
2016-04-05 15:38:16 +02:00
Christophe Fergeau
6c7552d543 tests: Fix glib version check
The glib version checks were using #ifdef GLIB_CHECK_VERSION() rather
than  #if GLIB_CHECK_VERSION()
2016-03-31 13:34:43 +02:00
Eduardo Lima (Etrunko)
55ec596798 2/2] Add check for openssl
It is required to compile ssl-verify.[ch].

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2016-03-31 11:25:49 +02:00
Eduardo Lima (Etrunko)
51df6f775a Fix build in systems with Glib version older than 2.38
Tests now include functions only available in glib 2.38. To avoid
setting the dependency bar too high, we simply put them between #ifdef
guards.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2016-03-31 11:25:02 +02:00
Frediano Ziglio
5b6be16b37 use macro to define constructor function
Avoid having to call function at runtime to inialize static.
Old functions are defined as deprecated for compatibility.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-03-23 15:06:08 +00:00
Frediano Ziglio
2505f9ac96 define SPICE_CONSTRUCTOR_FUNC and SPICE_DESTRUCTOR_FUNC macros
Allow to define functions executed at program/shared object initialization
or close.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-03-17 17:16:30 +00:00
Frediano Ziglio
0f45924f4c tests: exit on SIGABRT
Fatal error exit usually with abort() causing SIGABRT to be triggered
which can have problems with core dump generation depending on system
settings. Capturing and exiting on this signal solve the problem.
This is a workaround to some system configurations which could cause
test to fail.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-03-16 08:14:02 +00:00
Frediano Ziglio
53ee80bd7d Cap logging level to the valid bounds
Avoid overflows using its values.
The patch was originally written by Christophe Fergeau

Acked-by: Victor Toso <victortoso@redhat.com>
2016-03-11 10:16:22 +00:00
Christophe Fergeau
8af947e7b2 Remove 2 unused vfuncs from client_marshallers.h
The AudioVolume and AudioMute messages are not sent by the client, so
they do not need to appear in SpiceMessageMarshallers in
client_marshallers.h
2016-03-11 09:55:09 +01:00
Francois Gouget
00db440878 protocol: Add support for the VP8 and h264 video codecs
Clients that support multiple codecs must advertise the
SPICE_DISPLAY_CAP_MULTI_CODEC capability and one
SPICE_DISPLAY_CAP_CODEC_XXX per supported codec.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>

(cherry picked from spice-protocol commit 7937915d67702a5c4b5147b277c432f5555e3852)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:59:18 +01:00
Marc-Andre Lureau
279be89836 protocol: add unix GL scanout messages
Add 2 new messages to the display channel to stream pre-rendered GL
images of the display. This is only possible when the client supports
SPICE_DISPLAY_CAP_GL_SCANOUT capability.

The first message, SPICE_MSG_DISPLAY_GL_SCANOUT_UNIX, sends a gl image
file handle via socket ancillary data, and can be imported in a GL
context with the help of eglCreateImageKHR() (as with the 2d canvas, the
SPICE_MSG_DISPLAY_MONITORS_CONFIG will give the monitors
coordinates (x/y/w/h) within the image). There can be only one scanount
per display channel.

A SPICE_MSG_DISPLAY_GL_DRAW message is sent with the coordinate of the
region within the scanount to (re)draw on the client display. For each
draw, once the client is done with the rendering, it must acknowldge it
by sending a SPICE_MSGC_DISPLAY_GL_DRAW_DONE message, in order to
release the context (it is expected to improve this in the future with a
cross-process GL fence).

The relation with the existing display channel messages is that all
other messages are unchanged: the last drawing command received must be
displayed. However the scanout display is all or nothing. Consequently,
if a 2d canvas draw is received, the display must be switched to the
drawn canvas. In other words, if the last message received is a GL draw
the display should switch to the GL display, if it's a 2d draw message
the display should be switched to the client 2d canvas.

(there will probably be a stipped-down "gl-only" channel in the future,
or support for other streaming methods, but this protocol change should
be enough for basic virgl or other gpu-accelerated support)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>

(cherry picked from spice-protocol commit 3fc2221e965623c5a7e50d95f1623269a067c2d3)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:46 +01:00
Christophe Fergeau
0853b579df proto: Use proper type for preferred_compression field
No need to use an uint8 typed member, we can directly use the
appropriate enum8 type here, which makes everything more explicit.

(cherry picked from spice-protocol commit 8a3def14e35039753097094ba356e85e8fc2d128)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:46 +01:00
Christophe Fergeau
2ccf106920 proto: Rename image_compress to image_compression
Re-using the SPICE_IMAGE_COMPRESS_ prefix in newer spice-protocol
releases is going to cause issues as there will be clashing enum members
in older spice-server releases. Using SPICE_IMAGE_COMPRESSION_ as a
prefix sidesteps these backward compability issues.

(cherry picked from spice-protocol commit e857cd9a378cdf56805b64284491a12af93a7cbf)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:46 +01:00
Marc-André Lureau
487f914a5d codegen: simplify FdType
This patch is a left-over from the fd passing commit 267391c8fd as
suggested by Frediano Ziglio during review.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>

(cherry picked from spice-protocol commit 47076559628d71c128e14e11147ce36b92677885)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:42 +01:00
Marc-Andre Lureau
c5ed374a32 protocol: learn to describe fd passing in messages
Add a new type, "unix_fd", used to describe file descriptor sharing via
socket ancillary data (these messages are local only).

The marshaller/demarshaller can't serialize this in memory (consume_fd
implementation is empty), so it is the responsability of the marshaller
user to handle sending and receiving the handles, which are appended at
the end of the message with an extra stream byte (because some Unix
requires sending at least a byte with ancillary data).

Even if there is no fd to send (or if the fd is invalid etc), the
receiver side expects an extra byte anyway.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>

(cherry-picked from spice-protocol commit 267391c8fd7c90c067b3e4845ff0227a2580e2e2)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:42 +01:00
Marc-André Lureau
1cd26b87c1 Revert "Remove files moved to spice-protocol"
This reverts commit 7665dcf1bb.

Also revert the related build-sys changes to fix the build.

codegen generated code depends on spice-common code (marshaller,
messages etc), it makes more sense to keep the generator along
this. Otherwise a newer protocol release will fail to build older
projects.

*.proto files are required as well, since it generates code that parent
modules depend on unconditionnaly.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:36 +01:00
Marc-André Lureau
f06f699d78 test-logging: unset G_MESSAGES_DEBUG
This test is sensitive to G_MESSAGES_DEBUG variable. Make it insensitive
by unsetting the environment variable.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-03-10 14:47:39 +00:00
Frediano Ziglio
fd9ba72f1a marshaller: fix uninitialized field usage
has_fd was not initialized.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Marc-André Lureau <mlureau@redhat.com>
2016-02-03 11:48:43 +00:00
Marc-Andre Lureau
472e563591 marshaller: track if add_fd() was given -1
In some cases, it might be worth to be able to send a message with a -1
fd, has the protocol permits. Change add_fd/get_fd in order to track
if the caller wanted to send -1.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-02-02 12:38:54 +00:00
Pavel Grunt
6424c0baee Use lz4 if possible
Change the default option to "auto"

Acked-by: Victor Toso <victortoso@redhat.com>
2016-01-28 14:16:10 +01:00
Frediano Ziglio
75cb2701d3 Use code to compute a bit mask
Code is in the slow path, this reduce space needed for data+code.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-27 18:39:06 +00:00
Frediano Ziglio
580adf7c36 Avoid to call ceil_log_2 twice with same value
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-27 18:39:04 +00:00
Frediano Ziglio
6e04b94751 Constification
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-27 18:39:02 +00:00
Frediano Ziglio
daf406a179 zeroLUT has same content of lzeroes
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-27 18:39:01 +00:00
Frediano Ziglio
07b3150cb1 common: constify some declarations
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-27 18:38:43 +00:00
Frediano Ziglio
7790dacfd3 small spice_strdup optimization
avoid to compute the string length twice and use memcpy instead of
strcpy which is faster not having to check for terminator.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-26 17:17:08 +00:00
Frediano Ziglio
5376f1d88c remove wrong statement terminator from preprocessor macro
Actually not causing problems as when used is always followed by another
terminator but better to fix the definition.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-26 16:45:32 +00:00
Christophe Fergeau
0a6580d2e6 log: Kill spice_warn_if
It's redundant with spice_warn_if_fail(), and can even be confusing.

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-26 15:58:43 +01:00
Christophe Fergeau
df56d585cb log: Add test case for logging code
This gives us a baseline of how the SPICE/glib integration is supposed
to behave.

Everything goes through glib logging facilities, and is impacted by
G_MESSAGES_DEBUG/G_DEBUG=fatal-{warnings,criticals}

Messages in the SPICE_LOG_DOMAIN log domain (output either through
spice_log() or g_log()) will also consider the legacy SPICE_DEBUG_LEVEL
and SPICE_ABORT_LEVEL environment variables. Messages in other domains
will not be impacted by these legacy environment variables.

If spice-common is built without SPICE_DISABLE_ABORT,
spice_return_if_fail()/spice_critical() will abort the program.
g_return_if_fail()/g_critical() will not abort the program.
2016-01-26 15:58:43 +01:00
Christophe Fergeau
417dbedc0b tests: Always build tests
The next commit will introduce a test for log messages. As
libspice-common.la behaviour varies depending on whether
SPICE_DISABLE_ASSERT was defined at compile-time, this test will also
take into account this preprocessor define.
We are more likely to get a consistent build (SPICE_DISABLE_ASSERT being
the same when building libspice-common.la and the test) if both are
built at the same time.

This commit changes that, tests are now built (but not run) at 'make'
time rather than 'make check' time.
2016-01-26 15:58:43 +01:00
Christophe Fergeau
efd1d3cb4d log: Use glib for logging
spice-common has been duplicating glib logging methods for a long while.
Now that spice-common is depending on glib, it's more consistent to use
glib logging too. However, the code base is still using spice logging
functions.
This commit aims to make spice logging go through glib logging system,
while keeping the same behaviour for the SPICE_ABORT_LEVEL and
SPICE_DEBUG_LEVEL environment variables. They are deprecated however in
favour of the glib alternatives (G_DEBUG and G_MESSAGES_DEBUG).

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-26 15:58:43 +01:00
Christophe Fergeau
2ff25b7567 log: Remove unneeded #ifdef/#endif
If header guards are working as expected, there should not be multiple
definitions of these macros. If they are redefined somewhere else, this
is a bug we want to fix.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-26 11:49:14 +01:00
Christophe Fergeau
838596a257 log: Use more glib macros
No need to have our own SPICE_STMT_BEGIN/END and SPICE_STRINGIFY

Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-21 11:10:39 +01:00
Pavel Grunt
93cd2f6836 draw: Add spice_image_descriptor_is_lossy
It will be used in the server code

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-01-20 15:56:00 +00:00
Marc-Andre Lureau
b61f43f228 Add GL scanout structures
See related protocol changes.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-01-14 11:49:25 +00:00
Marc-Andre Lureau
a18bed136f marshaller: learn to describe fd passing in messages
The marshaller can't serialize fd in memory stream. Instead, append the
fd to the marshaller structure. The marshaller user is responsible for
sending the fd when the message is sent. The fd to send can be retrieved
with spice_marshaller_get_fd().

Note: only a single fd is supported with this API, supporting multiple
fd is left for the future if it becomes necessary.

Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-01-14 11:46:58 +00:00
Frediano Ziglio
80cc3f680a ring: use NULL instead of 0 for null pointers
This is consistent with the rest of the code making clear
fields are pointers.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-01-07 16:46:19 +00:00
Victor Toso
397eb47816 Remove headers that are included in spice_common.h
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-01-07 12:46:42 +01:00
Pavel Grunt
c3f2d217af m4: Add macro for --with-sasl
It is not used by spice-common, but both server and client can use it.
Compared to current checks in spice-gtk and spice server this macro only
supports libsasl2.

Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2015-12-18 13:57:58 +01:00
Lukas Venhoda
a78da942a7 Remove trailing whitespace 2015-12-18 11:41:15 +01:00
Lukas Venhoda
1118712c59 ppc: Fix alpha state checking on BE machines
The surface before conversion can be either LE or BE on a BE machine.
Check against both BE and LE color order on BE machine.
2015-12-17 16:03:22 +01:00
Lukas Venhoda
2493c60ff7 ppc: Fix colors on ppc when using jpeg
Fixes color order on PowerPC when using jpeg compression.
2015-12-17 16:03:20 +01:00
Lukas Venhoda
98f9097c49 ppc: Fix colors on ppc when using LZ4
Fixes color order on PowerPC when using LZ4 image compression.
2015-12-17 16:03:20 +01:00
Lukas Venhoda
d7719d3e60 ppc: Fix colors on ppc when using LZ
Fixes color order on PowerPC when using LZ image compression.
2015-12-17 16:03:20 +01:00