Commit Graph

422 Commits

Author SHA1 Message Date
Frediano Ziglio
f80b229e07 canvas-base: Do not attempt useless cast on stride adjustment
memmove already deal with any alignment so there's no
reason to have row byte pointer cast to uint32_t.
This also remove the confusing "dest" terminology used. The image
is aligned in place so the image bits are used for both destination
and source.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-06-21 12:57:52 +01:00
Christophe de Dinechin
858a0bfae9 Avoid clang warnings on casts with stricter alignment requirements
For example, something like this:
    uint8_t  *p8;
    uint32_t *p32 = (uint32_t *) p8;

generates a warning like this:
  spice-channel.c:1350:10: error: cast from 'uint8_t *' (aka 'unsigned char *') to
      'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to
      4 [-Werror,-Wcast-align]

The warning indicates that we end up with a pointer to data that
should be 4-byte aligned, but its value may be misaligned. On x86,
this does not make much of a difference, except a relatively minor
performance penalty. However, on platforms such as older ARM, misaligned
accesses are emulated by the kernel, and support for them is optional.
So we may end up with a fault.

The intent of the fix here is to make it easy to identify and rework
places where actual mis-alignment occurs. Wherever casts raise the warning,
they are replaced with a macro:

- SPICE_ALIGNED_CAST(type, value) casts value to type, and indicates that
  we believe the resulting pointer is aligned. If it is not, a runtime
  warning will be issued. This check is disabled unless
  --enable-alignment-checks is passed at configure time

- SPICE_UNALIGNED_CAST(type, value) casts value to type, and indicates that
  we believe the resulting pointer is not always aligned.

Any code using SPICE_UNALIGNED_CAST may need to be revisited in order
to improve performance, e.g. by using memcpy.

There are normally no warnings for SPICE_UNALIGNED_CAST, but it is possible
to emit debug messages for mis-alignment in SPICE_UNALIGNED_CAST
by configuring with CFLAGS=-DSPICE_DEBUG_ALIGNMENT.

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
2017-06-20 11:33:45 +02:00
Frediano Ziglio
765652da1d Use SPICE_ATTR_PACKED instead of custom ATTR_PACKED
Reuse {start,end}-packed headers to specify packed structure.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2017-06-15 12:47:36 +01:00
Christophe de Dinechin
30a33922d8 Use space and not colon to separate log domains
According to https://developer.gnome.org/glib/stable/glib-running.html,
G_MESSAGES_DEBUG is a space-separated list of log domains for which
informational and debug messages should be printed

Note that the equivalent code in spice-util.c gets it right.

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-06-09 09:56:29 +01:00
Frediano Ziglio
1d7acdcf57 log: Use GLib logging levels directly
As we moved toward GLib logging instead of having to convert
every time the log level from the old system to GLib use
directly GLib constants.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-06-09 09:46:35 +01:00
Frediano Ziglio
31ebe7c6d5 fix indentation on previous patch
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2017-06-01 10:12:34 +01:00
Frediano Ziglio
564635e3c1 log: Check log level from spice_logv
This was suggested by Christophe de Dinechin as an optimisation.
Most of the messages won't be processed for formatting.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-05-31 10:20:58 +01:00
Frediano Ziglio
a607077883 log: Optimise glib_debug_level check
Use INT_MAX for invalid value to remove a test in code.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-05-31 10:20:56 +01:00
Frediano Ziglio
f4a4d52702 log: Do not check impossible function return
spice_log_level_to_glib never returns 0 so don't check
for this value.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-05-31 10:20:50 +01:00
Christophe de Dinechin
5faba1e860 Style adjustment - Making code match surrounding style
Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2017-05-18 16:37:21 +01:00
Christophe Fergeau
af682b1b06 log: Follow spice style guidelines for #include in log.h
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-03-31 12:14:02 +02:00
Christophe Fergeau
0996c33d6d log: Add missing stdio.h include
This is needed because spice_printerr uses fprintf/stderr

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-03-31 10:37:28 +01:00
Frediano Ziglio
4423ea5d2a region: Avoid possible memory corruption
pixman_region32_copy assume that destination (first argument)
is initialized and can use a pointer inside based on different
conditions.
As intersection is not initialized this can cause different
memory problems.
This resulted in memory leak detection from address sanitizer.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2017-02-28 15:26:54 +00:00
Sebastian Andrzej Siewior
ab7cae45bc ssl: Use ASN1_STRING_get0_data instead of ASN1_STRING_data
The latter is deprecated, so might be removed at  some point in the
future. This also adds a compatibility wrapper for OpenSSL < 1.1.0.

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2017-02-16 16:40:52 +01:00
Jonathon Jongsma
c9ecd0e29e Document REGION_TEST_* bitmasks
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
2017-02-03 11:07:32 -06:00
Victor Toso
6439bec0de protocol: add preferred video codec message
Client might want to choose a preferred video codec for streaming for
different reasons which having hardware decoder support being the most
interest one.

This message allows the client to send an array of video codecs in
order of preference.

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2017-01-06 12:20:47 +00:00
Frediano Ziglio
86dcd22d33 marshaller: Remove deprecated replacement functions
spice-common has no stable ABI/API.
Also these function caused linking problems as these functions
were defined multiple times.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-12-08 13:49:13 +00:00
Jonathon Jongsma
adb36c6185 Marshaller: rename _add_ref() to _add_by_ref()
The spice_marshaller_add_ref() family of functions is confusing since it
sounds like you're incrementing a reference on the marshaller. What it
is actually doing is adding a data buffer to the marshaller by reference
rather than by value. Changing the function names to _add_by_ref() makes
this clearer.

The old functions are deprecated and are simply inline functions that
call the new functions.

Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-12-06 11:21:55 -06:00
Victor Toso
a5871c80a9 sw-canvas: remove unused defines
Including CANVAS_SINGLE_INSTANCE that was bounded to CanvasBase user
data which was removed in previous commit

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-30 15:36:29 +01:00
Victor Toso
580ca81536 canvas-base: remove user data from CanvasBase
Neither Spice nor spice-gtk are using this since the
following commit in Spice "server: remove OpenGL"
c5c176a5c7718177f23b07981556b5d460627498

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-11-30 15:36:29 +01:00
Victor Toso
edaafa187d canvas-base: group ifdef and defined together
Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-11-24 15:51:05 +00:00
Victor Toso
2c34cf49b5 canvas-base: use helper to get surface
Moving out a big switch statement that sole purpose is to retrieve the
surface (pixma_image_t)

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2016-11-24 15:51:01 +00:00
Frediano Ziglio
31819a2424 Define a new SPICE_VERIFY macro
The verify macro used currently has some problem
as it raise a warning in RHEL6.
As suggested in verify.h use verify_expr macro
to avoid the warning.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-11-14 17:19:18 +00:00
Pavel Grunt
63e575d5fc silence -Wunused-parameter 2016-11-01 15:26:43 +01:00
Eduardo Lima (Etrunko)
62f3024f42 Use explicit path for inclusion
As client_marshallers.h is included outisde of spice-common, we need to
specify the path for generated_marsharllers.h so that builds out of the
tree don't fail.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2016-07-13 15:03:34 -03:00
Christophe Fergeau
073d064b86 codegen: Autogenerate client_marshallers.h
This commit adds autogeneration of a generated_client_marshallers.h
header, which is then included in client_marshallers.h

This allows to remove the SpiceMessageMarshallers struct from this file,
which has to match what the generated code expects.

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-24 10:02:58 +01:00
Frediano Ziglio
15b8f28c14 Use a macro to simplify ring_get_length
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-21 12:52:27 +01:00
Christophe Fergeau
1d47225a8e Adjust verify.h licence
verify.h can be licensed as LGPLv2+ rather than GPLv3, see
http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=modules/verify;h=5216ce890dac58e596a27341e31258e5d6c0d702;hb=HEAD

A verify.h file with the appropriate licence can be generated from a
gnulib clone using:
gnulib-tool --lgpl=2 --import verify

This will fail if the 'verify' module is not licensed under a compatible
license.
2016-06-21 12:26:38 +02:00
Christophe Fergeau
62b996ffb0 Update verify.h to latest version 2016-06-20 15:03:44 +02:00
snir sheriber
4284011bdc Add LZ4 data compression and use it in spicevmc channel
Compressed message type is CompressedData which contains compression
type (1 byte) followed by the uncompressed data size (4 bytes-exists
only if data was compressed) followed by the compressed data

Update the required protocol to 0.12.12:

Signed-off-by: Snir Sheriber <ssheribe@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-13 23:00:28 +01:00
Frediano Ziglio
d0139f824e Remove a warning compiling under Windows
On Windows long is always 32 bit so under x64 the cast from pointer to
"unsigned long" cause a warning.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-13 18:38:25 +01:00
Frediano Ziglio
bbd8f9a5e2 Remove deprecated init functions
No need to keep API compatibility in spice-common.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Marc-André Lureau <mlureau@redhat.com>
2016-06-13 11:28:58 +01:00
Frediano Ziglio
73282208f0 simplify #ifdef code
Reduce conditional code

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2016-06-02 10:01:48 +01:00
Pavel Grunt
384698af37 Remove GL support
It is not needed since spice-server commit
c5c176a5c7718177f23b07981556b5d460627498

Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-05-11 16:54:23 +01:00
Fabiano Fidêncio
74439e8e6e Use g_getenv() instead of getenv()
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-04-25 09:09:17 +02:00
Fabiano Fidêncio
a8f756eabf coverity: remove structurally dead code
The loop (for (;;)) will be executed only once, so, no reason for
keeping it.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-04-25 09:09:17 +02:00
Fabiano Fidêncio
83b84428ec coverity: remove unused value
len is overwritten in the match label with the value from
"ip - anchor".

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-04-25 09:09:17 +02:00
Fabiano Fidêncio
657e1c5291 coverity: avoid division or modulo by zero
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-04-25 09:09:17 +02:00
Fabiano Fidêncio
3312a0f70b coverity: avoid dereference after null check
All decompress functions used after this check take into account that
encoder->palette is not NULL. So, if we already detected that the
palette is NULL, let's just return early.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2016-04-25 09:09:17 +02:00
Fabiano Fidêncio
89b902789b coverity: avoid resource leak
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-04-25 08:34:54 +02:00
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
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
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
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