unicorn/qemu/include/qemu
Peter Maydell 3ff38c2402
include/qemu/bswap.h: Use __builtin_memcpy() in accessor functions
In the accessor functions ld*_he_p() and st*_he_p() we use memcpy()
to perform a load or store to a pointer which might not be aligned
for the size of the type. We rely on the compiler to optimize this
memcpy() into an efficient load or store instruction where possible.
This is required for good performance, but at the moment it is also
required for correct operation, because some users of these functions
require that the access is atomic if the pointer is aligned, which
will only be the case if the compiler has optimized out the memcpy().
(The particular example where we discovered this is the virtio
vring_avail_idx() which calls virtio_lduw_phys_cached() which
eventually ends up calling lduw_he_p().)

Unfortunately some compile environments, such as the fortify-source
setup used in Alpine Linux, define memcpy() to a wrapper function
in a way that inhibits this compiler optimization.

The correct long-term fix here is to add a set of functions for
doing atomic accesses into AddressSpaces (and to other relevant
families of accessor functions like the virtio_*_phys_cached()
ones), and make sure that callsites which want atomic behaviour
use the correct functions.

In the meantime, switch to using __builtin_memcpy() in the
bswap.h accessor functions. This will make us robust against things
like this fortify library in the short term. In the longer term
it will mean that we don't end up with these functions being really
badly-performing even if the semantics of the out-of-line memcpy()
are correct.
2019-04-10 14:57:52 -04:00
..
atomic.h atomics: Set ATOMIC_REG_SIZE=8 for MIPS n32 2019-01-05 07:26:14 -05:00
atomic128.h tcg: add early clober modifier in atomic16_cmpxchg on aarch64 2019-02-07 08:58:53 -05:00
bitmap.h bitmap: provide to_le/from_le helpers 2018-03-05 01:11:13 -05:00
bitops.h i386: Fix up the Node id for CPUID_8000_001E 2018-07-03 00:31:38 -04:00
bswap.h include/qemu/bswap.h: Use __builtin_memcpy() in accessor functions 2019-04-10 14:57:52 -04:00
compiler.h qemu/compiler: Include <intrin.h> on MSVC 2019-01-30 13:25:26 -05:00
cpuid.h util: Introduce include/qemu/cpuid.h 2018-03-09 12:12:00 -05:00
crc32c.h import 2015-08-21 15:04:50 +08:00
cutils.h cutils: Fix qemu_strtosz() & friends to reject non-finite sizes 2018-12-18 04:48:12 -05:00
fprintf-fn.h Clean up decorations and whitespace around header guards 2018-02-25 04:26:02 -05:00
host-utils.h qemu/host-utils: Handle ctpop8/16/32/64 on MSVC 2019-01-30 13:29:58 -05:00
int128.h qemu/int128: Disable assert in int128.h 2018-09-03 09:54:59 -04:00
log.h tcg: Optionally log FPU state in TCG -d cpu logging 2018-05-15 22:31:08 -04:00
mmap-alloc.h mmap-alloc: fix hugetlbfs misaligned length in ppc64 2019-02-05 16:52:39 -05:00
module.h cleanup qemu/include/qemu/module.h 2017-01-25 00:20:08 +08:00
osdep.h osdep: Conditionally include non-Windows headers 2019-01-28 09:24:20 -05:00
queue.h tcg: Dynamically allocate TCGOps 2018-03-05 16:34:40 -05:00
range.h Don't talk about the LGPL if the file is licensed under the GPL 2019-02-03 17:55:28 -05:00
sys_membarrier.h membarrier: add --enable-membarrier 2018-03-17 19:30:43 -04:00
thread-posix.h Clean up ill-advised or unusual header guards 2018-02-25 04:22:46 -05:00
thread-win32.h Clean up ill-advised or unusual header guards 2018-02-25 04:22:46 -05:00
thread.h Clean up ill-advised or unusual header guards 2018-02-25 04:22:46 -05:00
timer.h Drop remaining bits of ia64 host support 2018-03-09 11:54:57 -05:00
typedefs.h move ObjectClass to typedefs.h 2018-12-11 20:37:04 -05:00
units.h include: Add IEC binary prefixes in qemu/units.h 2018-07-03 19:47:19 -04:00
xxhash.h xxhash: match output against the original xxhash32 2018-12-18 06:09:01 -05:00