Skip to content

Commit

Permalink
x/sys/windows: use SyscallN in mkwinsyscall
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mauri870 committed Aug 12, 2023
1 parent 552c4e8 commit fffa8e2
Show file tree
Hide file tree
Showing 3 changed files with 459 additions and 485 deletions.
36 changes: 5 additions & 31 deletions windows/mkwinsyscall/mkwinsyscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ import (
"go/parser"
"go/token"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"runtime"
"sort"
"strconv"
"strings"
"text/template"
)
Expand Down Expand Up @@ -553,42 +551,18 @@ func (f *Fn) ParamCount() int {
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
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"
}
return syscalldot() + "Syscall" + strconv.Itoa(c)
return syscalldot() + "SyscallN"
}

// SyscallParamList returns source code for SyscallX parameters for function f.
// SyscallParamList returns source code for SyscallN parameters for function f.
func (f *Fn) SyscallParamList() string {
a := make([]string, 0)
for _, p := range f.Params {
a = append(a, p.SyscallArgList()...)
}
for len(a) < f.SyscallParamCount() {
for len(a) == 0 {
a = append(a, "0")
}
return strings.Join(a, ", ")
Expand Down Expand Up @@ -923,7 +897,7 @@ func main() {
if *filename == "" {
_, err = os.Stdout.Write(data)
} else {
err = ioutil.WriteFile(*filename, data, 0644)
err = os.WriteFile(*filename, data, 0644)
}
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -1011,7 +985,7 @@ func {{.HelperName}}({{.HelperParamList}}) {{template "results" .}}{
{{define "results"}}{{if .Rets.List}}{{.Rets.List}} {{end}}{{end}}
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.Syscall}}(proc{{.DLLFuncName}}.Addr(), {{.ParamCount}}, {{.SyscallParamList}}){{end}}
{{define "syscall"}}{{.Rets.SetReturnValuesCode}}{{.Syscall}}(proc{{.DLLFuncName}}.Addr(), {{.SyscallParamList}}){{end}}
{{define "tmpvarsreadback"}}{{range .Params}}{{if .TmpVarReadbackCode}}
{{.TmpVarReadbackCode}}{{end}}{{end}}{{end}}
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 fffa8e2

Please sign in to comment.