Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/combase/combase_private.h
4393 views
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
22
extern HINSTANCE hProxyDll;
23
24
struct apartment
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
56
HRESULT open_key_for_clsid(REFCLSID clsid, const WCHAR *keyname, REGSAM access, HKEY *subkey);
57
HRESULT open_appidkey_from_clsid(REFCLSID clsid, REGSAM access, HKEY *subkey);
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
65
enum tlsdata_flags
66
{
67
OLETLS_UUIDINITIALIZED = 0x2,
68
OLETLS_DISABLE_OLE1DDE = 0x40,
69
OLETLS_APARTMENTTHREADED = 0x80,
70
OLETLS_MULTITHREADED = 0x100,
71
};
72
73
/* this is what is stored in TEB->ReservedForOle */
74
struct tlsdata
75
{
76
struct apartment *apt;
77
IErrorInfo *errorinfo;
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 */
86
DWORD unknown;
87
IObjContext *context_token; /* (+38h on x86) */
88
IUnknown *call_state; /* current call context (+3Ch on x86) */
89
DWORD unknown2[46];
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 */
93
DWORD spies_lock;
94
DWORD cancelcount;
95
CO_MTA_USAGE_COOKIE implicit_mta_cookie; /* mta referenced by roapi from sta thread */
96
};
97
98
extern HRESULT WINAPI InternalTlsAllocData(struct tlsdata **data);
99
extern BOOL WINAPI InternalIsProcessInitialized(void);
100
101
static inline HRESULT com_get_tlsdata(struct tlsdata **data)
102
{
103
*data = NtCurrentTeb()->ReservedForOle;
104
return *data ? S_OK : InternalTlsAllocData(data);
105
}
106
107
static inline struct apartment* com_get_current_apt(void)
108
{
109
struct tlsdata *tlsdata = NULL;
110
com_get_tlsdata(&tlsdata);
111
return tlsdata->apt;
112
}
113
114
HWND apartment_getwindow(const struct apartment *apt);
115
HRESULT apartment_createwindowifneeded(struct apartment *apt);
116
void apartment_freeunusedlibraries(struct apartment *apt, DWORD unload_delay);
117
void apartment_global_cleanup(void);
118
OXID apartment_getoxid(const struct apartment *apt);
119
HRESULT apartment_disconnectproxies(struct apartment *apt);
120
121
/* RpcSs interface */
122
HRESULT rpcss_get_next_seqid(DWORD *id);
123
HRESULT rpc_get_local_class_object(REFCLSID rclsid, REFIID riid, void **obj);
124
HRESULT rpc_register_local_server(REFCLSID clsid, IStream *stream, DWORD flags, unsigned int *cookie);
125
HRESULT rpc_revoke_local_server(unsigned int cookie);
126
HRESULT 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);
128
HRESULT rpc_create_serverchannel(DWORD dest_context, void *dest_context_data, IRpcChannelBuffer **chan);
129
HRESULT rpc_register_interface(REFIID riid);
130
void rpc_unregister_interface(REFIID riid, BOOL wait);
131
HRESULT rpc_resolve_oxid(OXID oxid, OXID_INFO *oxid_info);
132
void rpc_start_remoting(struct apartment *apt);
133
HRESULT rpc_register_channel_hook(REFGUID rguid, IChannelHook *hook);
134
void rpc_unregister_channel_hooks(void);
135
136
struct dispatch_params;
137
void rpc_execute_call(struct dispatch_params *params);
138
139
enum class_reg_data_origin
140
{
141
CLASS_REG_ACTCTX,
142
CLASS_REG_REGISTRY,
143
};
144
145
struct class_reg_data
146
{
147
enum class_reg_data_origin origin;
148
union
149
{
150
struct
151
{
152
const WCHAR *module_name;
153
DWORD threading_model;
154
HANDLE hactctx;
155
} actctx;
156
HKEY hkey;
157
} u;
158
};
159
160
HRESULT enter_apartment(struct tlsdata *data, DWORD model);
161
void leave_apartment(struct tlsdata *data);
162
void apartment_release(struct apartment *apt);
163
struct apartment * apartment_get_current_or_mta(void);
164
HRESULT apartment_increment_mta_usage(CO_MTA_USAGE_COOKIE *cookie);
165
void apartment_decrement_mta_usage(CO_MTA_USAGE_COOKIE cookie);
166
HRESULT ensure_mta(void);
167
struct apartment * apartment_get_mta(void);
168
HRESULT apartment_get_inproc_class_object(struct apartment *apt, const struct class_reg_data *regdata,
169
REFCLSID rclsid, REFIID riid, DWORD class_context, void **ppv);
170
HRESULT apartment_get_local_server_stream(struct apartment *apt, IStream **ret);
171
IUnknown *com_get_registered_class_object(const struct apartment *apartment, REFCLSID rclsid,
172
DWORD clscontext);
173
void apartment_revoke_all_classes(const struct apartment *apt);
174
struct apartment * apartment_findfromoxid(OXID oxid);
175
struct apartment * apartment_findfromtid(DWORD tid);
176
177
HRESULT 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
198
typedef enum ifstub_state
199
{
200
STUBSTATE_NORMAL_MARSHALED,
201
STUBSTATE_NORMAL_UNMARSHALED,
202
STUBSTATE_TABLE_WEAK_MARSHALED,
203
STUBSTATE_TABLE_WEAK_UNMARSHALED,
204
STUBSTATE_TABLE_STRONG,
205
} STUB_STATE;
206
207
/* an interface stub */
208
struct ifstub
209
{
210
struct list entry; /* entry in stub_manager->ifstubs list (CS stub_manager->lock) */
211
IRpcStubBuffer *stubbuffer; /* RO */
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 */
220
struct stub_manager
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) */
224
CRITICAL_SECTION 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
235
IExternalConnection *extern_conn;
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
247
ULONG stub_manager_int_release(struct stub_manager *stub_manager);
248
struct stub_manager * get_stub_manager_from_object(struct apartment *apt, IUnknown *object, BOOL alloc);
249
void stub_manager_disconnect(struct stub_manager *m);
250
ULONG stub_manager_ext_addref(struct stub_manager *m, ULONG refs, BOOL tableweak);
251
ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs, BOOL tableweak, BOOL last_unlock_releases);
252
struct stub_manager * get_stub_manager(struct apartment *apt, OID oid);
253
void stub_manager_release_marshal_data(struct stub_manager *m, ULONG refs, const IPID *ipid, BOOL tableweak);
254
BOOL stub_manager_is_table_marshaled(struct stub_manager *m, const IPID *ipid);
255
BOOL stub_manager_notify_unmarshal(struct stub_manager *m, const IPID *ipid);
256
struct ifstub * stub_manager_find_ifstub(struct stub_manager *m, REFIID iid, MSHLFLAGS flags);
257
struct ifstub * stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, REFIID iid, DWORD dest_context,
258
void *dest_context_data, MSHLFLAGS flags);
259
HRESULT ipid_get_dispatch_params(const IPID *ipid, struct apartment **stub_apt,
260
struct stub_manager **manager, IRpcStubBuffer **stub, IRpcChannelBuffer **chan,
261
IID *iid, IUnknown **iface);
262
HRESULT ipid_get_dest_context(const IPID *ipid, MSHCTX *dest_context, void **dest_context_data);
263
HRESULT start_apartment_remote_unknown(struct apartment *apt);
264
265