diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-05-29 14:33:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-29 14:33:50 +0200 |
| commit | baf825803c72cdc02bed92a5f84ec43482aa35d3 (patch) | |
| tree | c9594f9450bb91ce03a5f671f53755c193077ef3 /executor/common.h | |
| parent | 145e067777cb0d21644412548e67dcb934f1da5e (diff) | |
| parent | eaf1f711fc42235d0b9a73c6877d14b1b5244194 (diff) | |
Merge pull request #196 from dvyukov/executor-fault-inject3
fault injection and faster tests
Diffstat (limited to 'executor/common.h')
| -rw-r--r-- | executor/common.h | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/executor/common.h b/executor/common.h index c32341f57..73a528471 100644 --- a/executor/common.h +++ b/executor/common.h @@ -699,13 +699,7 @@ static int do_sandbox_setuid(int executor_pid, bool enable_tun) } #endif -#if defined(SYZ_EXECUTOR) || defined(SYZ_SANDBOX_NAMESPACE) -static int real_uid; -static int real_gid; -static int epid; -static bool etun; -__attribute__((aligned(64 << 10))) static char sandbox_stack[1 << 20]; - +#if defined(SYZ_EXECUTOR) || defined(SYZ_SANDBOX_NAMESPACE) || defined(SYZ_FAULT_INJECTION) static bool write_file(const char* file, const char* what, ...) { char buf[1024]; @@ -726,6 +720,14 @@ static bool write_file(const char* file, const char* what, ...) close(fd); return true; } +#endif + +#if defined(SYZ_EXECUTOR) || defined(SYZ_SANDBOX_NAMESPACE) +static int real_uid; +static int real_gid; +static int epid; +static bool etun; +__attribute__((aligned(64 << 10))) static char sandbox_stack[1 << 20]; static int namespace_sandbox_proc(void* arg) { @@ -897,6 +899,23 @@ static uint64_t current_time_ms() } #endif +#if defined(SYZ_EXECUTOR) || defined(SYZ_FAULT_INJECTION) +static int inject_fault(int nth) +{ + int fd; + char buf[128]; + + sprintf(buf, "/proc/self/task/%d/fail-nth", (int)syscall(SYS_gettid)); + fd = open(buf, O_RDWR); + if (fd == -1) + fail("failed to open /proc/self/task/tid/fail-nth"); + sprintf(buf, "%d", nth + 1); + if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) + fail("failed to write /proc/self/task/tid/fail-nth"); + return fd; +} +#endif + #if defined(SYZ_REPEAT) static void test(); |
