diff options
| author | Greg Steuck <greg@nest.cx> | 2023-04-24 20:27:30 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2023-04-25 17:36:18 +0200 |
| commit | 7560799c75f65327fe726b5b4b256d23b341709c (patch) | |
| tree | 17248a13063e63424fe909003ec4cf523529fcb0 /sys | |
| parent | 9ceb3140bbe76018aa28dde0297f1139717373dc (diff) | |
sys/targets: introduce HasCallNumber to reduce clutter
This centralizes all strings.HasPrefix(callName, "syz_") checks.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/syz-sysgen/sysgen.go | 6 | ||||
| -rw-r--r-- | sys/targets/targets.go | 4 |
2 files changed, 6 insertions, 4 deletions
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). |
