[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/47] util/oslib: Assert qemu_try_memalign() alignment is a power
From: |
Richard Henderson |
Subject: |
[PULL 05/47] util/oslib: Assert qemu_try_memalign() alignment is a power of 2 |
Date: |
Thu, 7 Jan 2021 10:14:06 -1000 |
From: Philippe Mathieu-Daudé <philmd@redhat.com>
qemu_try_memalign() expects a power of 2 alignment:
- posix_memalign(3):
The address of the allocated memory will be a multiple of alignment,
which must be a power of two and a multiple of sizeof(void *).
- _aligned_malloc()
The alignment value, which must be an integer power of 2.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20201021173803.2619054-3-philmd@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
util/oslib-posix.c | 2 ++
util/oslib-win32.c | 1 +
2 files changed, 3 insertions(+)
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index f1e2801b11..359c52df12 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -201,6 +201,8 @@ void *qemu_try_memalign(size_t alignment, size_t size)
if (alignment < sizeof(void*)) {
alignment = sizeof(void*);
+ } else {
+ g_assert(is_power_of_2(alignment));
}
#if defined(CONFIG_POSIX_MEMALIGN)
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 8adc651259..e6f83e10ed 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -58,6 +58,7 @@ void *qemu_try_memalign(size_t alignment, size_t size)
void *ptr;
g_assert(size != 0);
+ g_assert(is_power_of_2(alignment));
ptr = _aligned_malloc(alignment, size);
trace_qemu_memalign(alignment, size, ptr);
return ptr;
--
2.25.1
- [PULL 00/47] tcg patch queue, Richard Henderson, 2021/01/07
- [PULL 01/47] linux-user: Conditionalize TUNSETVNETLE, Richard Henderson, 2021/01/07
- [PULL 02/47] tcg/i386: Adjust TCG_TARGET_HAS_MEMORY_BSWAP, Richard Henderson, 2021/01/07
- [PULL 03/47] tcg: Introduce INDEX_op_qemu_st8_i32, Richard Henderson, 2021/01/07
- [PULL 04/47] util/oslib-win32: Use _aligned_malloc for qemu_try_memalign, Richard Henderson, 2021/01/07
- [PULL 05/47] util/oslib: Assert qemu_try_memalign() alignment is a power of 2,
Richard Henderson <=
- [PULL 06/47] tcg: Do not flush icache for interpreter, Richard Henderson, 2021/01/07
- [PULL 07/47] util: Enhance flush_icache_range with separate data pointer, Richard Henderson, 2021/01/07
- [PULL 08/47] util: Specialize flush_idcache_range for aarch64, Richard Henderson, 2021/01/07
- [PULL 09/47] tcg: Move tcg prologue pointer out of TCGContext, Richard Henderson, 2021/01/07
- [PULL 10/47] tcg: Move tcg epilogue pointer out of TCGContext, Richard Henderson, 2021/01/07
- [PULL 12/47] tcg: Introduce tcg_splitwx_to_{rx,rw}, Richard Henderson, 2021/01/07
- [PULL 14/47] tcg: Adjust tcg_out_call for const, Richard Henderson, 2021/01/07
- [PULL 13/47] tcg: Adjust TCGLabel for const, Richard Henderson, 2021/01/07
- [PULL 11/47] tcg: Add in_code_gen_buffer, Richard Henderson, 2021/01/07
- [PULL 15/47] tcg: Adjust tcg_out_label for const, Richard Henderson, 2021/01/07