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 /pkg | |
| parent | 9ceb3140bbe76018aa28dde0297f1139717373dc (diff) | |
sys/targets: introduce HasCallNumber to reduce clutter
This centralizes all strings.HasPrefix(callName, "syz_") checks.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/compiler/consts.go | 2 | ||||
| -rw-r--r-- | pkg/csource/csource.go | 5 |
2 files changed, 3 insertions, 4 deletions
diff --git a/pkg/compiler/consts.go b/pkg/compiler/consts.go index 3e8773a03..48a4f55aa 100644 --- a/pkg/compiler/consts.go +++ b/pkg/compiler/consts.go @@ -69,7 +69,7 @@ func (comp *compiler) extractConsts() map[string]*ConstInfo { info.defines[name] = v comp.addConst(infos, pos, name) case *ast.Call: - if comp.target.SyscallNumbers && !strings.HasPrefix(n.CallName, "syz_") { + if comp.target.HasCallNumber(n.CallName) { comp.addConst(infos, pos, comp.target.SyscallPrefix+n.CallName) } for _, attr := range n.Attrs { diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go index aedcf0d19..0c9f78e71 100644 --- a/pkg/csource/csource.go +++ b/pkg/csource/csource.go @@ -214,8 +214,7 @@ func (ctx *context) generateSyscalls(calls []string, hasVars bool) string { func (ctx *context) generateSyscallDefines() string { var calls []string for name, nr := range ctx.calls { - if !ctx.sysTarget.SyscallNumbers || - strings.HasPrefix(name, "syz_") || !ctx.sysTarget.NeedSyscallDefine(nr) { + if !ctx.sysTarget.HasCallNumber(name) || !ctx.sysTarget.NeedSyscallDefine(nr) { continue } calls = append(calls, name) @@ -290,7 +289,7 @@ func (ctx *context) generateCalls(p prog.ExecProg, trace bool) ([]string, []uint func isNative(sysTarget *targets.Target, callName string) bool { _, trampoline := sysTarget.SyscallTrampolines[callName] - return sysTarget.SyscallNumbers && !strings.HasPrefix(callName, "syz_") && !trampoline + return sysTarget.HasCallNumber(callName) && !trampoline } func (ctx *context) emitCall(w *bytes.Buffer, call prog.ExecCall, ci int, haveCopyout, trace bool) { |
