Skip to content

Commit

Permalink
Revert "windows/mkwinsyscall: use syscall.SyscallN instead of syscall…
Browse files Browse the repository at this point in the history
….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>
  • Loading branch information
qmuntal committed Nov 5, 2024
1 parent c29efe3 commit e0753d4
Show file tree
Hide file tree
Showing 4 changed files with 532 additions and 496 deletions.
54 changes: 45 additions & 9 deletions windows/mkwinsyscall/mkwinsyscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import (
"path/filepath"
"runtime"
"sort"
"strconv"
"strings"
"text/template"
)
Expand Down Expand Up @@ -542,9 +543,47 @@ func (f *Fn) ParamPrintList() string {
return join(f.Params, func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `)
}

// SyscallN returns a string representing the SyscallN function.
func (f *Fn) SyscallN() string {
return syscalldot() + "SyscallN"
// ParamCount return number of syscall parameters for function f.
func (f *Fn) ParamCount() int {
n := 0
for _, p := range f.Params {
n += len(p.SyscallArgList())
}
return n
}

// SyscallParamCount determines which version of Syscall/Syscall6/Syscall9/...
// to use. It returns parameter count for correspondent SyscallX function.
func (f *Fn) SyscallParamCount() int {
n := f.ParamCount()
switch {
case n <= 3:
return 3
case n <= 6:
return 6
case n <= 9:
return 9
case n <= 12:
return 12
case n <= 15:
return 15
case n <= 42: // current SyscallN limit
return n
default:
panic("too many arguments to system call")
}
}

// Syscall determines which SyscallX function to use for function f.
func (f *Fn) Syscall() string {
c := f.SyscallParamCount()
if c == 3 {
return syscalldot() + "Syscall"
}
if c > 15 {
return syscalldot() + "SyscallN"
}
return syscalldot() + "Syscall" + strconv.Itoa(c)
}

// SyscallParamList returns source code for SyscallX parameters for function f.
Expand All @@ -553,12 +592,9 @@ func (f *Fn) SyscallParamList() string {
for _, p := range f.Params {
a = append(a, p.SyscallArgList()...)
}

// Check if the number exceeds the current SyscallN limit
if len(a) > 42 {
panic("too many arguments to system call")
for len(a) < f.SyscallParamCount() {
a = append(a, "0")
}

return strings.Join(a, ", ")
}

Expand Down Expand Up @@ -979,7 +1015,7 @@ func {{.HelperName}}({{.HelperParamList}}) {{template "results" .}}{
{{define "results"}}{{if .Rets.List}}{{.Rets.List}} {{end}}{{end}}
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.SyscallN}}(proc{{.DLLFuncName}}.Addr(), {{.SyscallParamList}}){{end}}
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.Syscall}}(proc{{.DLLFuncName}}.Addr(),{{if le .ParamCount 15}} {{.ParamCount}},{{end}} {{.SyscallParamList}}){{end}}
{{define "tmpvarsreadback"}}{{range .Params}}{{if .TmpVarReadbackCode}}
{{.TmpVarReadbackCode}}{{end}}{{end}}{{end}}
Expand Down
8 changes: 4 additions & 4 deletions windows/mkwinsyscall/mkwinsyscall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ func TestDLLFilenameEscaping(t *testing.T) {
}
}

func TestSyscallNGeneration(t *testing.T) {
func TestSyscallXGeneration(t *testing.T) {
tests := []struct {
name string
wantsysfunc string
sig string
}{
{
name: "syscall with 2 params",
wantsysfunc: "syscall.SyscallN",
wantsysfunc: "syscall.Syscall",
sig: "Example(a1 *uint16, a2 *uint16) = ",
},
{
name: "syscall with 6 params",
wantsysfunc: "syscall.SyscallN",
wantsysfunc: "syscall.Syscall6",
sig: "Example(a1 *uint, a2 *uint, a3 *uint, a4 *uint, a5 *uint, a6 *uint) = ",
},
{
name: "syscall with 15 params",
wantsysfunc: "syscall.SyscallN",
wantsysfunc: "syscall.Syscall15",
sig: strings.ReplaceAll(`Example(a1 *uint, a2 *uint, a3 *uint, a4 *uint, a5 *uint, a6 *uint,
a7 *uint, a8 *uint, a9 *uint, a10 *uint, a11 *uint, a12 *uint,
a13 *uint, a14 *uint, a15 *uint) = `, "\n", ""),
Expand Down
16 changes: 8 additions & 8 deletions windows/registry/zsyscall_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e0753d4

Please sign in to comment.