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

x/sys/windows: clarify safety of Proc.Call, LazyProc.Call #42680

Open
bradfitz opened this issue Nov 17, 2020 · 5 comments
Open

x/sys/windows: clarify safety of Proc.Call, LazyProc.Call #42680

bradfitz opened this issue Nov 17, 2020 · 5 comments
Assignees
Labels
Milestone

Comments

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 17, 2020

https://godoc.org/golang.org/x/sys/windows#LazyProc.Call and https://godoc.org/golang.org/x/sys/windows#Proc.Call are syscall.SysCall wrappers but take a bunch of uintptrs.

I assume that those wrappers are not covered by the uintptr(unsafe.Pointer) conversion exception number (4) from https://golang.org/pkg/unsafe/#Pointer, correct?

Could we document that either way in x/sys/windows?

I assume that many callers will require runtime.KeepAlive?

/cc @ianlancetaylor @mdempsky @alexbrainman @josharian @crawshaw

@gopherbot gopherbot added this to the Unreleased milestone Nov 17, 2020
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Nov 17, 2020

I think this is Q1 of #34684.

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Nov 17, 2020

Also, runtime.KeepAlive would only guarantee that the actual pointer is still live. It doesn't guarantee that uintptr conversion stays valid. Calling Proc.Call might require growing the stack, which could invalidate a pointer to stack memory.

@bradfitz
Copy link
Contributor Author

@bradfitz bradfitz commented Nov 18, 2020

Yeah, this could be closed as a dup of #34684 I suppose.

But I'm not exactly sure the status of that bug. It sure sounds like {Lazy,}Proc.Call just aren't safe to use today, at least for arguments involving pointers.

Should we clarify that in the docs for now while we wait for something to happen with #34684?

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Nov 18, 2020

Direct calls to {Lazy,}Proc.Call should be fine, at least since b3bd7ab (first included in Go 1.14).

Either way, I'm happy to have the docs clarified.

@bradfitz
Copy link
Contributor Author

@bradfitz bradfitz commented Nov 20, 2020

Ah! I had just missed the //go:uintptrescapes lines in that file. Okay, that makes me feel much better.

I'll send some docs, thanks!

@bradfitz bradfitz self-assigned this Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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