diff options
Diffstat (limited to 'src/syscall/mksyscall_windows.go')
-rw-r--r-- | src/syscall/mksyscall_windows.go | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/syscall/mksyscall_windows.go b/src/syscall/mksyscall_windows.go index 622272ad50..546cb0d432 100644 --- a/src/syscall/mksyscall_windows.go +++ b/src/syscall/mksyscall_windows.go @@ -57,6 +57,7 @@ import ( "io/ioutil" "log" "os" + "sort" "strconv" "strings" "text/template" @@ -65,6 +66,8 @@ import ( 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", false, "whether all DLLs should be loaded from the Windows system directory") + sysRepo = flag.Bool("xsys", false, "whether this code is for the x/sys subrepo") ) func trim(s string) string { @@ -593,8 +596,14 @@ func (f *Fn) HelperName() string { // Source files and functions. type Source struct { - Funcs []*Fn - Files []string + Funcs []*Fn + Files []string + Imports []string +} + +func (src *Source) Import(pkg string) { + src.Imports = append(src.Imports, pkg) + sort.Strings(src.Imports) } // ParseFiles parses files listed in fs and extracts all syscall @@ -604,6 +613,12 @@ func ParseFiles(fs []string) (*Source, error) { src := &Source{ Funcs: make([]*Fn, 0), Files: make([]string, 0), + Imports: []string{ + "unsafe", + }, + } + if *systemDLL { + src.Import("internal/syscall/windows/sysdll") } for _, file := range fs { if err := src.ParseFile(file); err != nil { @@ -676,9 +691,30 @@ func (src *Source) ParseFile(path string) error { // Generate output source file from a source set src. func (src *Source) Generate(w io.Writer) error { + if *sysRepo && packageName != "windows" { + src.Import("golang.org/x/sys/windows") + } + if packageName != "syscall" { + src.Import("syscall") + } funcMap := template.FuncMap{ "packagename": packagename, "syscalldot": syscalldot, + "newlazydll": func(dll string) string { + arg := "\"" + dll + ".dll\"" + if *systemDLL { + arg = "sysdll.Add(" + arg + ")" + } + if *sysRepo { + if packageName == "windows" { + return "&LazyDLL{Name: " + arg + ", Flags: LoadLibrarySearchSystem32}" + } else { + return "&windows.LazyDLL{Name: " + arg + ", Flags: windows.LoadLibrarySearchSystem32}" + } + } else { + return syscalldot() + "NewLazyDLL(" + arg + ")" + } + }, } t := template.Must(template.New("main").Funcs(funcMap).Parse(srcTemplate)) err := t.Execute(w, src) @@ -733,8 +769,10 @@ const srcTemplate = ` package {{packagename}} -import "unsafe"{{if syscalldot}} -import "syscall"{{end}} +import ( +{{range .Imports}}"{{.}}" +{{end}} +) var _ unsafe.Pointer @@ -746,7 +784,7 @@ var ( {{/* help functions */}} -{{define "dlls"}}{{range .DLLs}} mod{{.}} = {{syscalldot}}NewLazyDLL("{{.}}.dll") +{{define "dlls"}}{{range .DLLs}} mod{{.}} = {{newlazydll .}} {{end}}{{end}} {{define "funcnames"}}{{range .Funcs}} proc{{.DLLFuncName}} = mod{{.DLLName}}.NewProc("{{.DLLFuncName}}") |