spice-common/common
Frediano Ziglio 74e50b57ae Make the compiler work out better way to write unaligned memory
Instead of assuming that the system can safely do unaligned access
to memory use packed structures to allow the compiler generate
best code possible.
A packed structure tells the compiler to not leave padding inside it
and that the structure can be unaligned so any field can be unaligned
having to generate proper access code based on architecture.
For instance ARM7 can use unaligned access but not for 64 bit
numbers (currently these accesses are emulated by Linux kernel
with obvious performance consequences).

This changes the current methods from:

#ifdef WORDS_BIGENDIAN
#define read_uint32(ptr) ((uint32_t)SPICE_BYTESWAP32(*((uint32_t *)(ptr))))
#define write_uint32(ptr, val) *(uint32_t *)(ptr) = SPICE_BYTESWAP32((uint32_t)val)
#else
#define read_uint32(ptr) (*((uint32_t *)(ptr)))
#define write_uint32(ptr, val) (*((uint32_t *)(ptr))) = val
#endif

to:

#include <spice/start-packed.h>
typedef struct SPICE_ATTR_PACKED {
    uint32_t v;
} uint32_unaligned_t;
#include <spice/end-packed.h>

#ifdef WORDS_BIGENDIAN
#define read_uint32(ptr) ((uint32_t)SPICE_BYTESWAP32(((uint32_unaligned_t *)(ptr))->v))
#define write_uint32(ptr, val) ((uint32_unaligned_t *)(ptr))->v = SPICE_BYTESWAP32((uint32_t)val)
#else
#define read_uint32(ptr) (((uint32_unaligned_t *)(ptr))->v)
#define write_uint32(ptr, val) (((uint32_unaligned_t *)(ptr))->v) = val
#endif

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2017-09-25 16:12:45 +01:00
..
backtrace.c Remove headers that are included in spice_common.h 2016-01-07 12:46:42 +01:00
backtrace.h common/backtrace: for mingw32 no pipe/wait_pid, just disable 2012-03-20 15:25:55 +01:00
bitops.h Remove INLINE usage 2013-10-04 12:45:00 +02:00
canvas_base.c canvas: Don't try to unref NULL pixman_image_t 2017-07-20 17:13:35 +02:00
canvas_base.h canvas-base: remove user data from CanvasBase 2016-11-30 15:36:29 +01:00
canvas_utils.c coverity: avoid use after free 2016-04-25 08:34:14 +02:00
canvas_utils.h Use SPICE_{BEGIN,END}_DECLS 2012-03-20 15:30:23 +01:00
client_demarshallers.h build-sys: make it a seperately buildable spice-common library 2012-03-22 20:21:05 +01:00
client_marshallers.h Use explicit path for inclusion 2016-07-13 15:03:34 -03:00
draw.h draw: Add spice_image_descriptor_is_lossy 2016-01-20 15:56:00 +00:00
gdi_canvas.c use macro to define constructor function 2016-03-23 15:06:08 +00:00
gdi_canvas.h Remove need for SPICE_CANVAS_INTERNAL 2012-03-20 15:30:24 +01:00
lines.c coverity: avoid division or modulo by zero 2016-04-25 09:09:17 +02:00
lines.h build-sys: make it a seperately buildable spice-common library 2012-03-22 20:21:05 +01:00
log.c log: Forbid the usage of obsolete SPICE_LOG_DOMAIN 2017-07-05 09:53:02 +01:00
log.h log: Force format in log macro to be a string 2017-07-05 09:53:10 +01:00
lz_common.h ppc: Fix lz magic endianess 2015-07-02 13:31:28 +02:00
lz_compress_tmpl.c simplify #ifdef code 2016-06-02 10:01:48 +01:00
lz_config.h common: use INLINE instead of inline 2012-03-20 15:25:53 +01:00
lz_decompress_tmpl.c Add support for A8 images to the LZ routines 2012-08-24 13:37:51 -04:00
lz.c Use SPICE_ATTR_PACKED instead of custom ATTR_PACKED 2017-06-15 12:47:36 +01:00
lz.h Add printf format annotations to all '...' functions 2012-03-20 15:30:24 +01:00
macros.h Define a new SPICE_VERIFY macro 2016-11-14 17:19:18 +00:00
Makefile.am Use explicit path for inclusion 2016-07-13 15:03:34 -03:00
marshaller.c Make the compiler work out better way to write unaligned memory 2017-09-25 16:12:45 +01:00
marshaller.h marshaller: Remove deprecated replacement functions 2016-12-08 13:49:13 +00:00
mem.c Avoid clang warnings on casts with stricter alignment requirements 2017-06-20 11:33:45 +02:00
mem.h Avoid clang warnings on casts with stricter alignment requirements 2017-06-20 11:33:45 +02:00
messages.h protocol: add preferred video codec message 2017-01-06 12:20:47 +00:00
pixman_utils.c Remove headers that are included in spice_common.h 2016-01-07 12:46:42 +01:00
pixman_utils.h pixman_utils: Add macros for color byte ordering 2015-12-17 16:03:19 +01:00
quic_config.h Use SPICE_{BEGIN,END}_DECLS 2012-03-20 15:30:23 +01:00
quic_family_tmpl.c log: remove spice_static_assert macro 2017-06-22 11:34:19 +01:00
quic_rgb_tmpl.c quic: Use i == 0 rather than !i 2017-08-01 15:53:59 +02:00
quic_tmpl.c quic: fix typo golomb_deoding -> golomb_decoding 2017-08-03 13:33:00 +01:00
quic.c quic: avoid crash on specific images 2017-08-23 22:47:08 +01:00
quic.h Remove deprecated init functions 2016-06-13 11:28:58 +01:00
rect.h Remove INLINE usage 2013-10-04 12:45:00 +02:00
region.c region: Avoid possible memory corruption 2017-02-28 15:26:54 +00:00
region.h Document REGION_TEST_* bitmasks 2017-02-03 11:07:32 -06:00
ring.h Use a macro to simplify ring_get_length 2016-06-21 12:52:27 +01:00
rop3.c use macro to define constructor function 2016-03-23 15:06:08 +00:00
rop3.h Remove deprecated init functions 2016-06-13 11:28:58 +01:00
snd_codec.c common: Fix -Wunused-variable 2014-10-23 14:54:48 +02:00
snd_codec.h Add support for the Opus codec. 2014-01-02 12:28:21 +01:00
spice_common.h Use a log handler to modify abort() behaviour 2012-03-20 15:30:23 +01:00
ssl_verify.c ssl: Use ASN1_STRING_get0_data instead of ASN1_STRING_data 2017-02-16 16:40:52 +01:00
ssl_verify.h ssl_verify: Move wincrypt.h related #ifdef closer to the include 2015-03-26 10:15:04 +01:00
sw_canvas.c Avoid clang warnings on casts with stricter alignment requirements 2017-06-20 11:33:45 +02:00
sw_canvas.h Remove deprecated init functions 2016-06-13 11:28:58 +01:00
verify.h Adjust verify.h licence 2016-06-21 12:26:38 +02:00