diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-11-26 16:37:46 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2016-11-26 16:41:40 +0100 |
| commit | c732a41acb817d330610e0e3ebbdcafca6fc2095 (patch) | |
| tree | 8721d2bb959076c5e3124acc7ce2bd9d9912161d /csource | |
| parent | 5d942834552931a373297d3421acd2d731bb9e86 (diff) | |
csource: don't emit syz_ syscalls is they are not used
Diffstat (limited to 'csource')
| -rw-r--r-- | csource/common.go | 29 | ||||
| -rw-r--r-- | csource/csource.go | 8 |
2 files changed, 28 insertions, 9 deletions
diff --git a/csource/common.go b/csource/common.go index 70e84ad1f..5cd07cdfe 100644 --- a/csource/common.go +++ b/csource/common.go @@ -115,6 +115,7 @@ static void install_segv_handler() __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } +#ifdef __NR_syz_open_dev static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2) { if (a0 == 0xc || a0 == 0xb) { @@ -133,7 +134,9 @@ static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2) return open(buf, a2, 0); } } +#endif +#ifdef __NR_syz_open_pts static uintptr_t syz_open_pts(uintptr_t a0, uintptr_t a1) { int ptyno = 0; @@ -143,7 +146,9 @@ static uintptr_t syz_open_pts(uintptr_t a0, uintptr_t a1) sprintf(buf, "/dev/pts/%d", ptyno); return open(buf, a1, 0); } +#endif +#ifdef __NR_syz_fuse_mount static uintptr_t syz_fuse_mount(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5) { uint64_t target = a0; @@ -167,7 +172,9 @@ static uintptr_t syz_fuse_mount(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintpt syscall(SYS_mount, "", target, "fuse", flags, buf); return fd; } +#endif +#ifdef __NR_syz_fuseblk_mount static uintptr_t syz_fuseblk_mount(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7) { uint64_t target = a0; @@ -197,22 +204,33 @@ static uintptr_t syz_fuseblk_mount(uintptr_t a0, uintptr_t a1, uintptr_t a2, uin syscall(SYS_mount, blkdev, target, "fuseblk", flags, buf); return fd; } +#endif static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7, uintptr_t a8) { switch (nr) { default: return syscall(nr, a0, a1, a2, a3, a4, a5); +#ifdef __NR_syz_test case __NR_syz_test: return 0; +#endif +#ifdef __NR_syz_open_dev case __NR_syz_open_dev: return syz_open_dev(a0, a1, a2); +#endif +#ifdef __NR_syz_open_pts case __NR_syz_open_pts: return syz_open_pts(a0, a1); +#endif +#ifdef __NR_syz_fuse_mount case __NR_syz_fuse_mount: return syz_fuse_mount(a0, a1, a2, a3, a4, a5); +#endif +#ifdef __NR_syz_fuseblk_mount case __NR_syz_fuseblk_mount: return syz_fuseblk_mount(a0, a1, a2, a3, a4, a5, a6, a7); +#endif } } @@ -405,7 +423,8 @@ retry: remove_dir(filename); continue; } - for (int i = 0;; i++) { + int i; + for (i = 0;; i++) { debug("unlink(%s)\n", filename); if (unlink(filename) == 0) break; @@ -421,7 +440,8 @@ retry: } } closedir(dp); - for (int i = 0;; i++) { + int i; + for (i = 0;; i++) { debug("rmdir(%s)\n", dir); if (rmdir(dir) == 0) break; @@ -447,6 +467,7 @@ retry: } } +#if defined(SYZ_EXECUTOR) || defined(SYZ_REPEAT) static uint64_t current_time_ms() { struct timespec ts; @@ -455,13 +476,15 @@ static uint64_t current_time_ms() fail("clock_gettime failed"); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } +#endif #if defined(SYZ_REPEAT) static void test(); void loop() { - for (int iter = 0;; iter++) { + int iter; + for (iter = 0;; iter++) { char cwdbuf[256]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) diff --git a/csource/csource.go b/csource/csource.go index 4464deb5c..0c4d93ed3 100644 --- a/csource/csource.go +++ b/csource/csource.go @@ -38,11 +38,6 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) { for _, c := range p.Calls { handled[c.Meta.CallName] = c.Meta.NR } - for _, c := range sys.Calls { - if strings.HasPrefix(c.CallName, "syz_") { - handled[c.CallName] = c.NR - } - } for name, nr := range handled { fmt.Fprintf(w, "#ifndef __NR_%v\n", name) fmt.Fprintf(w, "#define __NR_%v %v\n", name, nr) @@ -80,7 +75,8 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) { fmt.Fprint(w, "\treturn 0;\n}\n") } else { fmt.Fprint(w, "int main()\n{\n") - fmt.Fprintf(w, "\tfor (int i = 0; i < %v; i++) {\n", opts.Procs) + fmt.Fprint(w, "\tint i;") + fmt.Fprintf(w, "\tfor (i = 0; i < %v; i++) {\n", opts.Procs) fmt.Fprint(w, "\t\tif (fork() == 0) {\n") fmt.Fprint(w, "\t\t\tsetup_main_process();\n") fmt.Fprintf(w, "\t\t\tdo_sandbox_%v();\n", opts.Sandbox) |
