From 3da9017c17c7d2432c4b76345c4d2efbeedd2935 Mon Sep 17 00:00:00 2001 From: Joey Jiaojg Date: Wed, 26 May 2021 19:38:04 +0800 Subject: pkg/compiler: add glob type * all: add new typename dirname The current way to check files under sysfs or proc is: - define a string to represent each file - open the file - pass the fd to write / read / close The issues above are: - Need to know what file present on target device - Need to write openat for each file With dirname added, which will open one file in the directory randomly and then pass the fd to write/read/close. * all: use typename glob to match filename Fixes #481 --- prog/target.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'prog/target.go') diff --git a/prog/target.go b/prog/target.go index f2eaf6ead..974880c22 100644 --- a/prog/target.go +++ b/prog/target.go @@ -227,6 +227,31 @@ func (target *Target) DefaultChoiceTable() *ChoiceTable { return target.defaultChoiceTable } +func (target *Target) GetGlobs() []string { + var globs []string + ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) { + switch a := typ.(type) { + case *BufferType: + if a.Kind == BufferGlob && a.SubKind != "" { + globs = append(globs, a.SubKind) + } + } + }) + + return globs +} + +func (target *Target) UpdateGlobFilesForType(globFiles map[string][]string) { + ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) { + switch a := typ.(type) { + case *BufferType: + if a.Kind == BufferGlob && a.SubKind != "" { + a.Values = globFiles[a.SubKind] + } + } + }) +} + type Gen struct { r *randGen s *state -- cgit mrf-deployment