Add regression test for consecutive syscalls

This commit is contained in:
Justin Becker committed 2026-09-15 17:37:28 -07:00
1 parent 98516b539e
commit 393f7d8702
1 file changed
+34
@@ -0,0 +1,34 @@
#include <catch2/catch_test_macros.hpp>
#include <sys/syscall.h>
#include <unistd.h>
// 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());
}