2 * A stub manager is an object that controls interface stubs. It is
3 * identified by an OID (object identifier) and acts as the network
4 * identity of the object. There can be many stub managers in a
5 * process or apartment.
7 * Copyright 2002 Marcus Meissner
8 * Copyright 2004 Mike Hearn for CodeWeavers
9 * Copyright 2004 Robert Shearman (for CodeWeavers)
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
38 #include "wine/debug.h"
39 #include "wine/exception.h"
41 #include "compobj_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
46 /* generates an ipid in the following format (similar to native version):
47 * Data1 = apartment-local ipid counter
48 * Data2 = apartment creator thread ID
50 * Data4 = random value
52 static inline HRESULT
generate_ipid(struct stub_manager
*m
, IPID
*ipid
)
55 hr
= UuidCreate(ipid
);
58 ERR("couldn't create IPID for stub manager %p\n", m
);
63 ipid
->Data1
= InterlockedIncrement(&m
->apt
->ipidc
);
64 ipid
->Data2
= (USHORT
)m
->apt
->tid
;
65 ipid
->Data3
= (USHORT
)GetCurrentProcessId();
69 /* registers a new interface stub COM object with the stub manager and returns registration record */
70 struct ifstub
*stub_manager_new_ifstub(struct stub_manager
*m
, IRpcStubBuffer
*sb
, REFIID iid
, DWORD dest_context
,
71 void *dest_context_data
, MSHLFLAGS flags
)
76 TRACE("oid=%s, stubbuffer=%p, iid=%s\n", wine_dbgstr_longlong(m
->oid
), sb
, debugstr_guid(iid
));
78 stub
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct ifstub
));
79 if (!stub
) return NULL
;
81 hr
= IUnknown_QueryInterface(m
->object
, iid
, (void **)&stub
->iface
);
84 HeapFree(GetProcessHeap(), 0, stub
);
88 hr
= RPC_CreateServerChannel(dest_context
, dest_context_data
, &stub
->chan
);
91 IUnknown_Release(stub
->iface
);
92 HeapFree(GetProcessHeap(), 0, stub
);
96 stub
->stubbuffer
= sb
;
97 if (sb
) IRpcStubBuffer_AddRef(sb
);
102 /* FIXME: find a cleaner way of identifying that we are creating an ifstub
103 * for the remunknown interface */
104 if (flags
& MSHLFLAGSP_REMUNKNOWN
)
105 stub
->ipid
= m
->oxid_info
.ipidRemUnknown
;
107 generate_ipid(m
, &stub
->ipid
);
109 EnterCriticalSection(&m
->lock
);
110 list_add_head(&m
->ifstubs
, &stub
->entry
);
111 /* every normal marshal is counted so we don't allow more than we should */
112 if (flags
& MSHLFLAGS_NORMAL
) m
->norm_refs
++;
113 LeaveCriticalSection(&m
->lock
);
115 TRACE("ifstub %p created with ipid %s\n", stub
, debugstr_guid(&stub
->ipid
));
120 static void stub_manager_delete_ifstub(struct stub_manager
*m
, struct ifstub
*ifstub
)
122 TRACE("m=%p, m->oid=%s, ipid=%s\n", m
, wine_dbgstr_longlong(m
->oid
), debugstr_guid(&ifstub
->ipid
));
124 list_remove(&ifstub
->entry
);
126 if (!m
->disconnected
)
127 RPC_UnregisterInterface(&ifstub
->iid
, TRUE
);
129 if (ifstub
->stubbuffer
) IRpcStubBuffer_Release(ifstub
->stubbuffer
);
130 IUnknown_Release(ifstub
->iface
);
131 IRpcChannelBuffer_Release(ifstub
->chan
);
133 HeapFree(GetProcessHeap(), 0, ifstub
);
136 static struct ifstub
*stub_manager_ipid_to_ifstub(struct stub_manager
*m
, const IPID
*ipid
)
139 struct ifstub
*result
= NULL
;
141 EnterCriticalSection(&m
->lock
);
142 LIST_FOR_EACH( cursor
, &m
->ifstubs
)
144 struct ifstub
*ifstub
= LIST_ENTRY( cursor
, struct ifstub
, entry
);
146 if (IsEqualGUID(ipid
, &ifstub
->ipid
))
152 LeaveCriticalSection(&m
->lock
);
157 struct ifstub
*stub_manager_find_ifstub(struct stub_manager
*m
, REFIID iid
, MSHLFLAGS flags
)
159 struct ifstub
*result
= NULL
;
160 struct ifstub
*ifstub
;
162 EnterCriticalSection(&m
->lock
);
163 LIST_FOR_EACH_ENTRY( ifstub
, &m
->ifstubs
, struct ifstub
, entry
)
165 if (IsEqualIID(iid
, &ifstub
->iid
) && (ifstub
->flags
== flags
))
171 LeaveCriticalSection(&m
->lock
);
176 /* creates a new stub manager and adds it into the apartment. caller must
177 * release stub manager when it is no longer required. the apartment and
178 * external refs together take one implicit ref */
179 static struct stub_manager
*new_stub_manager(APARTMENT
*apt
, IUnknown
*object
)
181 struct stub_manager
*sm
;
186 sm
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct stub_manager
));
187 if (!sm
) return NULL
;
189 list_init(&sm
->ifstubs
);
191 InitializeCriticalSection(&sm
->lock
);
192 DEBUG_SET_CRITSEC_NAME(&sm
->lock
, "stub_manager");
194 IUnknown_AddRef(object
);
198 /* start off with 2 references because the stub is in the apartment
199 * and the caller will also hold a reference */
203 sm
->oxid_info
.dwPid
= GetCurrentProcessId();
204 sm
->oxid_info
.dwTid
= GetCurrentThreadId();
206 * FIXME: this is a hack for marshalling IRemUnknown. In real
207 * DCOM, the IPID of the IRemUnknown interface is generated like
208 * any other and passed to the OXID resolver which then returns it
209 * when queried. We don't have an OXID resolver yet so instead we
210 * use a magic IPID reserved for IRemUnknown.
212 sm
->oxid_info
.ipidRemUnknown
.Data1
= 0xffffffff;
213 sm
->oxid_info
.ipidRemUnknown
.Data2
= 0xffff;
214 sm
->oxid_info
.ipidRemUnknown
.Data3
= 0xffff;
215 assert(sizeof(sm
->oxid_info
.ipidRemUnknown
.Data4
) == sizeof(apt
->oxid
));
216 memcpy(sm
->oxid_info
.ipidRemUnknown
.Data4
, &apt
->oxid
, sizeof(OXID
));
217 sm
->oxid_info
.dwAuthnHint
= RPC_C_AUTHN_LEVEL_NONE
;
218 sm
->oxid_info
.psa
= NULL
/* FIXME */;
220 /* Yes, that's right, this starts at zero. that's zero EXTERNAL
221 * refs, i.e., nobody has unmarshalled anything yet. We can't have
222 * negative refs because the stub manager cannot be explicitly
223 * killed, it has to die by somebody unmarshalling then releasing
224 * the marshalled ifptr.
227 sm
->disconnected
= FALSE
;
229 hres
= IUnknown_QueryInterface(object
, &IID_IExternalConnection
, (void**)&sm
->extern_conn
);
231 sm
->extern_conn
= NULL
;
233 EnterCriticalSection(&apt
->cs
);
234 sm
->oid
= apt
->oidc
++;
235 list_add_head(&apt
->stubmgrs
, &sm
->entry
);
236 LeaveCriticalSection(&apt
->cs
);
238 TRACE("Created new stub manager (oid=%s) at %p for object with IUnknown %p\n", wine_dbgstr_longlong(sm
->oid
), sm
, object
);
243 void stub_manager_disconnect(struct stub_manager
*m
)
245 struct ifstub
*ifstub
;
247 EnterCriticalSection(&m
->lock
);
248 if (!m
->disconnected
)
250 LIST_FOR_EACH_ENTRY(ifstub
, &m
->ifstubs
, struct ifstub
, entry
)
251 RPC_UnregisterInterface(&ifstub
->iid
, FALSE
);
253 m
->disconnected
= TRUE
;
255 LeaveCriticalSection(&m
->lock
);
258 /* caller must remove stub manager from apartment prior to calling this function */
259 static void stub_manager_delete(struct stub_manager
*m
)
263 TRACE("destroying %p (oid=%s)\n", m
, wine_dbgstr_longlong(m
->oid
));
265 /* release every ifstub */
266 while ((cursor
= list_head(&m
->ifstubs
)))
268 struct ifstub
*ifstub
= LIST_ENTRY(cursor
, struct ifstub
, entry
);
269 stub_manager_delete_ifstub(m
, ifstub
);
273 IExternalConnection_Release(m
->extern_conn
);
275 CoTaskMemFree(m
->oxid_info
.psa
);
277 /* Some broken apps crash in object destructors. We have a test showing
278 * that on winxp+ those crashes are caught and ignored. */
281 IUnknown_Release(m
->object
);
285 ERR("Got page fault when releasing stub!\n");
289 DEBUG_CLEAR_CRITSEC_NAME(&m
->lock
);
290 DeleteCriticalSection(&m
->lock
);
292 HeapFree(GetProcessHeap(), 0, m
);
295 /* increments the internal refcount */
296 static ULONG
stub_manager_int_addref(struct stub_manager
*This
)
300 EnterCriticalSection(&This
->apt
->cs
);
302 LeaveCriticalSection(&This
->apt
->cs
);
304 TRACE("before %d\n", refs
- 1);
309 /* decrements the internal refcount */
310 ULONG
stub_manager_int_release(struct stub_manager
*This
)
313 APARTMENT
*apt
= This
->apt
;
315 EnterCriticalSection(&apt
->cs
);
318 TRACE("after %d\n", refs
);
320 /* remove from apartment so no other thread can access it... */
322 list_remove(&This
->entry
);
324 LeaveCriticalSection(&apt
->cs
);
326 /* ... so now we can delete it without being inside the apartment critsec */
328 stub_manager_delete(This
);
333 /* gets the stub manager associated with an object - caller must have
334 * a reference to the apartment while a reference to the stub manager is held.
335 * it must also call release on the stub manager when it is no longer needed */
336 struct stub_manager
*get_stub_manager_from_object(APARTMENT
*apt
, IUnknown
*obj
, BOOL alloc
)
338 struct stub_manager
*result
= NULL
;
343 hres
= IUnknown_QueryInterface(obj
, &IID_IUnknown
, (void**)&object
);
345 ERR("QueryInterface(IID_IUnknown failed): %08x\n", hres
);
349 EnterCriticalSection(&apt
->cs
);
350 LIST_FOR_EACH( cursor
, &apt
->stubmgrs
)
352 struct stub_manager
*m
= LIST_ENTRY( cursor
, struct stub_manager
, entry
);
354 if (m
->object
== object
)
357 stub_manager_int_addref(result
);
361 LeaveCriticalSection(&apt
->cs
);
364 TRACE("found %p for object %p\n", result
, object
);
366 TRACE("not found, creating new stub manager...\n");
367 result
= new_stub_manager(apt
, object
);
369 TRACE("not found for object %p\n", object
);
372 IUnknown_Release(object
);
376 /* gets the stub manager associated with an object id - caller must have
377 * a reference to the apartment while a reference to the stub manager is held.
378 * it must also call release on the stub manager when it is no longer needed */
379 struct stub_manager
*get_stub_manager(APARTMENT
*apt
, OID oid
)
381 struct stub_manager
*result
= NULL
;
384 EnterCriticalSection(&apt
->cs
);
385 LIST_FOR_EACH( cursor
, &apt
->stubmgrs
)
387 struct stub_manager
*m
= LIST_ENTRY( cursor
, struct stub_manager
, entry
);
392 stub_manager_int_addref(result
);
396 LeaveCriticalSection(&apt
->cs
);
399 TRACE("found %p for oid %s\n", result
, wine_dbgstr_longlong(oid
));
401 TRACE("not found for oid %s\n", wine_dbgstr_longlong(oid
));
406 /* add some external references (ie from a client that unmarshaled an ifptr) */
407 ULONG
stub_manager_ext_addref(struct stub_manager
*m
, ULONG refs
, BOOL tableweak
)
409 BOOL first_extern_ref
;
412 EnterCriticalSection(&m
->lock
);
414 first_extern_ref
= refs
&& !m
->extrefs
;
416 /* make sure we don't overflow extrefs */
417 refs
= min(refs
, (ULONG_MAX
-1 - m
->extrefs
));
418 rc
= (m
->extrefs
+= refs
);
423 LeaveCriticalSection(&m
->lock
);
425 TRACE("added %u refs to %p (oid %s), rc is now %u\n", refs
, m
, wine_dbgstr_longlong(m
->oid
), rc
);
428 * NOTE: According to tests, creating a stub causes two AddConnection calls followed by
429 * one ReleaseConnection call (with fLastReleaseCloses=FALSE).
431 if(first_extern_ref
&& m
->extern_conn
)
432 IExternalConnection_AddConnection(m
->extern_conn
, EXTCONN_STRONG
, 0);
437 /* remove some external references */
438 ULONG
stub_manager_ext_release(struct stub_manager
*m
, ULONG refs
, BOOL tableweak
, BOOL last_unlock_releases
)
440 BOOL last_extern_ref
;
443 EnterCriticalSection(&m
->lock
);
445 /* make sure we don't underflow extrefs */
446 refs
= min(refs
, m
->extrefs
);
447 rc
= (m
->extrefs
-= refs
);
451 if (!last_unlock_releases
)
454 last_extern_ref
= refs
&& !m
->extrefs
;
456 LeaveCriticalSection(&m
->lock
);
458 TRACE("removed %u refs from %p (oid %s), rc is now %u\n", refs
, m
, wine_dbgstr_longlong(m
->oid
), rc
);
460 if (last_extern_ref
&& m
->extern_conn
)
461 IExternalConnection_ReleaseConnection(m
->extern_conn
, EXTCONN_STRONG
, 0, last_unlock_releases
);
464 if (!(m
->extern_conn
&& last_unlock_releases
&& m
->weakrefs
))
465 stub_manager_int_release(m
);
470 /* gets the stub manager associated with an ipid - caller must have
471 * a reference to the apartment while a reference to the stub manager is held.
472 * it must also call release on the stub manager when it is no longer needed */
473 static struct stub_manager
*get_stub_manager_from_ipid(APARTMENT
*apt
, const IPID
*ipid
)
475 struct stub_manager
*result
= NULL
;
478 EnterCriticalSection(&apt
->cs
);
479 LIST_FOR_EACH( cursor
, &apt
->stubmgrs
)
481 struct stub_manager
*m
= LIST_ENTRY( cursor
, struct stub_manager
, entry
);
483 if (stub_manager_ipid_to_ifstub(m
, ipid
))
486 stub_manager_int_addref(result
);
490 LeaveCriticalSection(&apt
->cs
);
493 TRACE("found %p for ipid %s\n", result
, debugstr_guid(ipid
));
495 ERR("not found for ipid %s\n", debugstr_guid(ipid
));
500 static HRESULT
ipid_to_stub_manager(const IPID
*ipid
, APARTMENT
**stub_apt
, struct stub_manager
**stubmgr_ret
)
502 /* FIXME: hack for IRemUnknown */
503 if (ipid
->Data2
== 0xffff)
504 *stub_apt
= apartment_findfromoxid(*(const OXID
*)ipid
->Data4
, TRUE
);
506 *stub_apt
= apartment_findfromtid(ipid
->Data2
);
509 TRACE("Couldn't find apartment corresponding to TID 0x%04x\n", ipid
->Data2
);
510 return RPC_E_INVALID_OBJECT
;
512 *stubmgr_ret
= get_stub_manager_from_ipid(*stub_apt
, ipid
);
515 apartment_release(*stub_apt
);
517 return RPC_E_INVALID_OBJECT
;
522 /* gets the apartment, stub and channel of an object. the caller must
523 * release the references to all objects (except iface) if the function
524 * returned success, otherwise no references are returned. */
525 HRESULT
ipid_get_dispatch_params(const IPID
*ipid
, APARTMENT
**stub_apt
,
526 struct stub_manager
**manager
,
527 IRpcStubBuffer
**stub
, IRpcChannelBuffer
**chan
,
528 IID
*iid
, IUnknown
**iface
)
530 struct stub_manager
*stubmgr
;
531 struct ifstub
*ifstub
;
535 hr
= ipid_to_stub_manager(ipid
, &apt
, &stubmgr
);
536 if (hr
!= S_OK
) return RPC_E_DISCONNECTED
;
538 ifstub
= stub_manager_ipid_to_ifstub(stubmgr
, ipid
);
541 *stub
= ifstub
->stubbuffer
;
542 IRpcStubBuffer_AddRef(*stub
);
543 *chan
= ifstub
->chan
;
544 IRpcChannelBuffer_AddRef(*chan
);
547 *iface
= ifstub
->iface
;
552 stub_manager_int_release(stubmgr
);
557 stub_manager_int_release(stubmgr
);
558 apartment_release(apt
);
559 return RPC_E_DISCONNECTED
;
563 /* returns TRUE if it is possible to unmarshal, FALSE otherwise. */
564 BOOL
stub_manager_notify_unmarshal(struct stub_manager
*m
, const IPID
*ipid
)
567 struct ifstub
*ifstub
;
569 if (!(ifstub
= stub_manager_ipid_to_ifstub(m
, ipid
)))
571 ERR("attempted unmarshal of unknown IPID %s\n", debugstr_guid(ipid
));
575 EnterCriticalSection(&m
->lock
);
577 /* track normal marshals so we can enforce rules whilst in-process */
578 if (ifstub
->flags
& MSHLFLAGS_NORMAL
)
584 ERR("attempted invalid normal unmarshal, norm_refs is zero\n");
589 LeaveCriticalSection(&m
->lock
);
594 /* handles refcounting for CoReleaseMarshalData */
595 void stub_manager_release_marshal_data(struct stub_manager
*m
, ULONG refs
, const IPID
*ipid
, BOOL tableweak
)
597 struct ifstub
*ifstub
;
599 if (!(ifstub
= stub_manager_ipid_to_ifstub(m
, ipid
)))
602 if (ifstub
->flags
& MSHLFLAGS_TABLEWEAK
)
604 else if (ifstub
->flags
& MSHLFLAGS_TABLESTRONG
)
607 stub_manager_ext_release(m
, refs
, tableweak
, !tableweak
);
610 /* is an ifstub table marshaled? */
611 BOOL
stub_manager_is_table_marshaled(struct stub_manager
*m
, const IPID
*ipid
)
613 struct ifstub
*ifstub
= stub_manager_ipid_to_ifstub(m
, ipid
);
617 return ifstub
->flags
& (MSHLFLAGS_TABLESTRONG
| MSHLFLAGS_TABLEWEAK
);
621 /*****************************************************************************
623 * IRemUnknown implementation
626 * Note: this object is not related to the lifetime of a stub_manager, but it
627 * interacts with stub managers.
630 typedef struct rem_unknown
632 IRemUnknown IRemUnknown_iface
;
636 static const IRemUnknownVtbl RemUnknown_Vtbl
;
638 static inline RemUnknown
*impl_from_IRemUnknown(IRemUnknown
*iface
)
640 return CONTAINING_RECORD(iface
, RemUnknown
, IRemUnknown_iface
);
644 /* construct an IRemUnknown object with one outstanding reference */
645 static HRESULT
RemUnknown_Construct(IRemUnknown
**ppRemUnknown
)
647 RemUnknown
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
649 if (!This
) return E_OUTOFMEMORY
;
651 This
->IRemUnknown_iface
.lpVtbl
= &RemUnknown_Vtbl
;
654 *ppRemUnknown
= &This
->IRemUnknown_iface
;
658 static HRESULT WINAPI
RemUnknown_QueryInterface(IRemUnknown
*iface
, REFIID riid
, void **ppv
)
660 TRACE("(%p)->(%s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
662 if (IsEqualIID(riid
, &IID_IUnknown
) ||
663 IsEqualIID(riid
, &IID_IRemUnknown
))
666 IRemUnknown_AddRef(iface
);
670 if (!IsEqualIID(riid
, &IID_IExternalConnection
))
671 FIXME("No interface for iid %s\n", debugstr_guid(riid
));
674 return E_NOINTERFACE
;
677 static ULONG WINAPI
RemUnknown_AddRef(IRemUnknown
*iface
)
680 RemUnknown
*This
= impl_from_IRemUnknown(iface
);
682 refs
= InterlockedIncrement(&This
->refs
);
684 TRACE("%p before: %d\n", iface
, refs
-1);
688 static ULONG WINAPI
RemUnknown_Release(IRemUnknown
*iface
)
691 RemUnknown
*This
= impl_from_IRemUnknown(iface
);
693 refs
= InterlockedDecrement(&This
->refs
);
695 HeapFree(GetProcessHeap(), 0, This
);
697 TRACE("%p after: %d\n", iface
, refs
);
701 static HRESULT WINAPI
RemUnknown_RemQueryInterface(IRemUnknown
*iface
,
702 REFIPID ripid
, ULONG cRefs
, USHORT cIids
, IID
*iids
/* [size_is(cIids)] */,
703 REMQIRESULT
**ppQIResults
/* [size_is(,cIids)] */)
707 USHORT successful_qis
= 0;
709 struct stub_manager
*stubmgr
;
711 TRACE("(%p)->(%s, %d, %d, %p, %p)\n", iface
, debugstr_guid(ripid
), cRefs
, cIids
, iids
, ppQIResults
);
713 hr
= ipid_to_stub_manager(ripid
, &apt
, &stubmgr
);
714 if (hr
!= S_OK
) return hr
;
716 *ppQIResults
= CoTaskMemAlloc(sizeof(REMQIRESULT
) * cIids
);
718 for (i
= 0; i
< cIids
; i
++)
720 HRESULT hrobj
= marshal_object(apt
, &(*ppQIResults
)[i
].std
, &iids
[i
],
721 stubmgr
->object
, MSHCTX_DIFFERENTMACHINE
, NULL
, MSHLFLAGS_NORMAL
);
724 (*ppQIResults
)[i
].hResult
= hrobj
;
727 stub_manager_int_release(stubmgr
);
728 apartment_release(apt
);
730 if (successful_qis
== cIids
)
731 return S_OK
; /* we got all requested interfaces */
732 else if (successful_qis
== 0)
733 return E_NOINTERFACE
; /* we didn't get any interfaces */
735 return S_FALSE
; /* we got some interfaces */
738 static HRESULT WINAPI
RemUnknown_RemAddRef(IRemUnknown
*iface
,
739 USHORT cInterfaceRefs
,
740 REMINTERFACEREF
* InterfaceRefs
/* [size_is(cInterfaceRefs)] */,
741 HRESULT
*pResults
/* [size_is(cInterfaceRefs)] */)
746 TRACE("(%p)->(%d, %p, %p)\n", iface
, cInterfaceRefs
, InterfaceRefs
, pResults
);
748 for (i
= 0; i
< cInterfaceRefs
; i
++)
751 struct stub_manager
*stubmgr
;
753 pResults
[i
] = ipid_to_stub_manager(&InterfaceRefs
[i
].ipid
, &apt
, &stubmgr
);
754 if (pResults
[i
] != S_OK
)
760 stub_manager_ext_addref(stubmgr
, InterfaceRefs
[i
].cPublicRefs
, FALSE
);
761 if (InterfaceRefs
[i
].cPrivateRefs
)
762 FIXME("Adding %d refs securely not implemented\n", InterfaceRefs
[i
].cPrivateRefs
);
764 stub_manager_int_release(stubmgr
);
765 apartment_release(apt
);
771 static HRESULT WINAPI
RemUnknown_RemRelease(IRemUnknown
*iface
,
772 USHORT cInterfaceRefs
,
773 REMINTERFACEREF
* InterfaceRefs
/* [size_is(cInterfaceRefs)] */)
778 TRACE("(%p)->(%d, %p)\n", iface
, cInterfaceRefs
, InterfaceRefs
);
780 for (i
= 0; i
< cInterfaceRefs
; i
++)
783 struct stub_manager
*stubmgr
;
785 hr
= ipid_to_stub_manager(&InterfaceRefs
[i
].ipid
, &apt
, &stubmgr
);
789 /* FIXME: we should undo any changes already made in this function */
793 stub_manager_ext_release(stubmgr
, InterfaceRefs
[i
].cPublicRefs
, FALSE
, TRUE
);
794 if (InterfaceRefs
[i
].cPrivateRefs
)
795 FIXME("Releasing %d refs securely not implemented\n", InterfaceRefs
[i
].cPrivateRefs
);
797 stub_manager_int_release(stubmgr
);
798 apartment_release(apt
);
804 static const IRemUnknownVtbl RemUnknown_Vtbl
=
806 RemUnknown_QueryInterface
,
809 RemUnknown_RemQueryInterface
,
810 RemUnknown_RemAddRef
,
811 RemUnknown_RemRelease
814 /* starts the IRemUnknown listener for the current apartment */
815 HRESULT
start_apartment_remote_unknown(void)
817 IRemUnknown
*pRemUnknown
;
819 APARTMENT
*apt
= COM_CurrentApt();
821 EnterCriticalSection(&apt
->cs
);
822 if (!apt
->remunk_exported
)
824 /* create the IRemUnknown object */
825 hr
= RemUnknown_Construct(&pRemUnknown
);
828 STDOBJREF stdobjref
; /* dummy - not used */
829 /* register it with the stub manager */
830 hr
= marshal_object(apt
, &stdobjref
, &IID_IRemUnknown
, (IUnknown
*)pRemUnknown
, MSHCTX_DIFFERENTMACHINE
, NULL
, MSHLFLAGS_NORMAL
|MSHLFLAGSP_REMUNKNOWN
);
831 /* release our reference to the object as the stub manager will manage the life cycle for us */
832 IRemUnknown_Release(pRemUnknown
);
834 apt
->remunk_exported
= TRUE
;
837 LeaveCriticalSection(&apt
->cs
);