Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall: mksyscall_windows.go "Too many return values..." #23798

Closed
jeffreydwalter opened this issue Feb 12, 2018 · 1 comment
Closed

syscall: mksyscall_windows.go "Too many return values..." #23798

jeffreydwalter opened this issue Feb 12, 2018 · 1 comment

Comments

@jeffreydwalter
Copy link

@jeffreydwalter jeffreydwalter commented Feb 12, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.2 freebsd/amd64

Does this issue reproduce with the latest release?

yes.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOOS="freebsd"
GOPATH="/home/jeff_walter/src/agent"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/freebsd_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build944315930=/tmp/go-build -gno-record-gcc-switches"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I ran go generate to generate syscall wrappers for some windows functions I need.

Here's my windows.go file:

package windows

//go:generate go run mksyscall_windows.go -output zwindows.go windows.go

import (
    errorspkg "errors"
    "sync"
    "syscall"
    "unicode/utf16"
    "unsafe"
)

type Handle uintptr

//sys   WTSQuerySessionInformation(hServer Handle, sessionId uint32, WTSInfoClass WTS_INFO_CLASS) (buffer *uintptr, bytesReturned *uint32, err error) [failretval==0] = wtsapi32.WTSQuerySessionInformationW

What did you expect to see?

I expected to have a zwindows.go with my window syscall wrappers.

func WTSQuerySessionInformation(hServer syscall.Handle, sessionId uint32, WTSInfoClass WTS_INFO_CLASS) (buffer uintptr, bytesReturned uint32, err error) {
    r1, _, e1 := syscall.Syscall6(procWTSQuerySessionInformationW.Addr(), 5, uintptr(hServer), uintptr(sessionId), uintptr(WTSInfoClass), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(bytesReturned)), 0)
    if r1 == 0 { 
        if e1 != 0 {
            err = errnoErr(e1)
        } else { 
            err = syscall.EINVAL
        } 
    }       
    return
}   

What did you see instead?

go generate
2018/02/12 12:03:12 Too many return values in "WTSQuerySessionInformation(hServer syscall.Handle, sessionId uint32, WTSInfoClass WTS_INFO_CLASS) (buffer uintptr, bytesReturned uint32, err error) [failretval==0] = wtsapi32.WTSQuerySessionInformationW"
exit status 1

If I change the comment to this:

//sys   WTSQuerySessionInformation(hServer Handle, sessionId uint32, WTSInfoClass WTS_INFO_CLASS, buffer *uintptr, bytesReturned *uint32) (err error) [failretval==0] = wtsapi32.WTSQuerySessionInformationW

The code generation succeeds, but I get this signature:

func WTSQuerySessionInformation(hServer syscall.Handle, sessionId uint32, WTSInfoClass WTS_INFO_CLASS, buffer *uintptr, bytesReturned *uint32) (err error) {
    r1, _, e1 := syscall.Syscall6(procWTSQuerySessionInformationW.Addr(), 5, uintptr(hServer), uintptr(sessionId), uintptr(WTSInfoClass), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(bytesReturned)), 0)
    if r1 == 0 { 
        if e1 != 0 {
            err = errnoErr(e1)
        } else { 
            err = syscall.EINVAL
        } 
    }       
    return
}   

BUT, I don't really want that as my func signature...

@jeffreydwalter
Copy link
Author

@jeffreydwalter jeffreydwalter commented Feb 12, 2018

After looking at the output further, I understand why it is this way. It would be nice if there was a better mechanism for specifying the r0 return value, instead of mapping the go function signature directly to the windows function.

@mikioh mikioh changed the title mksyscall_windows.go "Too many return values..." syscall: mksyscall_windows.go "Too many return values..." Feb 21, 2018
@golang golang locked and limited conversation to collaborators Feb 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.