Skip to content

Commit 392fe1b

Browse files
committed
tools/mkwinsyscall: replace deprecated funcs with SyscallN (drops go1.17)
The "syscall.Syscall<number>" functions were deprecated in go1.18 in favor of the "syscall.SyscallN" function, which does not need the "nargs" argument, and does not need the list of arguments to be padded with zeros. https://github.com/golang/go/blob/go1.18/src/syscall/dll_windows.go#L27-L45 Now that go1.17 reached EOL and is no longer maintained, we can update the code to use the new SyscallN function. This patch updates the mkwinsyscall utility to generate code using the new SyscallN function, and removes the utilities that are now redundant. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 5748f02 commit 392fe1b

File tree

8 files changed

+66
-98
lines changed

8 files changed

+66
-98
lines changed

internal/socket/zsyscall_windows.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindfilter/zsyscall_windows.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/etw/zsyscall_windows.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/process/zsyscall_windows.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/security/zsyscall_windows.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/mkwinsyscall/mkwinsyscall.go

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"path/filepath"
2222
"runtime"
2323
"sort"
24-
"strconv"
2524
"strings"
2625
"text/template"
2726

@@ -541,54 +540,23 @@ func (f *Fn) ParamPrintList() string {
541540
return join(f.Params, func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `)
542541
}
543542

544-
// ParamCount return number of syscall parameters for function f.
545-
func (f *Fn) ParamCount() int {
546-
n := 0
547-
for _, p := range f.Params {
548-
n += len(p.SyscallArgList())
549-
}
550-
return n
551-
}
552-
553-
// SyscallParamCount determines which version of Syscall/Syscall6/Syscall9/...
554-
// to use. It returns parameter count for correspondent SyscallX function.
555-
func (f *Fn) SyscallParamCount() int {
556-
n := f.ParamCount()
557-
switch {
558-
case n <= 3:
559-
return 3
560-
case n <= 6:
561-
return 6
562-
case n <= 9:
563-
return 9
564-
case n <= 12:
565-
return 12
566-
case n <= 15:
567-
return 15
568-
default:
569-
panic("too many arguments to system call")
570-
}
571-
}
572-
573543
// Syscall determines which SyscallX function to use for function f.
574544
func (f *Fn) Syscall() string {
575-
c := f.SyscallParamCount()
576-
if c == 3 {
577-
return syscalldot() + "Syscall"
578-
}
579-
return syscalldot() + "Syscall" + strconv.Itoa(c)
545+
return syscalldot() + "SyscallN"
580546
}
581547

582-
// SyscallParamList returns source code for SyscallX parameters for function f.
548+
// SyscallParamList returns source code for SyscallN parameters for function f,
549+
// including a leading "comma". If f has no parameters, it returns an empty
550+
// string.
583551
func (f *Fn) SyscallParamList() string {
584-
a := make([]string, 0)
552+
a := make([]string, 0, len(f.Params))
585553
for _, p := range f.Params {
586554
a = append(a, p.SyscallArgList()...)
587555
}
588-
for len(a) < f.SyscallParamCount() {
589-
a = append(a, "0")
556+
if len(a) == 0 {
557+
return ""
590558
}
591-
return strings.Join(a, ", ")
559+
return ", " + strings.Join(a, ", ")
592560
}
593561

594562
// HelperCallParamList returns source code of call into function f helper.
@@ -1045,7 +1013,7 @@ func {{.HelperName}}({{.HelperParamList}}) {{template "results" .}}{
10451013
10461014
{{define "results"}}{{if .Rets.List}}{{.Rets.List}} {{end}}{{end}}
10471015
1048-
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.Syscall}}(proc{{.DLLFuncName}}.Addr(), {{.ParamCount}}, {{.SyscallParamList}}){{end}}
1016+
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.Syscall}}(proc{{.DLLFuncName}}.Addr(){{.SyscallParamList}}){{end}}
10491017
10501018
{{define "tmpvarsreadback"}}{{range .Params}}{{if .TmpVarReadbackCode}}
10511019
{{.TmpVarReadbackCode}}{{end}}{{end}}{{end}}

vhd/zvhd_windows.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)