test-flags.c calls mmap() to allocate a page but does not check
whether it succeeded. If the allocation fails, the following
*mprotect()* and *asm* block dereference the invalid pointer and
produce a confusing failure.
Add an assertion to fail early with a clear message.
Fixes: e7bbb7cb71b3 ("target/i386: introduce flags writeback mechanism")
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
tests/tcg/i386/test-flags.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tests/tcg/i386/test-flags.c b/tests/tcg/i386/test-flags.c
index c379e29627..4ecf7053e2 100644
--- a/tests/tcg/i386/test-flags.c
+++ b/tests/tcg/i386/test-flags.c
@@ -21,6 +21,7 @@ int main()
/* fault in the page then protect it */
addr = mmap (NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
+ assert(addr != MAP_FAILED);
*addr = 0x1234;
mprotect(addr, 4096, PROT_READ);
--
2.43.0