Skip to content

Commit fffa8e2

Browse files
committed
x/sys/windows: use SyscallN in mkwinsyscall
The mkwinsyscall command has a hard limit of 15 on the number of syscall arguments. Windows has several system calls with more than 15 arguments, for example CreateFontPackage has 18 arguments. Another limiting factor is that mkwinsyscall uses the various SyscallX functions, that generates extra complexity that can be avoided by relying on SyscallN. Updates golang/go#57914
1 parent 552c4e8 commit fffa8e2

File tree

3 files changed

+459
-485
lines changed

3 files changed

+459
-485
lines changed

windows/mkwinsyscall/mkwinsyscall.go

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ import (
5757
"go/parser"
5858
"go/token"
5959
"io"
60-
"io/ioutil"
6160
"log"
6261
"os"
6362
"path/filepath"
6463
"runtime"
6564
"sort"
66-
"strconv"
6765
"strings"
6866
"text/template"
6967
)
@@ -553,42 +551,18 @@ func (f *Fn) ParamCount() int {
553551
return n
554552
}
555553

556-
// SyscallParamCount determines which version of Syscall/Syscall6/Syscall9/...
557-
// to use. It returns parameter count for correspondent SyscallX function.
558-
func (f *Fn) SyscallParamCount() int {
559-
n := f.ParamCount()
560-
switch {
561-
case n <= 3:
562-
return 3
563-
case n <= 6:
564-
return 6
565-
case n <= 9:
566-
return 9
567-
case n <= 12:
568-
return 12
569-
case n <= 15:
570-
return 15
571-
default:
572-
panic("too many arguments to system call")
573-
}
574-
}
575-
576554
// Syscall determines which SyscallX function to use for function f.
577555
func (f *Fn) Syscall() string {
578-
c := f.SyscallParamCount()
579-
if c == 3 {
580-
return syscalldot() + "Syscall"
581-
}
582-
return syscalldot() + "Syscall" + strconv.Itoa(c)
556+
return syscalldot() + "SyscallN"
583557
}
584558

585-
// SyscallParamList returns source code for SyscallX parameters for function f.
559+
// SyscallParamList returns source code for SyscallN parameters for function f.
586560
func (f *Fn) SyscallParamList() string {
587561
a := make([]string, 0)
588562
for _, p := range f.Params {
589563
a = append(a, p.SyscallArgList()...)
590564
}
591-
for len(a) < f.SyscallParamCount() {
565+
for len(a) == 0 {
592566
a = append(a, "0")
593567
}
594568
return strings.Join(a, ", ")
@@ -923,7 +897,7 @@ func main() {
923897
if *filename == "" {
924898
_, err = os.Stdout.Write(data)
925899
} else {
926-
err = ioutil.WriteFile(*filename, data, 0644)
900+
err = os.WriteFile(*filename, data, 0644)
927901
}
928902
if err != nil {
929903
log.Fatal(err)
@@ -1011,7 +985,7 @@ func {{.HelperName}}({{.HelperParamList}}) {{template "results" .}}{
1011985
1012986
{{define "results"}}{{if .Rets.List}}{{.Rets.List}} {{end}}{{end}}
1013987
1014-
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.Syscall}}(proc{{.DLLFuncName}}.Addr(), {{.ParamCount}}, {{.SyscallParamList}}){{end}}
988+
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.Syscall}}(proc{{.DLLFuncName}}.Addr(), {{.SyscallParamList}}){{end}}
1015989
1016990
{{define "tmpvarsreadback"}}{{range .Params}}{{if .TmpVarReadbackCode}}
1017991
{{.TmpVarReadbackCode}}{{end}}{{end}}{{end}}

windows/registry/zsyscall_windows.go

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

0 commit comments

Comments
 (0)