{"action":"closed","issue":{"url":"https://api.github.com/repos/golang/go/issues/17908","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/17908/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/17908/comments","events_url":"https://api.github.com/repos/golang/go/issues/17908/events","html_url":"https://github.com/golang/go/issues/17908","id":189030166,"number":17908,"title":"syscall: panic calling Windows system call in 1.7, worked in 1.6","user":{"login":"robert-chiniquy","id":623808,"avatar_url":"https://avatars.githubusercontent.com/u/623808?v=3","gravatar_id":"","url":"https://api.github.com/users/robert-chiniquy","html_url":"https://github.com/robert-chiniquy","followers_url":"https://api.github.com/users/robert-chiniquy/followers","following_url":"https://api.github.com/users/robert-chiniquy/following{/other_user}","gists_url":"https://api.github.com/users/robert-chiniquy/gists{/gist_id}","starred_url":"https://api.github.com/users/robert-chiniquy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robert-chiniquy/subscriptions","organizations_url":"https://api.github.com/users/robert-chiniquy/orgs","repos_url":"https://api.github.com/users/robert-chiniquy/repos","events_url":"https://api.github.com/users/robert-chiniquy/events{/privacy}","received_events_url":"https://api.github.com/users/robert-chiniquy/received_events","type":"User","site_admin":false},"labels":[{"id":373402289,"url":"https://api.github.com/repos/golang/go/labels/NeedsInvestigation","name":"NeedsInvestigation","color":"ededed","default":false},{"id":199753992,"url":"https://api.github.com/repos/golang/go/labels/OS-Windows","name":"OS-Windows","color":"ededed","default":false},{"id":357033853,"url":"https://api.github.com/repos/golang/go/labels/WaitingForInfo","name":"WaitingForInfo","color":"ededed","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/38","html_url":"https://github.com/golang/go/milestones/Go1.8","labels_url":"https://api.github.com/repos/golang/go/milestones/38/labels","id":1709363,"number":38,"title":"Go1.8","description":"","creator":{"login":"griesemer","id":8528975,"avatar_url":"https://avatars.githubusercontent.com/u/8528975?v=3","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false},"open_issues":30,"closed_issues":662,"state":"open","created_at":"2016-04-15T16:30:23Z","updated_at":"2016-12-01T20:23:01Z","due_on":"2017-01-31T00:00:00Z","closed_at":null},"comments":10,"created_at":"2016-11-14T05:11:42Z","updated_at":"2016-12-01T20:23:01Z","closed_at":"2016-12-01T20:23:01Z","body":"Calling syscalls on Windows can cause a panic. This does not occur in Go 1.6 with the same code. \r\n\r\nI believe this code follows the rules listed at: https://golang.org/pkg/unsafe/#Pointer, most specifically:\r\n\r\n> If a pointer argument must be converted to uintptr for use as an argument, that conversion must appear in the call expression itself\r\n\r\nIt appears to me that this code is triggering a garbage collector or compiler bug by defining `resume_handle` in the scope of the function `resumeHandlePtrCrashes` and passing it to the syscall called in `callingNetLocalGroupGetMembers`.\r\n\r\n### What version of Go are you using (`go version`)?\r\n\r\ngo version go1.7.3 windows/amd64\r\n\r\n### What operating system and processor architecture are you using (`go env`)?\r\n\r\n```\r\nset GOARCH=amd64\r\nset GOBIN=\r\nset GOEXE=.exe\r\nset GOHOSTARCH=amd64\r\nset GOHOSTOS=windows\r\nset GOOS=windows\r\nset GOPATH=Z:\\sudo.wtf\r\nset GORACE=\r\nset GOROOT=C:\\Go\r\nset GOTOOLDIR=C:\\Go\\pkg\\tool\\windows_amd64\r\nset CC=gcc\r\nset GOGCCFLAGS=-m64 -mthreads -fmessage-length=0\r\nset CXX=g++\r\nset CGO_ENABLED=1\r\n```\r\n\r\n### What did you do?\r\n\r\nA small test program:\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"golang.org/x/sys/windows\"\r\n\t\"syscall\"\r\n\t\"unsafe\"\r\n)\r\n\r\nvar modNetapi32 = windows.NewLazySystemDLL(\"Netapi32.dll\")\r\n\r\nvar procNetLocalGroupGetMembers = modNetapi32.NewProc(\"NetLocalGroupGetMembers\")\r\n\r\ntype NET_API_STATUS uint32\r\n\r\nconst MAX_PREFERRED_LENGTH int32 = -1\r\n\r\nfunc main() {\r\n\tresumeHandlePtrCrashes()\r\n}\r\n\r\nfunc resumeHandlePtrCrashes() {\r\n\tvar resume_handle uint32\r\n\tcallingNetLocalGroupGetMembers(\"Administrators\", &resume_handle)\r\n}\r\n\r\nfunc callingNetLocalGroupGetMembers(groupName string, resume_handle *uint32) {\r\n\tvar bufptr *byte\r\n\tvar entriesread uint32\r\n\tvar totalentries uint32\r\n\tadminGroupName, _ := windows.UTF16PtrFromString(\"Administrators\")\r\n\tex := NetLocalGroupGetMembers(nil, adminGroupName, 1, &bufptr, MAX_PREFERRED_LENGTH, &entriesread, &totalentries, resume_handle)\r\n\tfmt.Printf(\"NetLocalGroupGetMembers = %d\\n\", ex)\r\n}\r\n\r\nfunc NetLocalGroupGetMembers(servername *uint16,\r\n\tlocalgroupname *uint16,\r\n\tlevel uint32, bufptr **byte,\r\n\tprefmaxlen int32, entriesread *uint32, totalentries *uint32, resumehandle *uint32) (status NET_API_STATUS) {\r\n\tr0, _, _ := syscall.Syscall9(procNetLocalGroupGetMembers.Addr(), 8,\r\n\t\tuintptr(unsafe.Pointer(servername)),\r\n\t\tuintptr(unsafe.Pointer(localgroupname)),\r\n\t\tuintptr(level), uintptr(unsafe.Pointer(bufptr)),\r\n\t\tuintptr(prefmaxlen), uintptr(unsafe.Pointer(entriesread)),\r\n\t\tuintptr(unsafe.Pointer(totalentries)), uintptr(unsafe.Pointer(resumehandle)), 0)\r\n\tstatus = NET_API_STATUS(r0)\r\n\treturn\r\n}\r\n```\r\n\r\ngo run test.go\r\n\r\n### What did you expect to see?\r\n\r\nRunning under Go 1.6, this code would produce: `NetLocalGroupGetMembers = 0`\r\n\r\n### What did you see instead?\r\n\r\nAn error like this:\r\n\r\n```\r\nException 0xc0000005 0x0 0xffffffffffffffff 0x7ff8ae692573\r\nPC=0x7ff8ae692573\r\n\r\nsyscall.Syscall9(0x7ff8ae692050, 0x8, 0x0, 0xc0420086e0, 0x1, 0xc04202ded8, 0xffffffffffffffff, 0xc04202ded0, 0xc04202de\r\ncc, 0xc04202df1c, ...)\r\n        C:/Go/src/runtime/syscall_windows.go:185 +0x6b\r\nmain.NetLocalGroupGetMembers(0x0, 0xc0420086e0, 0xc000000001, 0xc04202ded8, 0xffffffff, 0xc04202ded0, 0xc04202decc, 0xc0\r\n4202df1c, 0x0)\r\n        Z:/Go/src/[...]/test.go:52 +0x125\r\nmain.callingNetLocalGroupGetMembers(0x4b9acf, 0xe, 0xc04202df1c)\r\n        Z:/Go/src/[...]/test.go:28 +0xac\r\nmain.resumeHandlePtrCrashes()\r\n        Z:/Go/src/[...]/test.go +0x4f\r\nmain.main()\r\n        Z:/Go/src/[...]/test.go:20 +0x1b\r\nrax     0x4202df8000000000\r\nrbx     0x4202df8000000000\r\nrcx     0x0\r\nrdi     0xc04202ded0\r\nrsi     0x0\r\nrbp     0x7fd90\r\nrsp     0x7fc90\r\nr8      0x1\r\nr9      0xc04202ded8\r\nr10     0x0\r\nr11     0x4\r\nr12     0x0\r\nr13     0x1\r\nr14     0xc04202df1c\r\nr15     0xc04202ded8\r\nrip     0x7ff8ae692573\r\nrflags  0x10206\r\ncs      0x33\r\nfs      0x53\r\ngs      0x2b\r\nexit status 2\r\n```\r\n\r\n# Background\r\n\r\nThe above code is generated by [$GOROOT/src/syscall/mksyscall_windows.go](https://golang.org/src/syscall/mksyscall_windows.go), from this:\r\n\r\n```\r\n//sys NetLocalGroupGetMembers(servername *uint16, localgroupname *uint16, level uint32, bufptr **byte, prefmaxlen int32, entriesread *uint32, totalentries *uint32, resumehandle *uint32) (status NET_API_STATUS) = Netapi32.NetLocalGroupGetMembers\r\n/*\r\nNET_API_STATUS NetLocalGroupGetMembers(\r\n  _In_    LPCWSTR    servername,\r\n  _In_    LPCWSTR    localgroupname,\r\n  _In_    DWORD      level,\r\n  _Out_   LPBYTE     *bufptr,\r\n  _In_    DWORD      prefmaxlen,\r\n  _Out_   LPDWORD    entriesread,\r\n  _Out_   LPDWORD    totalentries,\r\n  _Inout_ PDWORD_PTR resumehandle\r\n);\r\n*/\r\n```"}}
{"actor":{"display_login":"robert-chiniquy"}}