Load the write length from guest data instead of an immediate,
and fail unless the syscall writes exactly twelve bytes.
This detects incorrect CPU data byte order rather than merely
accepting the ELF header.

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
 tests/tcg/aarch64_be/hello.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tests/tcg/aarch64_be/hello.c b/tests/tcg/aarch64_be/hello.c
index a9b2ab45de9b..4816635d1704 100644
--- a/tests/tcg/aarch64_be/hello.c
+++ b/tests/tcg/aarch64_be/hello.c
@@ -14,9 +14,10 @@ int write(int fd, char *buf, int len)
     register int x2 __asm__("x2") = len;
     register int x8 __asm__("x8") = __NR_write;
 
-    asm volatile("svc #0" : : "r"(x0), "r"(x1), "r"(x2), "r"(x8));
+    asm volatile("svc #0" : "+r"(x0) : "r"(x1), "r"(x2), "r"(x8)
+                 : "memory");
 
-    return len;
+    return x0;
 }
 
 void exit(int ret)
@@ -30,6 +31,8 @@ void exit(int ret)
 
 void _start(void)
 {
-    write(1, "Hello World\n", 12);
-    exit(0);
+    /* Force a data load to check CPU data byte order. */
+    static volatile int len = 12;
+
+    exit(write(1, "Hello World\n", len) != 12);
 }
-- 
2.55.0

Reply via email to