1// Copyright 2015 syzkaller project authors. All rights reserved. 2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4// +build linux 5 6package host 7 8import ( 9 "runtime" 10 "syscall" 11 "testing" 12 13 "github.com/google/syzkaller/prog" 14) 15 16func TestSupportedSyscalls(t *testing.T) { 17 t.Parallel() 18 target, err := prog.GetTarget("linux", runtime.GOARCH) 19 if err != nil { 20 t.Fatal(err) 21 } 22 supp, _, err := DetectSupportedSyscalls(target, "none") 23 if err != nil { 24 t.Skipf("skipping: %v", err) 25 } 26 // These are safe to execute with invalid arguments. 27 safe := []string{ 28 "memfd_create", 29 "sendfile", 30 "bpf$MAP_CREATE", 31 "open", 32 "openat", 33 "read", 34 "write", 35 "stat", 36 } 37 for _, name := range safe { 38 c := target.SyscallMap[name] 39 if c == nil { 40 t.Fatalf("can't find syscall '%v'", name) 41 } 42 a := ^uintptr(0) - 4097 // hopefully invalid 43 _, _, err := syscall.Syscall6(uintptr(c.NR), a, a, a, a, a, a) 44 if err == 0 { 45 t.Fatalf("%v did not fail", name) 46 } 47 if ok := err != syscall.ENOSYS; ok != supp[c] { 48 t.Fatalf("syscall %v: perse=%v kallsyms=%v", name, ok, supp[c]) 49 } 50 } 51} 52