Open Bug 1440267 Opened 6 years ago Updated 2 years ago

Always use the canonical IUnknown for an Interceptor's primary target

Categories

(Core :: IPC: MSCOM, enhancement)

All
Windows
enhancement

Tracking

()

People

(Reporter: Jamie, Unassigned)

Details

Interceptor::Create uses the pointer of the interface it is given as the key for the LiveSet. This LiveSet is used to ensure that retrieving the same object always gets the existing Interceptor (if there is one). However, this only works for interfaces which have the same IUnknown. In the case of multiple inheritance (and multiple IUnknowns), separate Interceptors get created, even though the interfaces belong to the same object.

This makes things tricky in the disconnection of remote clients for an accessible (bug 1434822). When an accessible shuts down, we need to get the Interceptor for that accessible. However, if the accessible was fetched via IAccessible2::hyperlink*, the IAccessibleHyperlink's IUnknown gets used (not the IAccessible's IUnknown), so we can't find its Interceptor. I'm hacking around this by just trying the IAccessibleHyperlink pointer as well for now, but this is not an ideal solution.

Because this is a violation of COM identity laws, it's possible there are also other consequences, though we haven't encountered any yet.

COM identifies objects using their canonical IUnknown; i.e. it does a QueryInterface to IUnknown and compares the pointers. So, we can fix this by ensuring Interceptor::Create queries to IUnknown and uses that pointer as the LiveSet key.

The problem is that at present, Interceptors are often created from the MTA, and we can't QI to IUnknown on a main thread object from the MTA. The simple solution would be to dispatch the QI to the main thread. However, this has performance implications, as we'd be doing this for a huge number of interface pointers.

Right now, the main body of the interface walking in MainThreadHandOff::OnCall happens in the MTA. I think we're going to need to (synchronously) dispatch most of this to the main thread so we can do these QIs without the overhead of queuing a lot of separate main thread calls.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.