You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: COM _Impl types are not mutable #2304
There are a lot of steps involved when calling the associated interfaces that require the interface to mutate to keep track of information supplied to them in earlier calls, like the CREDENTIAL_PROVIDER_USAGE_SCENARIO.
Until these interfaces have the option to remain mutable it seems nearly impossible to properly design and build an implementation for these interfaces in Rust.
Drawbacks
Obviously not all functions need to be mutable but I'd imagine anything with a Set prefix in the function should follow this standard.
Rationale and alternatives
I'm a relatively new Rust developer but I'm not aware of any alternatives without somehow undoing every single rust security and compiler feature there is to somehow mutate an otherwise immutable object.
Hello Kenny Kerr (@kennykerr), I assume because the label was changed from "enhancement" to "question" that I'm likely missing some key-info about implementations and how to go about them.
Is there some documentation regarding how to implement the COM Interfaces appropriately that I missed? Any help is appreciated. Thank you
Briefly, Rust aliasing rules surrounding &self and &mut self preclude the latter from ever being sound when combined with COM's reference counting model where there may be multiple outstanding references. Here's an example of how to handle this in Rust:
Basically, you can use something like RwLock to coordinate access to mutable state. Having spent a number of decades writing COM code in C++, I've actually come around to this model and find it far more intuitive as you cannot so easily write incorrect multi-threaded COM in Rust as you can in C++.
Ah ok. If that works then that's great. Thanks!
While I have your attention I'm not quite sure about how to expose those COM interfaces after they've been written. Are there any extra steps to expose them and register them with windows besides simply compiling the project as a DLL?
I noticed you had written this example that included a lot of overhead in-between code that included IDL definitions. Is that necessary for predefined Implementation types?
The scaffolding in the linked example is intended for WinRT components. What your component may need depends very much on the API you're implementing and is more a question for those more familiar with this particular authentication API. For that you're better off checking the docs or going over to https://stackoverflow.com/ as I'm not familiar.
Now I just need to figure out how exposing the object works in windows. I've done basic FFI before but I've never done DLLs or worked with windows like this and COM programming seems so odd.
Activity
imgurbot12 commentedon Jan 24, 2023
Hello Kenny Kerr (@kennykerr), I assume because the label was changed from "enhancement" to "question" that I'm likely missing some key-info about implementations and how to go about them.
Is there some documentation regarding how to implement the COM Interfaces appropriately that I missed? Any help is appreciated. Thank you
kennykerr commentedon Jan 24, 2023
Yeah, sorry I plan to write about it here as it comes up quite often: https://kennykerr.ca/rust-getting-started/
That's the next topic on my list. 😊
Briefly, Rust aliasing rules surrounding
&selfand&mut selfpreclude the latter from ever being sound when combined with COM's reference counting model where there may be multiple outstanding references. Here's an example of how to handle this in Rust:https://github.com/microsoft/windows-rs/blob/master/crates/tests/implement/tests/vector.rs
Basically, you can use something like
RwLockto coordinate access to mutable state. Having spent a number of decades writing COM code in C++, I've actually come around to this model and find it far more intuitive as you cannot so easily write incorrect multi-threaded COM in Rust as you can in C++.imgurbot12 commentedon Jan 24, 2023
Ah ok. If that works then that's great. Thanks!
While I have your attention I'm not quite sure about how to expose those COM interfaces after they've been written. Are there any extra steps to expose them and register them with windows besides simply compiling the project as a DLL?
I noticed you had written this example that included a lot of overhead in-between code that included IDL definitions. Is that necessary for predefined Implementation types?
kennykerr commentedon Jan 24, 2023
The scaffolding in the linked example is intended for WinRT components. What your component may need depends very much on the API you're implementing and is more a question for those more familiar with this particular authentication API. For that you're better off checking the docs or going over to https://stackoverflow.com/ as I'm not familiar.
imgurbot12 commentedon Jan 24, 2023
Will do. Thanks for the info :)
riverar commentedon Jan 24, 2023
Perhaps a snippet that might help you as well.
imgurbot12 commentedon Jan 25, 2023
Rafael Rivera (@riverar) that helps thank you!
Now I just need to figure out how exposing the object works in windows. I've done basic FFI before but I've never done DLLs or worked with windows like this and COM programming seems so odd.
tim-weis commentedon Feb 2, 2023
Quick follow-up question here: Would it be sufficient to set the panic strategy to
"abort", so as to prevent potential panics from crossing the ABI?kennykerr commentedon Feb 2, 2023
I believe that's correct. Related: #1061