Load the write length from guest data instead of an immediate, and fail unless the syscall writes exactly 12 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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/tcg/aarch64_be/hello.c b/tests/tcg/aarch64_be/hello.c index a9b2ab45de9b..18432d3257dd 100644 --- a/tests/tcg/aarch64_be/hello.c +++ b/tests/tcg/aarch64_be/hello.c @@ -7,16 +7,17 @@ #define __NR_write 64 #define __NR_exit 93 -int write(int fd, char *buf, int len) +int write(int fd, const char *buf, int len) { register int x0 __asm__("x0") = fd; - register char *x1 __asm__("x1") = buf; + register const char *x1 __asm__("x1") = buf; 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,9 @@ 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 const char hello[] = "Hello World\n"; + static volatile int len = sizeof(hello) - 1; + + exit(write(1, hello, len) != len); } -- 2.55.0
