-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[strict provenance] Review Windows HANDLE Types #95490
Comments
To sum up, yes standard* Though we'd have to be careful changing the global type. Some functions allow smuggling random pointers (and anything else) through arguments labelled as * Note: I'm using "standard |
(Also whoops I did the Worst Typo and the original version of the initial comment said "absolutely just pointers" when I meant to write "absolutely just integers". 🤦♀️) |
Also it might be worth mentioning that there is a public |
That HANDLE is correctly a pointer alias at least. I think the main reason for a Handle type to be isize over a pointer is literally just Send/Sync. |
Hm. I thought the intent here was to avoid unnecessary ptr to int (and vice versa) conversions? A (Although I would reiterate that some APIs lie about their arguments and actually take a union of types) |
So if things are ever a pointer, use a pointer. Even if they're also sometimes an int, still use a pointer. (This was already said in another issue but by now there's a whole lot of issues so it's easy to miss). |
In that case it doesn't really matter what windows-rs or the standard library use for actual kernel The only thing to be wary of is proper function definitions. And for that the C type may be unreliable. |
Yeah it's just annoying that the two will need a cast to interop. |
Full disclosure: I'm not a Microsoft employee. I've just been working with Windows for a billion years and am a current Windows Development MVP. So I wouldn't necessarily take anything I wrote as gospel... but I did draw from experience and did review Windows OS manuals going back to 1.0.
I'm not aware of any cases where a returned handle is designed/intended to be used as a pointer by the developer. (Do fact check me.) It would seem @Gankra Love what you're trying to accomplish here! Good hunting! |
The issue, imho, is cases where a |
FWIW, it seems like on WINE these may be real pointers, even if they aren't under proper Windows. We've seen segfaults and the like from misuse of them under wine, for example in #101474. That probably means we should keep them as pointers everywhere. I don't know if windows-rs cares to support that, but in the stdlib we certainly do. |
More concretely, my experience with these APIs is that there are plenty of places where they are just pointers even on windows. For example LocalAlloc will return a genuine pointer (not an integer) if the flags include |
The windows-rs definition of |
Apologies if this is repetitive, I've made similar comments elsewhere.
That said, programming examples in the same SDK's Programmer's Guide, separate from the Reference, make use of this insider knowledge! Despite this, I still don't believe we should start down the slippery slope of labeling handles based on their backing implementations or usage trends, both of which could change over time. |
windows-rs has switched to using |
This issue is part of the Strict Provenance Experiment - #95228
Windows defines HANDLE to be void* and rust faithfully reproduces that. But now windows-rs is actually trying to insist it's an integer. Also there are other types like SOCKET that "are" HANDLEs for many purposes but are defined to be integers.
I filed an issue against windows-rs for this, detailing the many places that define typedefs for these types, which has some interesting discussion from Microsoft devs. I think the ultimate conclusion is that truly truly truly these are absolutely just integers and to the extent that the address of something might be embedded within, acting on that fact is being a smartass and basically just "abi crimes".
It's possible there is "nothing to do here" but at very least it's suboptimal for Rust and windows-sys to disagree on typedefs and if that's gonna happen we should at least Actively Decide To Do That instead of Accidentally Doing It.
I left a mildly-confused-at-the-time FIXME about this here:
rust/library/std/src/os/windows/io/socket.rs
Lines 132 to 136 in 3e75146
(Arguably the "real" issue is that we define RawHandle to be
void*
)The text was updated successfully, but these errors were encountered: