From 88e3a1226bc591d81c1fb98e83cb63cd4f341c6e Mon Sep 17 00:00:00 2001 From: Andrey Artemiev Date: Sat, 6 Aug 2022 05:17:33 -0700 Subject: pkg/csource, pkg/instance, pkg/ipc, pkg/mgrconfig, tools/syz-prog2c, syz-manager: introduce a new setting 'sandbox_arg' (#3263) --- pkg/csource/csource.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'pkg/csource/csource.go') diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go index 7d3b133bf..df35b54b8 100644 --- a/pkg/csource/csource.go +++ b/pkg/csource/csource.go @@ -28,6 +28,7 @@ import ( "fmt" "regexp" "sort" + "strconv" "strings" "time" @@ -58,6 +59,18 @@ type context struct { calls map[string]uint64 // CallName -> NR } +func generateSandboxFunctionSignature(sandboxName string, sandboxArg int) string { + if sandboxName == "" { + return "loop();" + } + + arguments := "();" + if sandboxName == "android" { + arguments = "(" + strconv.Itoa(sandboxArg) + ");" + } + return "do_sandbox_" + sandboxName + arguments +} + func (ctx *context) generateSource() ([]byte, error) { ctx.filterCalls() calls, vars, err := ctx.generateProgCalls(ctx.p, ctx.opts.Trace) @@ -94,14 +107,7 @@ func (ctx *context) generateSource() ([]byte, error) { fmt.Fprintf(varsBuf, "};\n") } - sandboxFunc := "loop();" - if ctx.opts.Sandbox != "" { - arguments := "();" - if ctx.opts.Sandbox == "android" { - arguments = "(0);" - } - sandboxFunc = "do_sandbox_" + ctx.opts.Sandbox + arguments - } + sandboxFunc := generateSandboxFunctionSignature(ctx.opts.Sandbox, ctx.opts.SandboxArg) replacements := map[string]string{ "PROCS": fmt.Sprint(ctx.opts.Procs), "REPEAT_TIMES": fmt.Sprint(ctx.opts.RepeatTimes), -- cgit mrf-deployment