From 80d43738f1e4c648ccfc4599e17dc8ba455fe1ea Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 14 Mar 2020 16:42:00 +0100 Subject: prog: rename target.SanitizeCall to Neutralize We will need a wrapper for target.SanitizeCall that will do more than just calling the target-provided function. To avoid confusion and potential mistakes, give the target function and prog function different names. Prog package will continue to call this "sanitize", which will include target's "neutralize" + more. Also refactor API a bit: we need a helper function that sanitizes the whole program because that's needed most of the time. Fixes #477 Fixes #502 --- prog/target.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'prog/target.go') diff --git a/prog/target.go b/prog/target.go index 69398a54d..b19645ea2 100644 --- a/prog/target.go +++ b/prog/target.go @@ -28,8 +28,9 @@ type Target struct { // MakeMmap creates call that maps [addr, addr+size) memory range. MakeMmap func(addr, size uint64) *Call - // SanitizeCall neutralizes harmful calls. - SanitizeCall func(c *Call) + // Neutralize neutralizes harmful calls by transforming them into non-harmful ones + // (e.g. an ioctl that turns off console output is turned into ioctl that turns on output). + Neutralize func(c *Call) // AnnotateCall annotates a syscall invocation in C reproducers. // The returned string will be placed inside a comment except for the @@ -113,7 +114,7 @@ func AllTargets() []*Target { } func (target *Target) lazyInit() { - target.SanitizeCall = func(c *Call) {} + target.Neutralize = func(c *Call) {} target.AnnotateCall = func(c ExecCall) string { return "" } target.initTarget() target.initArch(target) @@ -165,6 +166,11 @@ func (target *Target) GetConst(name string) uint64 { return v } +func (target *Target) sanitize(c *Call, fix bool) error { + target.Neutralize(c) + return nil +} + func RestoreLinks(syscalls []*Syscall, resources []*ResourceDesc, structs []*KeyedStruct) { restoreLinks(syscalls, resources, structs) } @@ -277,7 +283,7 @@ func MakeProgGen(target *Target) *Builder { func (pg *Builder) Append(c *Call) error { pg.target.assignSizesCall(c) - pg.target.SanitizeCall(c) + pg.target.sanitize(c, true) pg.p.Calls = append(pg.p.Calls, c) return nil } -- cgit mrf-deployment