ReactOS 0.4.16-dev-2320-ge1853c6
combase_private.h
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17#include "winternl.h"
18#include "wine/orpc.h"
19
20#include "wine/list.h"
21
22extern HINSTANCE hProxyDll;
23
25{
26 struct list entry;
27
28 LONG refs; /* refcount of the apartment (LOCK) */
29 BOOL multi_threaded; /* multi-threaded or single-threaded apartment? (RO) */
30 DWORD tid; /* thread id (RO) */
31 OXID oxid; /* object exporter ID (RO) */
32 LONG ipidc; /* interface pointer ID counter, starts at 1 (LOCK) */
33 CRITICAL_SECTION cs; /* thread safety */
34 struct list proxies; /* imported objects (CS cs) */
35 struct list stubmgrs; /* stub managers for exported objects (CS cs) */
36 BOOL remunk_exported; /* has the IRemUnknown interface for this apartment been created yet? (CS cs) */
37 LONG remoting_started; /* has the RPC system been started for this apartment? (LOCK) */
38 struct list loaded_dlls; /* list of dlls loaded by this apartment (CS cs) */
39 DWORD host_apt_tid; /* thread ID of apartment hosting objects of differing threading model (CS cs) */
40 HWND host_apt_hwnd; /* handle to apartment window of host apartment (CS cs) */
41 struct local_server *local_server; /* A marshallable object exposing local servers (CS cs) */
42 BOOL being_destroyed; /* is currently being destroyed */
43
44 /* FIXME: OIDs should be given out by RPCSS */
45 OID oidc; /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
46
47 /* STA-only fields */
48 HWND win; /* message window (LOCK) */
49 IMessageFilter *filter; /* message filter (CS cs) */
50 BOOL main; /* is this a main-threaded-apartment? (RO) */
51
52 /* MTA-only */
53 struct list usage_cookies; /* Used for refcount control with CoIncrementMTAUsage()/CoDecrementMTAUsage(). */
54};
55
58
59/* DCOM messages used by the apartment window (not compatible with native) */
60#define DM_EXECUTERPC (WM_USER + 0) /* WPARAM = 0, LPARAM = (struct dispatch_params *) */
61#define DM_HOSTOBJECT (WM_USER + 1) /* WPARAM = 0, LPARAM = (struct host_object_params *) */
62
63#define CHARS_IN_GUID 39
64
66{
71};
72
73/* this is what is stored in TEB->ReservedForOle */
74struct tlsdata
75{
76 struct apartment *apt;
78 DWORD thread_seqid; /* returned with CoGetCurrentProcess */
79 DWORD flags; /* tlsdata_flags (+0Ch on x86) */
80 void *unknown0;
81 DWORD inits; /* number of times CoInitializeEx called */
82 DWORD ole_inits; /* number of times OleInitialize called */
83 GUID causality_id; /* unique identifier for each COM call */
84 LONG pending_call_count_client; /* number of client calls pending */
85 LONG pending_call_count_server; /* number of server calls pending */
87 IObjContext *context_token; /* (+38h on x86) */
88 IUnknown *call_state; /* current call context (+3Ch on x86) */
90 IUnknown *cancel_object; /* cancel object set by CoSetCancelObject (+F8h on x86) */
91 IUnknown *state; /* see CoSetState */
92 struct list spies; /* Spies installed with CoRegisterInitializeSpy */
95 CO_MTA_USAGE_COOKIE implicit_mta_cookie; /* mta referenced by roapi from sta thread */
96};
97
100
101static inline HRESULT com_get_tlsdata(struct tlsdata **data)
102{
103 *data = NtCurrentTeb()->ReservedForOle;
104 return *data ? S_OK : InternalTlsAllocData(data);
105}
106
107static inline struct apartment* com_get_current_apt(void)
108{
109 struct tlsdata *tlsdata = NULL;
111 return tlsdata->apt;
112}
113
116void apartment_freeunusedlibraries(struct apartment *apt, DWORD unload_delay);
117void apartment_global_cleanup(void);
118OXID apartment_getoxid(const struct apartment *apt);
120
121/* RpcSs interface */
126HRESULT rpc_create_clientchannel(const OXID *oxid, const IPID *ipid, const OXID_INFO *oxid_info, const IID *iid,
127 DWORD dest_context, void *dest_context_data, IRpcChannelBuffer **chan, struct apartment *apt);
128HRESULT rpc_create_serverchannel(DWORD dest_context, void *dest_context_data, IRpcChannelBuffer **chan);
131HRESULT rpc_resolve_oxid(OXID oxid, OXID_INFO *oxid_info);
132void rpc_start_remoting(struct apartment *apt);
135
136struct dispatch_params;
138
139enum class_reg_data_origin
140{
143};
144
146{
147 enum class_reg_data_origin origin;
148 union
149 {
150 struct
151 {
157 } u;
158};
159
161void leave_apartment(struct tlsdata *data);
162void apartment_release(struct apartment *apt);
164HRESULT apartment_increment_mta_usage(CO_MTA_USAGE_COOKIE *cookie);
165void apartment_decrement_mta_usage(CO_MTA_USAGE_COOKIE cookie);
166HRESULT ensure_mta(void);
167struct apartment * apartment_get_mta(void);
168HRESULT apartment_get_inproc_class_object(struct apartment *apt, const struct class_reg_data *regdata,
169 REFCLSID rclsid, REFIID riid, DWORD class_context, void **ppv);
173void apartment_revoke_all_classes(const struct apartment *apt);
176
177HRESULT marshal_object(struct apartment *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *object,
178 DWORD dest_context, void *dest_context_data, MSHLFLAGS mshlflags);
179
180/* Stub Manager */
181
182/* signal to stub manager that this is a rem unknown object */
183#define MSHLFLAGSP_REMUNKNOWN 0x80000000
184
185/* Thread-safety Annotation Legend:
186 *
187 * RO - The value is read only. It never changes after creation, so no
188 * locking is required.
189 * LOCK - The value is written to only using Interlocked* functions.
190 * CS - The value is read or written to inside a critical section.
191 * The identifier following "CS" is the specific critical section that
192 * must be used.
193 * MUTEX - The value is read or written to with a mutex held.
194 * The identifier following "MUTEX" is the specific mutex that
195 * must be used.
196 */
197
198typedef enum ifstub_state
199{
206
207/* an interface stub */
208struct ifstub
209{
210 struct list entry; /* entry in stub_manager->ifstubs list (CS stub_manager->lock) */
212 IID iid; /* RO */
213 IPID ipid; /* RO */
214 IUnknown *iface; /* RO */
215 MSHLFLAGS flags; /* so we can enforce process-local marshalling rules (RO) */
216 IRpcChannelBuffer*chan; /* channel passed to IRpcStubBuffer::Invoke (RO) */
217};
218
219/* stub managers hold refs on the object and each interface stub */
221{
222 struct list entry; /* entry in apartment stubmgr list (CS apt->cs) */
223 struct list ifstubs; /* list of active ifstubs for the object (CS lock) */
225 struct apartment *apt; /* owning apt (RO) */
226
227 ULONG extrefs; /* number of 'external' references (CS lock) */
228 ULONG refs; /* internal reference count (CS apt->cs) */
229 ULONG weakrefs; /* number of weak references (CS lock) */
230 OID oid; /* apartment-scoped unique identifier (RO) */
231 IUnknown *object; /* the object we are managing the stub for (RO) */
232 ULONG next_ipid; /* currently unused (LOCK) */
233 OXID_INFO oxid_info; /* string binding, ipid of rem unknown and other information (RO) */
234
236
237 /* We need to keep a count of the outstanding marshals, so we can enforce the
238 * marshalling rules (ie, you can only unmarshal normal marshals once). Note
239 * that these counts do NOT include unmarshalled interfaces, once a stream is
240 * unmarshalled and a proxy set up, this count is decremented.
241 */
242
243 ULONG norm_refs; /* refcount of normal marshals (CS lock) */
244 BOOL disconnected; /* CoDisconnectObject has been called (CS lock) */
245};
246
251ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs, BOOL tableweak, BOOL last_unlock_releases);
253void stub_manager_release_marshal_data(struct stub_manager *m, ULONG refs, const IPID *ipid, BOOL tableweak);
256struct ifstub * stub_manager_find_ifstub(struct stub_manager *m, REFIID iid, MSHLFLAGS flags);
258 void *dest_context_data, MSHLFLAGS flags);
259HRESULT ipid_get_dispatch_params(const IPID *ipid, struct apartment **stub_apt,
261 IID *iid, IUnknown **iface);
262HRESULT ipid_get_dest_context(const IPID *ipid, MSHCTX *dest_context, void **dest_context_data);
@ hook
Definition: SystemMenu.c:35
Definition: list.h:37
struct ifstub * stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, REFIID iid, DWORD dest_context, void *dest_context_data, MSHLFLAGS flags)
Definition: stubmanager.c:71
HRESULT WINAPI InternalTlsAllocData(struct tlsdata **data)
Definition: combase.c:405
void rpc_execute_call(struct dispatch_params *params)
Definition: rpc.c:1874
HRESULT ipid_get_dispatch_params(const IPID *ipid, struct apartment **stub_apt, struct stub_manager **manager, IRpcStubBuffer **stub, IRpcChannelBuffer **chan, IID *iid, IUnknown **iface)
Definition: stubmanager.c:530
HRESULT apartment_createwindowifneeded(struct apartment *apt)
Definition: apartment.c:1250
@ CLASS_REG_REGISTRY
@ CLASS_REG_ACTCTX
HRESULT rpc_revoke_local_server(unsigned int cookie)
Definition: rpc.c:375
ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs, BOOL tableweak, BOOL last_unlock_releases)
Definition: stubmanager.c:437
HRESULT apartment_get_inproc_class_object(struct apartment *apt, const struct class_reg_data *regdata, REFCLSID rclsid, REFIID riid, DWORD class_context, void **ppv)
Definition: apartment.c:1031
void apartment_global_cleanup(void)
Definition: apartment.c:1289
struct apartment * apartment_get_mta(void)
Definition: apartment.c:607
HRESULT enter_apartment(struct tlsdata *data, DWORD model)
Definition: apartment.c:1129
HRESULT open_appidkey_from_clsid(REFCLSID clsid, REGSAM access, HKEY *subkey)
Definition: combase.c:353
void rpc_unregister_interface(REFIID riid, BOOL wait)
Definition: rpc.c:2143
struct stub_manager * get_stub_manager_from_object(struct apartment *apt, IUnknown *object, BOOL alloc)
Definition: stubmanager.c:335
IUnknown * com_get_registered_class_object(const struct apartment *apartment, REFCLSID rclsid, DWORD clscontext)
Definition: combase.c:144
HRESULT apartment_disconnectproxies(struct apartment *apt)
Definition: marshal.c:1992
HRESULT rpc_register_local_server(REFCLSID clsid, IStream *stream, DWORD flags, unsigned int *cookie)
Definition: rpc.c:701
HRESULT apartment_increment_mta_usage(CO_MTA_USAGE_COOKIE *cookie)
Definition: apartment.c:1175
HRESULT rpc_create_clientchannel(const OXID *oxid, const IPID *ipid, const OXID_INFO *oxid_info, const IID *iid, DWORD dest_context, void *dest_context_data, IRpcChannelBuffer **chan, struct apartment *apt)
Definition: rpc.c:1642
tlsdata_flags
@ OLETLS_DISABLE_OLE1DDE
@ OLETLS_APARTMENTTHREADED
@ OLETLS_MULTITHREADED
@ OLETLS_UUIDINITIALIZED
HRESULT apartment_get_local_server_stream(struct apartment *apt, IStream **ret)
Definition: apartment.c:315
void apartment_revoke_all_classes(const struct apartment *apt)
Definition: combase.c:3089
ULONG stub_manager_int_release(struct stub_manager *stub_manager)
Definition: stubmanager.c:309
void rpc_start_remoting(struct apartment *apt)
Definition: rpc.c:2186
BOOL stub_manager_is_table_marshaled(struct stub_manager *m, const IPID *ipid)
Definition: stubmanager.c:630
ifstub_state
@ STUBSTATE_NORMAL_MARSHALED
@ STUBSTATE_TABLE_WEAK_MARSHALED
@ STUBSTATE_NORMAL_UNMARSHALED
@ STUBSTATE_TABLE_STRONG
@ STUBSTATE_TABLE_WEAK_UNMARSHALED
void leave_apartment(struct tlsdata *data)
Definition: apartment.c:1153
HINSTANCE hProxyDll
Definition: combase.c:40
void apartment_release(struct apartment *apt)
Definition: apartment.c:444
HRESULT ensure_mta(void)
Definition: apartment.c:1297
struct stub_manager * get_stub_manager(struct apartment *apt, OID oid)
Definition: stubmanager.c:381
void apartment_decrement_mta_usage(CO_MTA_USAGE_COOKIE cookie)
Definition: apartment.c:1199
HRESULT ipid_get_dest_context(const IPID *ipid, MSHCTX *dest_context, void **dest_context_data)
Definition: stubmanager.c:557
void stub_manager_disconnect(struct stub_manager *m)
Definition: stubmanager.c:242
BOOL stub_manager_notify_unmarshal(struct stub_manager *m, const IPID *ipid)
Definition: stubmanager.c:583
void apartment_freeunusedlibraries(struct apartment *apt, DWORD unload_delay)
Definition: apartment.c:403
HRESULT marshal_object(struct apartment *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *object, DWORD dest_context, void *dest_context_data, MSHLFLAGS mshlflags)
Definition: marshal.c:870
HRESULT rpc_register_channel_hook(REFGUID rguid, IChannelHook *hook)
Definition: rpc.c:971
HWND apartment_getwindow(const struct apartment *apt)
Definition: apartment.c:1278
HRESULT rpcss_get_next_seqid(DWORD *id)
Definition: rpc.c:308
OXID apartment_getoxid(const struct apartment *apt)
Definition: apartment.c:1284
struct apartment * apartment_findfromtid(DWORD tid)
Definition: apartment.c:657
struct apartment * apartment_findfromoxid(OXID oxid)
Definition: apartment.c:635
HRESULT rpc_create_serverchannel(DWORD dest_context, void *dest_context_data, IRpcChannelBuffer **chan)
Definition: rpc.c:1709
struct apartment * apartment_get_current_or_mta(void)
Definition: apartment.c:623
HRESULT open_key_for_clsid(REFCLSID clsid, const WCHAR *keyname, REGSAM access, HKEY *subkey)
Definition: combase.c:320
struct ifstub * stub_manager_find_ifstub(struct stub_manager *m, REFIID iid, MSHLFLAGS flags)
Definition: stubmanager.c:156
static struct apartment * com_get_current_apt(void)
HRESULT rpc_resolve_oxid(OXID oxid, OXID_INFO *oxid_info)
Definition: rpc.c:2165
BOOL WINAPI InternalIsProcessInitialized(void)
Definition: combase.c:391
HRESULT rpc_get_local_class_object(REFCLSID rclsid, REFIID riid, void **obj)
Definition: rpc.c:629
HRESULT rpc_register_interface(REFIID riid)
Definition: rpc.c:2086
void rpc_unregister_channel_hooks(void)
Definition: rpc.c:990
void stub_manager_release_marshal_data(struct stub_manager *m, ULONG refs, const IPID *ipid, BOOL tableweak)
Definition: stubmanager.c:614
HRESULT start_apartment_remote_unknown(struct apartment *apt)
Definition: stubmanager.c:838
enum ifstub_state STUB_STATE
static HRESULT com_get_tlsdata(struct tlsdata **data)
ULONG stub_manager_ext_addref(struct stub_manager *m, ULONG refs, BOOL tableweak)
Definition: stubmanager.c:406
#define NULL
Definition: types.h:112
return ret
Definition: mutex.c:146
superblock * sb
Definition: btrfs.c:4261
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum const GLfloat * params
Definition: glext.h:5645
GLbitfield flags
Definition: glext.h:7161
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
const GLfloat * m
Definition: glext.h:10848
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
static TfClientId tid
#define S_OK
Definition: intsafe.h:52
voidpf uLong int origin
Definition: ioapi.h:144
#define NtCurrentTeb
static IUnknown DWORD clscontext
Definition: compobj.c:82
UINT64 OID
Definition: marshal.c:87
UINT64 OXID
Definition: marshal.c:86
const CLSID * clsid
Definition: msctf.cpp:50
long LONG
Definition: pedump.c:60
#define REFIID
Definition: guiddef.h:118
#define REFCLSID
Definition: guiddef.h:117
#define alloc
Definition: rosglue.h:13
Definition: scsiwmi.h:51
Definition: stubgen.c:11
struct list proxies
struct list entry
struct list loaded_dlls
LONG remoting_started
BOOL being_destroyed
CRITICAL_SECTION cs
struct local_server * local_server
struct list usage_cookies
DWORD host_apt_tid
BOOL remunk_exported
struct list stubmgrs
HWND host_apt_hwnd
IMessageFilter * filter
BOOL multi_threaded
const WCHAR * module_name
union class_reg_data::@323 u
struct class_reg_data::@323::@324 actctx
Definition: cookie.c:34
struct list entry
IUnknown * iface
IRpcStubBuffer * stubbuffer
MSHLFLAGS flags
IRpcChannelBuffer * chan
Definition: parse.h:23
CRITICAL_SECTION lock
OXID_INFO oxid_info
IExternalConnection * extern_conn
struct apartment * apt
IUnknown * object
struct list ifstubs
struct list entry
DWORD inits
DWORD flags
IUnknown * call_state
void * unknown0
LONG pending_call_count_client
IUnknown * cancel_object
DWORD thread_seqid
DWORD unknown2[46]
CO_MTA_USAGE_COOKIE implicit_mta_cookie
DWORD unknown
DWORD ole_inits
IUnknown * state
IObjContext * context_token
struct apartment * apt
LONG pending_call_count_server
DWORD spies_lock
struct list spies
IErrorInfo * errorinfo
DWORD cancelcount
GUID causality_id
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
ACCESS_MASK REGSAM
Definition: winreg.h:76
__wchar_t WCHAR
Definition: xmlstorage.h:180