From 8144982a26c6b8e5f0f5401c2a2de99e4ced04cd Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 19 Sep 2023 16:46:40 +0200 Subject: sys: refactor const extraction 1) Make FabricateSyscallConsts() operate on ConstFile. 2) Expose Pos inside ConstInfo. --- sys/syz-extract/fetch.go | 16 ++++++++-------- sys/syz-extract/netbsd.go | 16 ++++++++-------- sys/syz-extract/openbsd.go | 10 +++++----- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'sys/syz-extract') diff --git a/sys/syz-extract/fetch.go b/sys/syz-extract/fetch.go index a7a0e46fe..834189fff 100644 --- a/sys/syz-extract/fetch.go +++ b/sys/syz-extract/fetch.go @@ -39,8 +39,8 @@ func extract(info *compiler.ConstInfo, cc string, args []string, params *extract missingIncludes := make(map[string]bool) undeclared := make(map[string]bool) valMap := make(map[string]bool) - for _, val := range info.Consts { - valMap[val] = true + for _, def := range info.Consts { + valMap[def.Name] = true } for { bin1, out, err := compile(cc, args, data) @@ -74,11 +74,11 @@ func extract(info *compiler.ConstInfo, cc string, args []string, params *extract cc, args, err, out) } data.Values = nil - for _, v := range info.Consts { - if undeclared[v] { + for _, def := range info.Consts { + if undeclared[def.Name] { continue } - data.Values = append(data.Values, v) + data.Values = append(data.Values, def) } data.Includes = nil for _, v := range info.Includes { @@ -105,8 +105,8 @@ func extract(info *compiler.ConstInfo, cc string, args []string, params *extract len(flagVals), len(data.Values)) } res := make(map[string]uint64) - for i, name := range data.Values { - res[name] = flagVals[i] + for i, def := range data.Values { + res[def.Name] = flagVals[i] } return res, undeclared, nil } @@ -115,7 +115,7 @@ type CompileData struct { *extractParams Defines map[string]string Includes []string - Values []string + Values []*compiler.Const } func compile(cc string, args []string, data *CompileData) (string, []byte, error) { diff --git a/sys/syz-extract/netbsd.go b/sys/syz-extract/netbsd.go index 8cc5efac0..b2ce7d620 100644 --- a/sys/syz-extract/netbsd.go +++ b/sys/syz-extract/netbsd.go @@ -72,20 +72,20 @@ func (*netbsd) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uin // Syscall consts on netbsd have weird prefixes sometimes, // try to extract consts with these prefixes as well. compatNames := make(map[string][]string) - for _, val := range info.Consts { + for _, def := range info.Consts { const SYS = "SYS_" - if strings.HasPrefix(val, SYS) { + if strings.HasPrefix(def.Name, SYS) { for _, prefix := range []string{"_", "__", "___"} { for _, suffix := range []string{"30", "50"} { - compat := SYS + prefix + val[len(SYS):] + suffix - compatNames[val] = append(compatNames[val], compat) - info.Consts = append(info.Consts, compat) + compat := SYS + prefix + def.Name[len(SYS):] + suffix + compatNames[def.Name] = append(compatNames[def.Name], compat) + info.Consts = append(info.Consts, &compiler.Const{Name: compat}) } } } else { - compat := "LINUX_" + val - compatNames[val] = append(compatNames[val], compat) - info.Consts = append(info.Consts, compat) + compat := "LINUX_" + def.Name + compatNames[def.Name] = append(compatNames[def.Name], compat) + info.Consts = append(info.Consts, &compiler.Const{Name: compat}) } } params := &extractParams{ diff --git a/sys/syz-extract/openbsd.go b/sys/syz-extract/openbsd.go index f103d1949..9d9a7026e 100644 --- a/sys/syz-extract/openbsd.go +++ b/sys/syz-extract/openbsd.go @@ -71,11 +71,11 @@ func (*openbsd) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]ui "SYS_tmpfd": true, } compatNames := make(map[string][]string) - for _, val := range info.Consts { - if _, ok := syscallsQuirks[val]; ok { - compat := "SYS___" + val[len("SYS_"):] - compatNames[val] = append(compatNames[val], compat) - info.Consts = append(info.Consts, compat) + for _, def := range info.Consts { + if _, ok := syscallsQuirks[def.Name]; ok { + compat := "SYS___" + def.Name[len("SYS_"):] + compatNames[def.Name] = append(compatNames[def.Name], compat) + info.Consts = append(info.Consts, &compiler.Const{Name: compat}) } } params := &extractParams{ -- cgit mrf-deployment