Skip to content

Commit e0753d4

Browse files
committed
Revert "windows/mkwinsyscall: use syscall.SyscallN instead of syscall.Syscall{6,9,12,15}"
This reverts CL 614082. Reason for revert: syscall.SyscallN allocates more than its syscall.SyscallX counterparts, producing perf-related test failures across the board. Updates #70197 Change-Id: I51107d909fcdbef4e65ee3f84932b2a0e7804f1b Reviewed-on: https://go-review.googlesource.com/c/sys/+/625375 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
1 parent c29efe3 commit e0753d4

File tree

4 files changed

+532
-496
lines changed

4 files changed

+532
-496
lines changed

windows/mkwinsyscall/mkwinsyscall.go

+45-9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import (
6262
"path/filepath"
6363
"runtime"
6464
"sort"
65+
"strconv"
6566
"strings"
6667
"text/template"
6768
)
@@ -542,9 +543,47 @@ func (f *Fn) ParamPrintList() string {
542543
return join(f.Params, func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `)
543544
}
544545

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

550589
// SyscallParamList returns source code for SyscallX parameters for function f.
@@ -553,12 +592,9 @@ func (f *Fn) SyscallParamList() string {
553592
for _, p := range f.Params {
554593
a = append(a, p.SyscallArgList()...)
555594
}
556-
557-
// Check if the number exceeds the current SyscallN limit
558-
if len(a) > 42 {
559-
panic("too many arguments to system call")
595+
for len(a) < f.SyscallParamCount() {
596+
a = append(a, "0")
560597
}
561-
562598
return strings.Join(a, ", ")
563599
}
564600

@@ -979,7 +1015,7 @@ func {{.HelperName}}({{.HelperParamList}}) {{template "results" .}}{
9791015
9801016
{{define "results"}}{{if .Rets.List}}{{.Rets.List}} {{end}}{{end}}
9811017
982-
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.SyscallN}}(proc{{.DLLFuncName}}.Addr(), {{.SyscallParamList}}){{end}}
1018+
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.Syscall}}(proc{{.DLLFuncName}}.Addr(),{{if le .ParamCount 15}} {{.ParamCount}},{{end}} {{.SyscallParamList}}){{end}}
9831019
9841020
{{define "tmpvarsreadback"}}{{range .Params}}{{if .TmpVarReadbackCode}}
9851021
{{.TmpVarReadbackCode}}{{end}}{{end}}{{end}}

windows/mkwinsyscall/mkwinsyscall_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,25 @@ func TestDLLFilenameEscaping(t *testing.T) {
5050
}
5151
}
5252

53-
func TestSyscallNGeneration(t *testing.T) {
53+
func TestSyscallXGeneration(t *testing.T) {
5454
tests := []struct {
5555
name string
5656
wantsysfunc string
5757
sig string
5858
}{
5959
{
6060
name: "syscall with 2 params",
61-
wantsysfunc: "syscall.SyscallN",
61+
wantsysfunc: "syscall.Syscall",
6262
sig: "Example(a1 *uint16, a2 *uint16) = ",
6363
},
6464
{
6565
name: "syscall with 6 params",
66-
wantsysfunc: "syscall.SyscallN",
66+
wantsysfunc: "syscall.Syscall6",
6767
sig: "Example(a1 *uint, a2 *uint, a3 *uint, a4 *uint, a5 *uint, a6 *uint) = ",
6868
},
6969
{
7070
name: "syscall with 15 params",
71-
wantsysfunc: "syscall.SyscallN",
71+
wantsysfunc: "syscall.Syscall15",
7272
sig: strings.ReplaceAll(`Example(a1 *uint, a2 *uint, a3 *uint, a4 *uint, a5 *uint, a6 *uint,
7373
a7 *uint, a8 *uint, a9 *uint, a10 *uint, a11 *uint, a12 *uint,
7474
a13 *uint, a14 *uint, a15 *uint) = `, "\n", ""),

windows/registry/zsyscall_windows.go

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)