-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This one depends on the timing of a SIGCHLD (needs to happen right when resuming the parent task, so that it gets delivered in the AutoRemoteSyscall for the syscallbuf cleanup), so it's somewhat non-deterministic. However, but exiting fast enough (and the dynamic linker is not), it's possible to trigger this condition quite reliably, so add an executable that does that.
- Loading branch information
Showing
6 changed files
with
132 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ | ||
|
||
#include "util.h" | ||
|
||
static pid_t child_tid; | ||
static char *exe; | ||
|
||
static int do_child(__attribute__((unused)) void* p) { | ||
char* argv[] = { exe, NULL }; | ||
child_tid = sys_gettid(); // Force the syscallbuf to be allocated | ||
execve(exe, argv, environ); | ||
test_assert(0 && "Failed exec!"); | ||
return 0; | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
int i; | ||
pid_t child; | ||
int status; | ||
|
||
test_assert(argc == 2); | ||
exe = argv[1]; | ||
|
||
const size_t stack_size = 1 << 20; | ||
void* stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE, | ||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
|
||
// This test has a slight timing dependency. We want the SIGCHLD from the child process | ||
// exiting to be delivered exactly when the parent process resumes for the first time. | ||
// Our exit_fast executable makes this happen fairly reliably, but we run it a few times, | ||
// just to make sure. | ||
for (i = 0; i < 10; ++i) { | ||
child = clone(do_child, stack + stack_size, | ||
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_VFORK | | ||
CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, | ||
NULL, &child_tid, NULL, &child_tid); | ||
test_assert(child != -1); | ||
test_assert(child == waitpid(child, &status, 0)); | ||
test_assert(WIFEXITED(status) && WEXITSTATUS(status) == 77); | ||
} | ||
|
||
atomic_puts("EXIT-SUCCESS"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source `dirname $0`/util.sh | ||
|
||
save_exe exit_fast$bitness | ||
record $TESTNAME exit_fast$bitness-$nonce | ||
replay | ||
check EXIT-SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ | ||
|
||
#include "util_syscall.h" | ||
|
||
void _start(void) { | ||
unbufferable_syscall(RR_exit, 77, 0, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */ | ||
|
||
#ifndef RRUTIL_SYSCALL_H | ||
#define RRUTIL_SYSCLAL_H | ||
|
||
#include <stdint.h> | ||
|
||
#if defined(__i386__) | ||
#include "SyscallEnumsForTestsX86.generated" | ||
#elif defined(__x86_64__) | ||
#include "SyscallEnumsForTestsX64.generated" | ||
#elif defined(__aarch64__) | ||
#include "SyscallEnumsForTestsGeneric.generated" | ||
#else | ||
#error Unknown architecture | ||
#endif | ||
|
||
static inline uintptr_t unbufferable_syscall(uintptr_t syscall, uintptr_t arg1, | ||
uintptr_t arg2, | ||
uintptr_t arg3) { | ||
uintptr_t ret; | ||
#ifdef __x86_64__ | ||
__asm__ volatile("syscall\n\t" | ||
/* Make sure we don't patch this syscall for syscall buffering */ | ||
"cmp $0x77,%%rax\n\t" | ||
: "=a"(ret) | ||
: "a"(syscall), "D"(arg1), "S"(arg2), "d"(arg3) | ||
: "flags"); | ||
#elif defined(__i386__) | ||
__asm__ volatile("xchg %%esi,%%edi\n\t" | ||
"int $0x80\n\t" | ||
"xchg %%esi,%%edi\n\t" | ||
: "=a"(ret) | ||
: "a"(syscall), "b"(arg1), "c"(arg2), "d"(arg3)); | ||
#elif defined(__aarch64__) | ||
register long x8 __asm__("x8") = syscall; | ||
register long x0 __asm__("x0") = (long)arg1; | ||
register long x1 __asm__("x1") = (long)arg2; | ||
register long x2 __asm__("x2") = (long)arg3; | ||
__asm__ volatile("b 1f\n\t" | ||
"mov x8, 0xdc\n" | ||
"1:\n\t" | ||
"svc #0\n\t" | ||
: "+r"(x0) | ||
: "r"(x1), "r"(x2), "r"(x8)); | ||
ret = x0; | ||
#else | ||
#error define syscall here | ||
#endif | ||
return ret; | ||
} | ||
|
||
#endif |