From 7560799c75f65327fe726b5b4b256d23b341709c Mon Sep 17 00:00:00 2001 From: Greg Steuck Date: Mon, 24 Apr 2023 20:27:30 +0100 Subject: sys/targets: introduce HasCallNumber to reduce clutter This centralizes all strings.HasPrefix(callName, "syz_") checks. --- sys/syz-sysgen/sysgen.go | 6 ++---- sys/targets/targets.go | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'sys') diff --git a/sys/syz-sysgen/sysgen.go b/sys/syz-sysgen/sysgen.go index 2ac48e94e..0459d544f 100644 --- a/sys/syz-sysgen/sysgen.go +++ b/sys/syz-sysgen/sysgen.go @@ -12,7 +12,6 @@ import ( "path/filepath" "reflect" "sort" - "strings" "sync" "text/template" @@ -287,8 +286,7 @@ func generateExecutorSyscalls(target *targets.Target, syscalls []*prog.Syscall, data.Calls = append(data.Calls, newSyscallData(target, c, attrVals[:last+1])) // Some syscalls might not be present on the compiling machine, so we // generate definitions for them. - if target.SyscallNumbers && !strings.HasPrefix(c.CallName, "syz_") && - target.NeedSyscallDefine(c.NR) { + if target.HasCallNumber(c.CallName) && target.NeedSyscallDefine(c.NR) { defines[target.SyscallPrefix+c.CallName] = fmt.Sprintf("%d", c.NR) } } @@ -316,7 +314,7 @@ func newSyscallData(target *targets.Target, sc *prog.Syscall, attrs []uint64) Sy Name: sc.Name, CallName: callName, NR: int32(sc.NR), - NeedCall: (!target.SyscallNumbers || strings.HasPrefix(sc.CallName, "syz_") || patchCallName) && !sc.Attrs.Disabled, + NeedCall: (!target.HasCallNumber(sc.CallName) || patchCallName) && !sc.Attrs.Disabled, Attrs: attrs, } } diff --git a/sys/targets/targets.go b/sys/targets/targets.go index 99c64725a..67c3161e4 100644 --- a/sys/targets/targets.go +++ b/sys/targets/targets.go @@ -46,6 +46,10 @@ type Target struct { timeouts Timeouts } +func (target *Target) HasCallNumber(callName string) bool { + return target.SyscallNumbers && !strings.HasPrefix(callName, "syz_") +} + type osCommon struct { // What OS can build native binaries for this OS. // If not set, defaults to itself (i.e. native build). -- cgit mrf-deployment