diff --git a/unittests/FEXLinuxTests/tests/syscalls/consecutive_syscalls.cpp b/unittests/FEXLinuxTests/tests/syscalls/consecutive_syscalls.cpp new file mode 100644 index 000000000..520db3edb --- /dev/null +++ b/unittests/FEXLinuxTests/tests/syscalls/consecutive_syscalls.cpp @@ -0,0 +1,34 @@ +#include + +#include +#include + +// Regression test for issue #5942. Not ending the block after a syscall +// can cause the register state to be incorrect afterwards, demonstrated here +// by running two syscalls in a row in the same block. +TEST_CASE("Two syscalls in one block") { + long Result {}; +#ifdef __x86_64__ + __asm volatile(R"( + mov eax, %[GetPPid] + syscall + mov eax, %[GetPPid] + syscall + )" + : "=a"(Result) + : [GetPPid] "i"(SYS_getppid) + : "rcx", "r11", "memory"); +#else + __asm volatile(R"( + mov eax, %[GetPPid] + int 0x80 + mov eax, %[GetPPid] + int 0x80 + )" + : "=a"(Result) + : [GetPPid] "i"(SYS_getppid) + : "memory"); +#endif + + CHECK(Result == ::getppid()); +}