[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/12] util/main-loop: Avoid adding the same HANDLE twice
From: |
Paolo Bonzini |
Subject: |
[PULL 02/12] util/main-loop: Avoid adding the same HANDLE twice |
Date: |
Sun, 6 Nov 2022 09:51:05 +0100 |
From: Bin Meng <bin.meng@windriver.com>
Fix the logic in qemu_add_wait_object() to avoid adding the same
HANDLE twice, as the behavior is undefined when passing an array
that contains same HANDLEs to WaitForMultipleObjects() API.
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Message-Id: <20221019102015.2441622-2-bmeng.cn@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/qemu/main-loop.h | 2 ++
util/main-loop.c | 10 ++++++++++
2 files changed, 12 insertions(+)
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index aac707d073a1..3c9a9a982def 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -157,6 +157,8 @@ typedef void WaitObjectFunc(void *opaque);
* in the main loop's calls to WaitForMultipleObjects. When the handle
* is in a signaled state, QEMU will call @func.
*
+ * If the same HANDLE is added twice, this function returns -1.
+ *
* @handle: The Windows handle to be observed.
* @func: A function to be called when @handle is in a signaled state.
* @opaque: A pointer-size value that is passed to @func.
diff --git a/util/main-loop.c b/util/main-loop.c
index de38876064e4..10fa74c6e319 100644
--- a/util/main-loop.c
+++ b/util/main-loop.c
@@ -373,10 +373,20 @@ static WaitObjects wait_objects = {0};
int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
{
+ int i;
WaitObjects *w = &wait_objects;
+
if (w->num >= MAXIMUM_WAIT_OBJECTS) {
return -1;
}
+
+ for (i = 0; i < w->num; i++) {
+ /* check if the same handle is added twice */
+ if (w->events[i] == handle) {
+ return -1;
+ }
+ }
+
w->events[w->num] = handle;
w->func[w->num] = func;
w->opaque[w->num] = opaque;
--
2.38.1
- [PULL 00/12] Misc bugfix patches (+ improved module errors) for QEMU 7.2, Paolo Bonzini, 2022/11/06
- [PULL 01/12] util/main-loop: Fix maximum number of wait objects for win32, Paolo Bonzini, 2022/11/06
- [PULL 02/12] util/main-loop: Avoid adding the same HANDLE twice,
Paolo Bonzini <=
- [PULL 04/12] gdb-xml: Fix size of EFER register on i386 architecture when debugged by GDB, Paolo Bonzini, 2022/11/06
- [PULL 03/12] util/aio-win32: Correct the event array size in aio_poll(), Paolo Bonzini, 2022/11/06
- [PULL 05/12] Fix broken configure with -Wunused-parameter, Paolo Bonzini, 2022/11/06
- [PULL 06/12] meson: avoid unused arguments of main() in compiler tests, Paolo Bonzini, 2022/11/06
- [PULL 07/12] Add missing include statement for global xml_builtin, Paolo Bonzini, 2022/11/06
- [PULL 08/12] module: removed unused function argument "mayfail", Paolo Bonzini, 2022/11/06
- [PULL 09/12] module: rename module_load_one to module_load, Paolo Bonzini, 2022/11/06
- [PULL 10/12] module: add Error arguments to module_load and module_load_qom, Paolo Bonzini, 2022/11/06
- [PULL 11/12] dmg: warn when opening dmg images containing blocks of unknown type, Paolo Bonzini, 2022/11/06
- [PULL 12/12] accel: abort if we fail to load the accelerator plugin, Paolo Bonzini, 2022/11/06