aboutsummaryrefslogtreecommitdiffstats
path: root/executor/common_linux.h
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-07-26 17:47:27 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-07-27 10:22:23 +0200
commit9d92841b4e4d0ac0f97f983cd90087323f27c26c (patch)
tree562c5d32f96e010c34b3f122616213110d1b979b /executor/common_linux.h
parentc3da5dc5e0d0c6614f48c2d1178d58ff1e47809c (diff)
pkg/csource: tidy generated code
1. Remove unnecessary includes. 2. Remove thunk function in threaded mode. 3. Inline syscalls into main for the simplest case. 4. Define main in common.h rather than form with printfs. 5. Fix generation for repeat mode (we had 2 infinite loops: in main and in loop). 6. Remove unused functions (setup/reset_loop, setup/reset_test, sandbox_namespace, etc).
Diffstat (limited to 'executor/common_linux.h')
-rw-r--r--executor/common_linux.h27
1 files changed, 20 insertions, 7 deletions
diff --git a/executor/common_linux.h b/executor/common_linux.h
index ad653f396..4ff59aa80 100644
--- a/executor/common_linux.h
+++ b/executor/common_linux.h
@@ -4,7 +4,6 @@
// This file is shared between executor and csource package.
#include <stdlib.h>
-#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
@@ -641,8 +640,6 @@ static long syz_genetlink_get_family_id(long name)
#include <sys/stat.h>
#include <sys/types.h>
-extern unsigned long long procid;
-
struct fs_image_segment {
void* data;
uintptr_t size;
@@ -758,6 +755,9 @@ error:
#endif
#if SYZ_EXECUTOR || __NR_syz_mount_image
+#include <string.h>
+#include <sys/mount.h>
+
//syz_mount_image(fs ptr[in, string[disk_filesystems]], dir ptr[in, filename], size intptr, nsegs len[segments], segments ptr[in, array[fs_image_segment]], flags flags[mount_flags], opts ptr[in, fs_options[vfat_options]])
//fs_image_segment {
// data ptr[in, array[int8]]
@@ -885,6 +885,7 @@ static long syz_kvm_setup_cpu(long a0, long a1, long a2, long a3, long a4, long
#include <fcntl.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -916,6 +917,7 @@ static bool write_file(const char* file, const char* what, ...)
#include <errno.h>
#include <linux/net.h>
#include <netinet/in.h>
+#include <string.h>
#include <sys/socket.h>
// checkpoint/reset_net_namespace partially resets net namespace to initial state
@@ -1572,6 +1574,7 @@ static int do_sandbox_setuid(void)
#include <linux/capability.h>
#include <sched.h>
#include <sys/mman.h>
+#include <sys/mount.h>
static int real_uid;
static int real_gid;
@@ -1706,6 +1709,8 @@ static int do_sandbox_namespace(void)
#if SYZ_EXECUTOR || SYZ_REPEAT && SYZ_USE_TMP_DIR
#include <dirent.h>
#include <errno.h>
+#include <string.h>
+#include <sys/mount.h>
// One does not simply remove a directory.
// There can be mounts, so we need to try to umount.
@@ -1795,6 +1800,7 @@ retry:
#if SYZ_EXECUTOR || SYZ_FAULT_INJECTION
#include <fcntl.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -1832,16 +1838,14 @@ static int fault_injected(int fail_fd)
}
#endif
-#if SYZ_EXECUTOR || SYZ_REPEAT
+#if SYZ_EXECUTOR || SYZ_REPEAT && SYZ_ENABLE_CGROUPS
#include <fcntl.h>
#include <sys/ioctl.h>
-#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-extern unsigned long long procid;
-
+#define SYZ_HAVE_SETUP_LOOP 1
static void setup_loop()
{
#if SYZ_ENABLE_CGROUPS
@@ -1874,7 +1878,10 @@ static void setup_loop()
}
#endif
}
+#endif
+#if SYZ_EXECUTOR || SYZ_REPEAT && (SYZ_RESET_NET_NAMESPACE || __NR_syz_mount_image || __NR_syz_read_part_table)
+#define SYZ_HAVE_RESET_LOOP 1
static void reset_loop()
{
#if SYZ_EXECUTOR || __NR_syz_mount_image || __NR_syz_read_part_table
@@ -1890,7 +1897,12 @@ static void reset_loop()
reset_net_namespace();
#endif
}
+#endif
+
+#if SYZ_EXECUTOR || SYZ_REPEAT
+#include <sys/prctl.h>
+#define SYZ_HAVE_SETUP_TEST 1
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
@@ -1917,6 +1929,7 @@ static void setup_test()
#endif
}
+#define SYZ_HAVE_RESET_TEST 1
static void reset_test()
{
// Keeping a 9p transport pipe open will hang the proccess dead,