aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorFlorent Revest <revest@chromium.org>2023-06-08 17:56:49 +0200
committerAleksandr Nogikh <wp32pw@gmail.com>2023-06-09 17:56:11 +0200
commit49519f067f7fc9bfbf869e6851a4d398a9f7863f (patch)
treeaaab672be53e832a098f8797fad2cdebadf67cf6 /pkg
parentf6c9fc7b5ee92530706841871ae962f2300f4f26 (diff)
pkg/csource: annotate syscall() args with their names
This annotates syscall arguments so they are easier to read without having to pull out the syscall's man page. E.g: syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, ... Signed-off-by: Florent Revest <revest@chromium.org>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/csource/csource.go12
-rw-r--r--pkg/csource/csource_test.go14
2 files changed, 16 insertions, 10 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go
index 0c9f78e71..54cf2fa39 100644
--- a/pkg/csource/csource.go
+++ b/pkg/csource/csource.go
@@ -351,25 +351,27 @@ func (ctx *context) fmtCallBody(call prog.ExecCall) string {
}
funcName = fmt.Sprintf("((intptr_t(*)(%v))CAST(%v))", args, callName)
}
- for _, arg := range call.Args {
+ for i, arg := range call.Args {
switch arg := arg.(type) {
case prog.ExecArgConst:
if arg.Format != prog.FormatNative && arg.Format != prog.FormatBigEndian {
panic("string format in syscall argument")
}
+ com := ctx.argComment(call.Meta.Args[i], arg)
suf := ctx.literalSuffix(arg, native)
- argsStrs = append(argsStrs, handleBigEndian(arg, ctx.constArgToStr(arg, suf)))
+ argsStrs = append(argsStrs, com+handleBigEndian(arg, ctx.constArgToStr(arg, suf)))
case prog.ExecArgResult:
if arg.Format != prog.FormatNative && arg.Format != prog.FormatBigEndian {
panic("string format in syscall argument")
}
+ com := ctx.argComment(call.Meta.Args[i], arg)
val := ctx.resultArgToStr(arg)
if native && ctx.target.PtrSize == 4 {
// syscall accepts args as ellipsis, resources are uint64
// and take 2 slots without the cast, which would be wrong.
val = "(intptr_t)" + val
}
- argsStrs = append(argsStrs, val)
+ argsStrs = append(argsStrs, com+val)
default:
panic(fmt.Sprintf("unknown arg type: %+v", arg))
}
@@ -499,6 +501,10 @@ func (ctx *context) copyout(w *bytes.Buffer, call prog.ExecCall, resCopyout bool
}
}
+func (ctx *context) argComment(field prog.Field, arg prog.ExecArg) string {
+ return "/*" + field.Name + "=" + "*/"
+}
+
func (ctx *context) constArgToStr(arg prog.ExecArgConst, suffix string) string {
mask := (uint64(1) << (arg.Size * 8)) - 1
v := arg.Value & mask
diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go
index 2eb8cd150..eb85fd77b 100644
--- a/pkg/csource/csource_test.go
+++ b/pkg/csource/csource_test.go
@@ -191,10 +191,10 @@ r0 = csource0(0x1)
csource1(r0)
`,
output: `
-res = syscall(SYS_csource0, 1);
+res = syscall(SYS_csource0, /*num=*/1);
if (res != -1)
r[0] = res;
-syscall(SYS_csource1, r[0]);
+syscall(SYS_csource1, /*fd=*/r[0]);
`,
},
{
@@ -207,15 +207,15 @@ csource6(&AUTO)
`,
output: fmt.Sprintf(`
NONFAILING(memcpy((void*)0x%x, "\x12\x34\x56\x78", 4));
-syscall(SYS_csource2, 0x%xul);
+syscall(SYS_csource2, /*buf=*/0x%xul);
NONFAILING(memset((void*)0x%x, 0, 10));
-syscall(SYS_csource3, 0x%xul);
+syscall(SYS_csource3, /*buf=*/0x%xul);
NONFAILING(memset((void*)0x%x, 48, 10));
-syscall(SYS_csource4, 0x%xul);
+syscall(SYS_csource4, /*buf=*/0x%xul);
NONFAILING(memcpy((void*)0x%x, "0101010101", 10));
-syscall(SYS_csource5, 0x%xul);
+syscall(SYS_csource5, /*buf=*/0x%xul);
NONFAILING(memcpy((void*)0x%x, "101010101010", 12));
-syscall(SYS_csource6, 0x%xul);
+syscall(SYS_csource6, /*buf=*/0x%xul);
`,
target.DataOffset+0x40, target.DataOffset+0x40,
target.DataOffset+0x80, target.DataOffset+0x80,