diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2025-04-11 08:04:51 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2025-04-11 09:37:01 +0000 |
| commit | a2335417592dcd4545c1953807ae9c8906e133d5 (patch) | |
| tree | 919af28ce8d763f29270c69afdd895e194e088ee /pkg/declextract/interface.go | |
| parent | c0efc34f5a3f6a494541381c0f5770200c2640b5 (diff) | |
tools/syz-declextract: export info about file ops interfaces
Diffstat (limited to 'pkg/declextract/interface.go')
| -rw-r--r-- | pkg/declextract/interface.go | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/pkg/declextract/interface.go b/pkg/declextract/interface.go index dd5bfa1d4..e8ace450b 100644 --- a/pkg/declextract/interface.go +++ b/pkg/declextract/interface.go @@ -18,8 +18,8 @@ type Interface struct { Func string Access string Subsystems []string - ManualDescriptions bool - AutoDescriptions bool + ManualDescriptions TristateVal + AutoDescriptions TristateVal ReachableLOC int CoveredBlocks int TotalBlocks int @@ -28,9 +28,19 @@ type Interface struct { scopeVal string } +type TristateVal int + +const ( + TristateUnknown TristateVal = iota + TristateYes + TristateNo +) + const ( IfaceSyscall = "SYSCALL" IfaceNetlinkOp = "NETLINK" + IfaceFileop = "FILEOP" + IfaceIoctl = "IOCTL" IfaceIouring = "IOURING" AccessUnknown = "unknown" @@ -44,6 +54,17 @@ func (ctx *context) noteInterface(iface *Interface) { } func (ctx *context) finishInterfaces() { + ctx.interfaces = sortAndDedupSlice(ctx.interfaces) + count := make(map[string]int) + for _, iface := range ctx.interfaces { + count[iface.Type+iface.Name]++ + } + // Lots of file ops have the same name, add file name to them. + for _, iface := range ctx.interfaces { + if count[iface.Type+iface.Name] > 1 { + iface.Name = iface.Name + "_" + fileNameSuffix(iface.Files[0]) + } + } for _, iface := range ctx.interfaces { ctx.calculateLOC(iface) slices.Sort(iface.Files) @@ -51,6 +72,9 @@ func (ctx *context) finishInterfaces() { if iface.Access == "" { iface.Access = AccessUnknown } + if iface.Access == "" { + iface.Access = AccessUnknown + } } ctx.interfaces = sortAndDedupSlice(ctx.interfaces) } @@ -148,3 +172,45 @@ func (ctx *context) findFunc(name, file string) *Function { } return ctx.funcs[name] } + +func (ctx *context) funcDefinitionFile(name, calledFrom string) string { + fn := ctx.findFunc(name, calledFrom) + if fn == nil { + return "" + } + return fn.File +} + +func fileNameSuffix(file string) string { + // Remove file extension. + ext := strings.LastIndexByte(file, '.') + if ext != -1 { + file = file[:ext] + } + raw := []byte(file) + for i, v := range raw { + if v >= 'a' && v <= 'z' || v >= 'A' && v <= 'Z' || v >= '0' && v <= '9' { + continue + } + raw[i] = '_' + } + return string(raw) +} + +func Tristate(v bool) TristateVal { + if v { + return TristateYes + } + return TristateNo +} + +func (tv TristateVal) String() string { + switch tv { + case TristateYes: + return "true" + case TristateNo: + return "false" + default: + return "unknown" + } +} |
