unicorn/qemu/include/qemu
Eric Blake be742759b0
osdep: Fix ROUND_UP(64-bit, 32-bit)
When using bit-wise operations that exploit the power-of-two
nature of the second argument of ROUND_UP(), we still need to
ensure that the mask is as wide as the first argument (done
by using a ternary to force proper arithmetic promotion).
Unpatched, ROUND_UP(2ULL*1024*1024*1024*1024, 512U) produces 0,
instead of the intended 2TiB, because negation of an unsigned
32-bit quantity followed by widening to 64-bits does not
sign-extend the mask.

Broken since its introduction in commit 292c8e50 (v1.5.0).
Callers that passed the same width type to both macro parameters,
or that had other code to ensure the first parameter's maximum
runtime value did not exceed the second parameter's width, are
unaffected, but I did not audit to see which (if any) existing
clients of the macro could trigger incorrect behavior (I found
the bug while adding a new use of the macro).

While preparing the patch, checkpatch complained about poor
spacing, so I also fixed that here and in the nearby DIV_ROUND_UP.

Backports commit 33a599667a9e70588483a31286dfff8cfc27d513 from qemu
2018-03-04 01:54:09 -05:00
..
atomic.h qemu/atomic: Loosen restrictions for 64-bit ILP32 hosts 2018-03-02 20:06:39 -05:00
bitmap.h bitmap: add bitmap_copy_and_clear_atomic 2018-03-02 18:59:11 -05:00
bitops.h bitops: Add MAKE_64BIT_MASK macro 2018-02-25 00:30:39 -05:00
bswap.h bswap.h: Document cpu_to_* and *_to_cpu conversion functions 2018-02-25 04:06:28 -05:00
compiler.h Drop QEMU_GNUC_PREREQ() checks for gcc older than 4.1 2018-03-02 18:59:05 -05:00
crc32c.h import 2015-08-21 15:04:50 +08:00
cutils.h util/cutils: Change qemu_strtosz*() from int64_t to uint64_t 2018-03-02 08:58:55 -05:00
fprintf-fn.h Clean up decorations and whitespace around header guards 2018-02-25 04:26:02 -05:00
host-utils.h Drop QEMU_GNUC_PREREQ() checks for gcc older than 4.1 2018-03-02 18:59:05 -05:00
int128.h tcg: Add atomic128 helpers 2018-02-27 21:43:48 -05:00
log.h tcg: Lower indirect registers in a separate pass 2018-02-25 22:32:28 -05:00
mmap-alloc.h Clean up ill-advised or unusual header guards 2018-02-25 04:22:46 -05:00
module.h cleanup qemu/include/qemu/module.h 2017-01-25 00:20:08 +08:00
osdep.h osdep: Fix ROUND_UP(64-bit, 32-bit) 2018-03-04 01:54:09 -05:00
queue.h Clean up ill-advised or unusual header guards 2018-02-25 04:22:46 -05:00
range.h range: Replace internal representation of Range 2018-02-25 00:44:36 -05: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 include: move CPU-related definitions out of qemu-common.h 2018-02-24 00:33:49 -05:00
typedefs.h exec: introduce MemoryRegionCache 2018-03-01 10:50:30 -05:00