aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/csource/csource.go
diff options
context:
space:
mode:
authorAndrey Artemiev <artemiev@google.com>2022-08-06 05:17:33 -0700
committerGitHub <noreply@github.com>2022-08-06 14:17:33 +0200
commit88e3a1226bc591d81c1fb98e83cb63cd4f341c6e (patch)
tree323b7fa492a8d9698e432c1d3bd4514771fc3252 /pkg/csource/csource.go
parente853abd9a2542fcccb8e1a23eb8ae475500ecaf9 (diff)
pkg/csource, pkg/instance, pkg/ipc, pkg/mgrconfig, tools/syz-prog2c, syz-manager: introduce a new setting 'sandbox_arg' (#3263)
Diffstat (limited to 'pkg/csource/csource.go')
-rw-r--r--pkg/csource/csource.go22
1 files changed, 14 insertions, 8 deletions
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),