mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-common
synced 2026-08-08 09:18:08 +00:00
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>
|
||
|---|---|---|
| .. | ||
| backtrace.c | ||
| backtrace.h | ||
| bitops.h | ||
| canvas_base.c | ||
| canvas_base.h | ||
| canvas_utils.c | ||
| canvas_utils.h | ||
| client_demarshallers.h | ||
| client_marshallers.h | ||
| draw.h | ||
| gdi_canvas.c | ||
| gdi_canvas.h | ||
| lines.c | ||
| lines.h | ||
| log.c | ||
| log.h | ||
| lz_common.h | ||
| lz_compress_tmpl.c | ||
| lz_config.h | ||
| lz_decompress_tmpl.c | ||
| lz.c | ||
| lz.h | ||
| macros.h | ||
| Makefile.am | ||
| marshaller.c | ||
| marshaller.h | ||
| mem.c | ||
| mem.h | ||
| messages.h | ||
| pixman_utils.c | ||
| pixman_utils.h | ||
| quic_config.h | ||
| quic_family_tmpl.c | ||
| quic_rgb_tmpl.c | ||
| quic_tmpl.c | ||
| quic.c | ||
| quic.h | ||
| rect.h | ||
| region.c | ||
| region.h | ||
| ring.h | ||
| rop3.c | ||
| rop3.h | ||
| snd_codec.c | ||
| snd_codec.h | ||
| spice_common.h | ||
| ssl_verify.c | ||
| ssl_verify.h | ||
| sw_canvas.c | ||
| sw_canvas.h | ||
| verify.h | ||