Skip to content

Commit

Permalink
Make local mksyscall_windows.go forks less forked
Browse files Browse the repository at this point in the history
At this point points of difference between the three local
mksyscall_windows.go implementations and
golang.org/x/sys/windows/mkwinsyscall v0.0.0-20210104204734-6f8348627aad
are:
- pkg/etw: Deduplicates imported functions due to multiple calling APIs
- pkg/security and vhd: Forced UTF-16 mode, not checking A/W suffix. I
  also removed cosmetic differences between these two implementations.

`go generate` reports no changes with these updates.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
  • Loading branch information
TBBle committed Feb 11, 2021
1 parent 1390d1a commit bc48b61
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
35 changes: 4 additions & 31 deletions pkg/security/mksyscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Hard-coding unicode mode for VHD library.

// +build ignore

/*
Expand Down Expand Up @@ -72,7 +74,6 @@ var (
filename = flag.String("output", "", "output file name (standard output if omitted)")
printTraceFlag = flag.Bool("trace", false, "generate print statement after every syscall")
systemDLL = flag.Bool("systemdll", true, "whether all DLLs should be loaded from the Windows system directory")
winio = flag.Bool("winio", false, "import go-winio")
)

func trim(s string) string {
Expand Down Expand Up @@ -321,24 +322,14 @@ func (r *Rets) SetErrorCode() string {
const code = `if r0 != 0 {
%s = %sErrno(r0)
}`
const hrCode = `if int32(r0) < 0 {
if r0&0x1fff0000 == 0x00070000 {
r0 &= 0xffff
}
%s = %sErrno(r0)
}`
if r.Name == "" && !r.ReturnsError {
return ""
}
if r.Name == "" {
return r.useLongHandleErrorCode("r1")
}
if r.Type == "error" {
if r.Name == "hr" {
return fmt.Sprintf(hrCode, r.Name, syscalldot())
} else {
return fmt.Sprintf(code, r.Name, syscalldot())
}
return fmt.Sprintf(code, r.Name, syscalldot())
}
s := ""
switch {
Expand Down Expand Up @@ -639,18 +630,6 @@ func (f *Fn) HasStringParam() bool {
return false
}

var uniqDllFuncName = make(map[string]bool)

// IsNotDuplicate is true if f is not a duplicated function
func (f *Fn) IsNotDuplicate() bool {
funcName := f.DLLFuncName()
if uniqDllFuncName[funcName] == false {
uniqDllFuncName[funcName] = true
return true
}
return false
}

// HelperName returns name of function f helper.
func (f *Fn) HelperName() string {
if !f.HasStringParam() {
Expand Down Expand Up @@ -817,9 +796,6 @@ func (src *Source) Generate(w io.Writer) error {
src.ExternalImport("golang.org/x/sys/windows")
}
}
if *winio {
src.ExternalImport("github.com/Microsoft/go-winio")
}
if packageName != "syscall" {
src.Import("syscall")
}
Expand All @@ -831,9 +807,6 @@ func (src *Source) Generate(w io.Writer) error {
if !*systemDLL {
return syscalldot() + "NewLazyDLL(" + arg + ")"
}
if strings.HasPrefix(dll, "api_") || strings.HasPrefix(dll, "ext_") {
arg = strings.Replace(arg, "_", "-", -1)
}
switch pkgtype {
case pkgStd:
return syscalldot() + "NewLazyDLL(sysdll.Add(" + arg + "))"
Expand Down Expand Up @@ -944,7 +917,7 @@ var (
{{define "dlls"}}{{range .DLLs}} mod{{.}} = {{newlazydll .}}
{{end}}{{end}}
{{define "funcnames"}}{{range .Funcs}}{{if .IsNotDuplicate}} proc{{.DLLFuncName}} = mod{{.DLLName}}.NewProc("{{.DLLFuncName}}"){{end}}
{{define "funcnames"}}{{range .Funcs}} proc{{.DLLFuncName}} = mod{{.DLLName}}.NewProc("{{.DLLFuncName}}")
{{end}}{{end}}
{{define "helperbody"}}
Expand Down
2 changes: 1 addition & 1 deletion vhd/mksyscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (p *Fn) MaybeAbsent() string {

// IsUTF16 is true, if f is W (utf16) function. It is false
// for all A (ascii) functions.
func (f *Fn) IsUTF16() bool {
func (_ *Fn) IsUTF16() bool {
return true
}

Expand Down

0 comments on commit bc48b61

Please sign in to comment.