6
6
#include " stdafx.h" // Standard header.
7
7
8
8
#include < utilcode.h> // Utility helpers.
9
- #include < posterror.h> // Error handlers
10
- #define INIT_GUIDS
11
9
#include < corpriv.h>
12
- #include < winwrap.h>
13
- #include < mscoree.h>
14
- #include " shimload.h"
15
- #include " metadataexports.h"
16
- #include " ex.h"
17
-
18
- #include < dbgenginemetrics.h>
19
10
20
11
#if !defined(CORECLR_EMBEDDED)
21
12
@@ -45,18 +36,16 @@ BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
45
36
46
37
#endif // !defined(CORECLR_EMBEDDED)
47
38
48
- extern void * GetClrModuleBase ();
49
-
50
39
// ---------------------------------------------------------------------------
51
40
// %%Function: MetaDataGetDispenser
52
41
// This function gets the Dispenser interface given the CLSID and REFIID.
42
+ // Exported from coreclr and used by external profilers.
53
43
// ---------------------------------------------------------------------------
54
- STDAPI DLLEXPORT MetaDataGetDispenser ( // Return HRESULT
44
+ STDAPI DLLEXPORT MetaDataGetDispenser ( // Return HRESULT
55
45
REFCLSID rclsid, // The class to desired.
56
46
REFIID riid, // Interface wanted on class factory.
57
47
LPVOID FAR *ppv) // Return interface pointer here.
58
48
{
59
-
60
49
CONTRACTL {
61
50
NOTHROW;
62
51
GC_NOTRIGGER;
@@ -69,208 +58,3 @@ STDAPI DLLEXPORT MetaDataGetDispenser( // Return HRESULT
69
58
70
59
return CreateMetaDataDispenser (riid, ppv);
71
60
}
72
-
73
- // ---------------------------------------------------------------------------
74
- // %%Function: GetMetaDataInternalInterface
75
- // This function gets the IMDInternalImport given the metadata on memory.
76
- // ---------------------------------------------------------------------------
77
- STDAPI DLLEXPORT GetMetaDataInternalInterface (
78
- LPVOID pData, // [IN] in memory metadata section
79
- ULONG cbData, // [IN] size of the metadata section
80
- DWORD flags, // [IN] MDInternal_OpenForRead or MDInternal_OpenForENC
81
- REFIID riid, // [IN] desired interface
82
- void **ppv) // [OUT] returned interface
83
- {
84
- CONTRACTL{
85
- NOTHROW;
86
- GC_NOTRIGGER;
87
- ENTRY_POINT;
88
- PRECONDITION (CheckPointer (pData));
89
- PRECONDITION (CheckPointer (ppv));
90
- } CONTRACTL_END;
91
-
92
- return GetMDInternalInterface (pData, cbData, flags, riid, ppv);
93
- }
94
-
95
- // ---------------------------------------------------------------------------
96
- // %%Function: GetMetaDataInternalInterfaceFromPublic
97
- // This function gets the internal scopeless interface given the public
98
- // scopeless interface.
99
- // ---------------------------------------------------------------------------
100
- STDAPI DLLEXPORT GetMetaDataInternalInterfaceFromPublic (
101
- IUnknown *pv, // [IN] Given interface.
102
- REFIID riid, // [IN] desired interface
103
- void **ppv) // [OUT] returned interface
104
- {
105
- CONTRACTL{
106
- NOTHROW;
107
- GC_NOTRIGGER;
108
- ENTRY_POINT;
109
- PRECONDITION (CheckPointer (pv));
110
- PRECONDITION (CheckPointer (ppv));
111
- } CONTRACTL_END;
112
-
113
- return GetMDInternalInterfaceFromPublic (pv, riid, ppv);
114
- }
115
-
116
- // ---------------------------------------------------------------------------
117
- // %%Function: GetMetaDataPublicInterfaceFromInternal
118
- // This function gets the public scopeless interface given the internal
119
- // scopeless interface.
120
- // ---------------------------------------------------------------------------
121
- STDAPI DLLEXPORT GetMetaDataPublicInterfaceFromInternal (
122
- void *pv, // [IN] Given interface.
123
- REFIID riid, // [IN] desired interface.
124
- void **ppv) // [OUT] returned interface
125
- {
126
- CONTRACTL{
127
- NOTHROW;
128
- GC_NOTRIGGER;
129
- PRECONDITION (CheckPointer (pv));
130
- PRECONDITION (CheckPointer (ppv));
131
- ENTRY_POINT;
132
- } CONTRACTL_END;
133
-
134
- return GetMDPublicInterfaceFromInternal (pv, riid, ppv);
135
- }
136
-
137
-
138
- // ---------------------------------------------------------------------------
139
- // %%Function: ReopenMetaDataWithMemory
140
- // This function gets the public scopeless interface given the internal
141
- // scopeless interface.
142
- // ---------------------------------------------------------------------------
143
- STDAPI ReOpenMetaDataWithMemory (
144
- void *pUnk, // [IN] Given scope. public interfaces
145
- LPCVOID pData, // [in] Location of scope data.
146
- ULONG cbData) // [in] Size of the data pointed to by pData.
147
- {
148
- CONTRACTL{
149
- NOTHROW;
150
- GC_NOTRIGGER;
151
- ENTRY_POINT;
152
- PRECONDITION (CheckPointer (pUnk));
153
- PRECONDITION (CheckPointer (pData));
154
- } CONTRACTL_END;
155
-
156
- return MDReOpenMetaDataWithMemory (pUnk, pData, cbData);
157
- }
158
-
159
- // ---------------------------------------------------------------------------
160
- // %%Function: ReopenMetaDataWithMemoryEx
161
- // This function gets the public scopeless interface given the internal
162
- // scopeless interface.
163
- // ---------------------------------------------------------------------------
164
- STDAPI ReOpenMetaDataWithMemoryEx (
165
- void *pUnk, // [IN] Given scope. public interfaces
166
- LPCVOID pData, // [in] Location of scope data.
167
- ULONG cbData, // [in] Size of the data pointed to by pData.
168
- DWORD dwReOpenFlags) // [in] ReOpen flags
169
- {
170
- CONTRACTL{
171
- NOTHROW;
172
- GC_NOTRIGGER;
173
- ENTRY_POINT;
174
- PRECONDITION (CheckPointer (pUnk));
175
- PRECONDITION (CheckPointer (pData));
176
- } CONTRACTL_END;
177
-
178
- return MDReOpenMetaDataWithMemoryEx (pUnk, pData, cbData, dwReOpenFlags);
179
- }
180
-
181
- static DWORD g_dwSystemDirectory = 0 ;
182
- static WCHAR * g_pSystemDirectory = NULL ;
183
-
184
- HRESULT GetInternalSystemDirectory (_Out_writes_to_opt_(*pdwLength,*pdwLength) LPWSTR buffer, __inout DWORD* pdwLength)
185
- {
186
- CONTRACTL {
187
- NOTHROW;
188
- GC_NOTRIGGER;
189
- PRECONDITION (CheckPointer (buffer, NULL_OK));
190
- PRECONDITION (CheckPointer (pdwLength));
191
- } CONTRACTL_END;
192
-
193
- if (g_dwSystemDirectory == 0 )
194
- SetInternalSystemDirectory ();
195
-
196
- //
197
- // g_dwSystemDirectory includes the NULL in its count!
198
- //
199
- if (*pdwLength < g_dwSystemDirectory)
200
- {
201
- *pdwLength = g_dwSystemDirectory;
202
- return HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER);
203
- }
204
-
205
- if (buffer != NULL )
206
- {
207
- //
208
- // wcsncpy_s will automatically append a null and g_dwSystemDirectory
209
- // includes the null in its count, so we have to subtract 1.
210
- //
211
- wcsncpy_s (buffer, *pdwLength, g_pSystemDirectory, g_dwSystemDirectory-1 );
212
- }
213
- *pdwLength = g_dwSystemDirectory;
214
- return S_OK;
215
- }
216
-
217
-
218
- LPCWSTR GetInternalSystemDirectory (_Out_ DWORD* pdwLength)
219
- {
220
- LIMITED_METHOD_CONTRACT;
221
-
222
- if (g_dwSystemDirectory == 0 )
223
- {
224
- SetInternalSystemDirectory ();
225
- }
226
-
227
- if (pdwLength != NULL )
228
- {
229
- * pdwLength = g_dwSystemDirectory;
230
- }
231
-
232
- return g_pSystemDirectory;
233
- }
234
-
235
-
236
- HRESULT SetInternalSystemDirectory ()
237
- {
238
- CONTRACTL {
239
- NOTHROW;
240
- GC_NOTRIGGER;
241
- } CONTRACTL_END;
242
-
243
- HRESULT hr = S_OK;
244
- if (g_dwSystemDirectory == 0 ) {
245
-
246
- DWORD len = 0 ;
247
- NewArrayHolder<WCHAR> pSystemDirectory;
248
- EX_TRY{
249
-
250
- // use local buffer for thread safety
251
- PathString wzSystemDirectory;
252
- hr = GetClrModuleDirectory (wzSystemDirectory);
253
-
254
- if (FAILED (hr)) {
255
- wzSystemDirectory.Set (W (' \0 ' ));
256
- }
257
-
258
- pSystemDirectory = wzSystemDirectory.GetCopyOfUnicodeString ();
259
- if (pSystemDirectory == NULL )
260
- {
261
- hr = HRESULT_FROM_WIN32 (ERROR_NOT_ENOUGH_MEMORY);
262
- }
263
- len = wzSystemDirectory.GetCount () + 1 ;
264
-
265
- }
266
- EX_CATCH_HRESULT (hr);
267
-
268
- // publish results idempotently with correct memory ordering
269
- g_pSystemDirectory = pSystemDirectory.Extract ();
270
-
271
- (void )InterlockedExchange ((LONG *)&g_dwSystemDirectory, len);
272
- }
273
-
274
- return hr;
275
- }
276
-
0 commit comments