Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

591 lines
21 KiB

  1. /* Copyright (c) 2001-2003, Microsoft Corp. All rights reserved. */
  2. #if _MSC_VER > 1000
  3. #pragma once
  4. #endif
  5. #if defined(__cplusplus)
  6. extern "C" {
  7. #endif
  8. #if !defined(RC_INVOKED) /* RC complains about long symbols in #ifs */
  9. #if defined(ISOLATION_AWARE_ENABLED) && (ISOLATION_AWARE_ENABLED != 0)
  10. #if !defined(ISOLATION_AWARE_USE_STATIC_LIBRARY)
  11. #define ISOLATION_AWARE_USE_STATIC_LIBRARY 0
  12. #endif
  13. #if !defined(ISOLATION_AWARE_BUILD_STATIC_LIBRARY)
  14. #define ISOLATION_AWARE_BUILD_STATIC_LIBRARY 0
  15. #endif
  16. #if !defined(ISOLATION_AWARE_INLINE)
  17. #if ISOLATION_AWARE_BUILD_STATIC_LIBRARY
  18. #define ISOLATION_AWARE_INLINE /* nothing */
  19. #else
  20. #if defined(__cplusplus)
  21. #define ISOLATION_AWARE_INLINE inline
  22. #else
  23. #define ISOLATION_AWARE_INLINE __inline
  24. #endif
  25. #endif
  26. #endif
  27. #if !ISOLATION_AWARE_USE_STATIC_LIBRARY
  28. /* These wrappers prevent warnings about taking the addresses of __declspec(dllimport) functions. */
  29. ISOLATION_AWARE_INLINE HMODULE WINAPI IsolationAwarePrivatezlybNQyVOeNeln(LPCSTR s) { return LoadLibraryA(s); }
  30. ISOLATION_AWARE_INLINE HMODULE WINAPI IsolationAwarePrivatezlybNQyVOeNelJ(LPCWSTR s) { return LoadLibraryW(s); }
  31. ISOLATION_AWARE_INLINE HMODULE WINAPI IsolationAwarePrivatezltRgzbQhYRuNaQYRn(LPCSTR s) { return GetModuleHandleA(s); }
  32. ISOLATION_AWARE_INLINE HMODULE WINAPI IsolationAwarePrivatezltRgzbQhYRuNaQYRJ(LPCWSTR s) { return GetModuleHandleW(s); }
  33. /* temporary support for out of sync headers */
  34. #define IsolationAwarePrivateG_FqbjaLEiEL IsolationAwarePrivateT_SqbjaYRiRY
  35. #define IsolationAwarePrivatenCgIiAgEzlnCgpgk IsolationAwarePrivatenPgViNgRzlnPgpgk
  36. #define WinbaseIsolationAwarePrivateG_HnCgpgk WinbaseIsolationAwarePrivateT_UnPgpgk
  37. #define IsolationAwarePrivatezlybADyIBeAeln IsolationAwarePrivatezlybNQyVOeNeln
  38. #define IsolationAwarePrivatezlybADyIBeAelJ IsolationAwarePrivatezlybNQyVOeNelJ
  39. #define IsolationAwarePrivatezltEgCebCnDDeEff IsolationAwarePrivatezltRgCebPnQQeRff
  40. BOOL WINAPI IsolationAwarePrivatenPgViNgRzlnPgpgk(ULONG_PTR* pulpCookie);
  41. /*
  42. These are private.
  43. */
  44. __declspec(selectany) HANDLE WinbaseIsolationAwarePrivateT_UnPgpgk = INVALID_HANDLE_VALUE;
  45. __declspec(selectany) BOOL IsolationAwarePrivateT_SqbjaYRiRY = FALSE;
  46. __declspec(selectany) BOOL WinbaseIsolationAwarePrivateT_SpeRNgRQnPgpgk = FALSE;
  47. __declspec(selectany) BOOL WinbaseIsolationAwarePrivateT_SpYRNahcpNYYRQ = FALSE;
  48. FARPROC WINAPI WinbaseIsolationAwarePrivatetRgCebPnQQeRff_xReaRYQP_QYY(LPCSTR pszProcName);
  49. #endif /* ISOLATION_AWARE_USE_STATIC_LIBRARY */
  50. HMODULE WINAPI IsolationAwareLoadLibraryA(LPCSTR lpLibFileName);
  51. HMODULE WINAPI IsolationAwareLoadLibraryW(LPCWSTR lpLibFileName);
  52. HMODULE WINAPI IsolationAwareLoadLibraryExA(LPCSTR lpLibFileName,HANDLE hFile,DWORD dwFlags);
  53. HMODULE WINAPI IsolationAwareLoadLibraryExW(LPCWSTR lpLibFileName,HANDLE hFile,DWORD dwFlags);
  54. HANDLE WINAPI IsolationAwareCreateActCtxW(PCACTCTXW pActCtx);
  55. void WINAPI IsolationAwareReleaseActCtx(HANDLE hActCtx);
  56. BOOL WINAPI IsolationAwareActivateActCtx(HANDLE hActCtx,ULONG_PTR*lpCookie);
  57. BOOL WINAPI IsolationAwareDeactivateActCtx(DWORD dwFlags,ULONG_PTR ulCookie);
  58. BOOL WINAPI IsolationAwareFindActCtxSectionStringW(DWORD dwFlags,const GUID*lpExtensionGuid,ULONG ulSectionId,LPCWSTR lpStringToFind,PACTCTX_SECTION_KEYED_DATA ReturnedData);
  59. BOOL WINAPI IsolationAwareQueryActCtxW(DWORD dwFlags,HANDLE hActCtx,PVOID pvSubInstance,ULONG ulInfoClass,PVOID pvBuffer,SIZE_T cbBuffer,SIZE_T*pcbWrittenOrRequired);
  60. #if defined(UNICODE)
  61. #define IsolationAwareLoadLibrary IsolationAwareLoadLibraryW
  62. #define IsolationAwareLoadLibraryEx IsolationAwareLoadLibraryExW
  63. #else /* UNICODE */
  64. #define IsolationAwareLoadLibrary IsolationAwareLoadLibraryA
  65. #define IsolationAwareLoadLibraryEx IsolationAwareLoadLibraryExA
  66. #endif /* UNICODE */
  67. #if !ISOLATION_AWARE_USE_STATIC_LIBRARY
  68. ISOLATION_AWARE_INLINE HMODULE WINAPI IsolationAwareLoadLibraryA(LPCSTR lpLibFileName)
  69. {
  70. HMODULE moduleResult = NULL;
  71. ULONG_PTR ulpCookie = 0;
  72. const BOOL fActivateActCtxSuccess = IsolationAwarePrivateT_SqbjaYRiRY || IsolationAwarePrivatenPgViNgRzlnPgpgk(&ulpCookie);
  73. if (!fActivateActCtxSuccess)
  74. return moduleResult;
  75. __try
  76. {
  77. moduleResult = LoadLibraryA(lpLibFileName);
  78. }
  79. __finally
  80. {
  81. if (!IsolationAwarePrivateT_SqbjaYRiRY)
  82. {
  83. const BOOL fPreserveLastError = (moduleResult == NULL);
  84. const DWORD dwLastError = fPreserveLastError ? GetLastError() : NO_ERROR;
  85. (void)IsolationAwareDeactivateActCtx(0, ulpCookie);
  86. if (fPreserveLastError)
  87. SetLastError(dwLastError);
  88. }
  89. }
  90. return moduleResult;
  91. }
  92. ISOLATION_AWARE_INLINE HMODULE WINAPI IsolationAwareLoadLibraryW(LPCWSTR lpLibFileName)
  93. {
  94. HMODULE moduleResult = NULL;
  95. ULONG_PTR ulpCookie = 0;
  96. const BOOL fActivateActCtxSuccess = IsolationAwarePrivateT_SqbjaYRiRY || IsolationAwarePrivatenPgViNgRzlnPgpgk(&ulpCookie);
  97. if (!fActivateActCtxSuccess)
  98. return moduleResult;
  99. __try
  100. {
  101. moduleResult = LoadLibraryW(lpLibFileName);
  102. }
  103. __finally
  104. {
  105. if (!IsolationAwarePrivateT_SqbjaYRiRY)
  106. {
  107. const BOOL fPreserveLastError = (moduleResult == NULL);
  108. const DWORD dwLastError = fPreserveLastError ? GetLastError() : NO_ERROR;
  109. (void)IsolationAwareDeactivateActCtx(0, ulpCookie);
  110. if (fPreserveLastError)
  111. SetLastError(dwLastError);
  112. }
  113. }
  114. return moduleResult;
  115. }
  116. ISOLATION_AWARE_INLINE HMODULE WINAPI IsolationAwareLoadLibraryExA(LPCSTR lpLibFileName,HANDLE hFile,DWORD dwFlags)
  117. {
  118. HMODULE moduleResult = NULL;
  119. ULONG_PTR ulpCookie = 0;
  120. const BOOL fActivateActCtxSuccess = IsolationAwarePrivateT_SqbjaYRiRY || IsolationAwarePrivatenPgViNgRzlnPgpgk(&ulpCookie);
  121. if (!fActivateActCtxSuccess)
  122. return moduleResult;
  123. __try
  124. {
  125. moduleResult = LoadLibraryExA(lpLibFileName,hFile,dwFlags);
  126. }
  127. __finally
  128. {
  129. if (!IsolationAwarePrivateT_SqbjaYRiRY)
  130. {
  131. const BOOL fPreserveLastError = (moduleResult == NULL);
  132. const DWORD dwLastError = fPreserveLastError ? GetLastError() : NO_ERROR;
  133. (void)IsolationAwareDeactivateActCtx(0, ulpCookie);
  134. if (fPreserveLastError)
  135. SetLastError(dwLastError);
  136. }
  137. }
  138. return moduleResult;
  139. }
  140. ISOLATION_AWARE_INLINE HMODULE WINAPI IsolationAwareLoadLibraryExW(LPCWSTR lpLibFileName,HANDLE hFile,DWORD dwFlags)
  141. {
  142. HMODULE moduleResult = NULL;
  143. ULONG_PTR ulpCookie = 0;
  144. const BOOL fActivateActCtxSuccess = IsolationAwarePrivateT_SqbjaYRiRY || IsolationAwarePrivatenPgViNgRzlnPgpgk(&ulpCookie);
  145. if (!fActivateActCtxSuccess)
  146. return moduleResult;
  147. __try
  148. {
  149. moduleResult = LoadLibraryExW(lpLibFileName,hFile,dwFlags);
  150. }
  151. __finally
  152. {
  153. if (!IsolationAwarePrivateT_SqbjaYRiRY)
  154. {
  155. const BOOL fPreserveLastError = (moduleResult == NULL);
  156. const DWORD dwLastError = fPreserveLastError ? GetLastError() : NO_ERROR;
  157. (void)IsolationAwareDeactivateActCtx(0, ulpCookie);
  158. if (fPreserveLastError)
  159. SetLastError(dwLastError);
  160. }
  161. }
  162. return moduleResult;
  163. }
  164. ISOLATION_AWARE_INLINE HANDLE WINAPI IsolationAwareCreateActCtxW(PCACTCTXW pActCtx)
  165. {
  166. HANDLE result = INVALID_HANDLE_VALUE;
  167. typedef HANDLE (WINAPI* PFN)(PCACTCTXW pActCtx);
  168. static PFN s_pfn;
  169. if (s_pfn == NULL)
  170. {
  171. s_pfn = (PFN)WinbaseIsolationAwarePrivatetRgCebPnQQeRff_xReaRYQP_QYY("CreateActCtxW");
  172. if (s_pfn == NULL)
  173. return result;
  174. }
  175. result = s_pfn(pActCtx);
  176. return result;
  177. }
  178. ISOLATION_AWARE_INLINE void WINAPI IsolationAwareReleaseActCtx(HANDLE hActCtx)
  179. {
  180. typedef void (WINAPI* PFN)(HANDLE hActCtx);
  181. static PFN s_pfn;
  182. if (s_pfn == NULL)
  183. {
  184. s_pfn = (PFN)WinbaseIsolationAwarePrivatetRgCebPnQQeRff_xReaRYQP_QYY("ReleaseActCtx");
  185. if (s_pfn == NULL)
  186. return;
  187. }
  188. s_pfn(hActCtx);
  189. return;
  190. }
  191. ISOLATION_AWARE_INLINE BOOL WINAPI IsolationAwareActivateActCtx(HANDLE hActCtx,ULONG_PTR*lpCookie)
  192. {
  193. BOOL fResult = FALSE;
  194. typedef BOOL (WINAPI* PFN)(HANDLE hActCtx,ULONG_PTR*lpCookie);
  195. static PFN s_pfn;
  196. if (s_pfn == NULL)
  197. {
  198. s_pfn = (PFN)WinbaseIsolationAwarePrivatetRgCebPnQQeRff_xReaRYQP_QYY("ActivateActCtx");
  199. if (s_pfn == NULL)
  200. return fResult;
  201. }
  202. fResult = s_pfn(hActCtx,lpCookie);
  203. return fResult;
  204. }
  205. ISOLATION_AWARE_INLINE BOOL WINAPI IsolationAwareDeactivateActCtx(DWORD dwFlags,ULONG_PTR ulCookie)
  206. {
  207. BOOL fResult = FALSE;
  208. typedef BOOL (WINAPI* PFN)(DWORD dwFlags,ULONG_PTR ulCookie);
  209. static PFN s_pfn;
  210. if (s_pfn == NULL)
  211. {
  212. s_pfn = (PFN)WinbaseIsolationAwarePrivatetRgCebPnQQeRff_xReaRYQP_QYY("DeactivateActCtx");
  213. if (s_pfn == NULL)
  214. return fResult;
  215. }
  216. fResult = s_pfn(dwFlags,ulCookie);
  217. return fResult;
  218. }
  219. ISOLATION_AWARE_INLINE BOOL WINAPI IsolationAwareFindActCtxSectionStringW(DWORD dwFlags,const GUID*lpExtensionGuid,ULONG ulSectionId,LPCWSTR lpStringToFind,PACTCTX_SECTION_KEYED_DATA ReturnedData)
  220. {
  221. BOOL fResult = FALSE;
  222. typedef BOOL (WINAPI* PFN)(DWORD dwFlags,const GUID*lpExtensionGuid,ULONG ulSectionId,LPCWSTR lpStringToFind,PACTCTX_SECTION_KEYED_DATA ReturnedData);
  223. static PFN s_pfn;
  224. if (s_pfn == NULL)
  225. {
  226. s_pfn = (PFN)WinbaseIsolationAwarePrivatetRgCebPnQQeRff_xReaRYQP_QYY("FindActCtxSectionStringW");
  227. if (s_pfn == NULL)
  228. return fResult;
  229. }
  230. fResult = s_pfn(dwFlags,lpExtensionGuid,ulSectionId,lpStringToFind,ReturnedData);
  231. return fResult;
  232. }
  233. ISOLATION_AWARE_INLINE BOOL WINAPI IsolationAwareQueryActCtxW(DWORD dwFlags,HANDLE hActCtx,PVOID pvSubInstance,ULONG ulInfoClass,PVOID pvBuffer,SIZE_T cbBuffer,SIZE_T*pcbWrittenOrRequired)
  234. {
  235. BOOL fResult = FALSE;
  236. typedef BOOL (WINAPI* PFN)(DWORD dwFlags,HANDLE hActCtx,PVOID pvSubInstance,ULONG ulInfoClass,PVOID pvBuffer,SIZE_T cbBuffer,SIZE_T*pcbWrittenOrRequired);
  237. static PFN s_pfn;
  238. if (s_pfn == NULL)
  239. {
  240. s_pfn = (PFN)WinbaseIsolationAwarePrivatetRgCebPnQQeRff_xReaRYQP_QYY("QueryActCtxW");
  241. if (s_pfn == NULL)
  242. return fResult;
  243. }
  244. fResult = s_pfn(dwFlags,hActCtx,pvSubInstance,ulInfoClass,pvBuffer,cbBuffer,pcbWrittenOrRequired);
  245. return fResult;
  246. }
  247. #define WINBASE_NUMBER_OF(x) (sizeof(x) / sizeof((x)[0]))
  248. typedef struct IsolationAwarePrivate_pBAFGnAG_zBqHyr_vAsB {
  249. HMODULE (WINAPI * WinbaseIsolationAwarePrivateybNQn)(LPCSTR a);
  250. HMODULE (WINAPI * WinbaseIsolationAwarePrivateybNQJ)(LPCWSTR w);
  251. PCSTR WinbaseIsolationAwarePrivateANZRn;
  252. PCWSTR WinbaseIsolationAwarePrivateANZRJ;
  253. } IsolationAwarePrivatepBAFGnAG_zBqHyr_vAsB;
  254. typedef const IsolationAwarePrivatepBAFGnAG_zBqHyr_vAsB *IsolationAwarePrivateCpBAFGnAG_zBqHyr_vAsB;
  255. typedef struct IsolationAwarePrivate_zHGnoyr_zBqHyr_vAsB {
  256. HMODULE WinbaseIsolationAwarePrivateybNQRQzbQhYR;
  257. } IsolationAwarePrivatezHGnoyr_zBqHyr_vAsB, *IsolationAwarePrivateCzHGnoyr_zBqHyr_vAsB;
  258. ISOLATION_AWARE_INLINE FARPROC WINAPI
  259. IsolationAwarePrivatezltRgCebPnQQeRff(
  260. IsolationAwarePrivateCpBAFGnAG_zBqHyr_vAsB c,
  261. IsolationAwarePrivateCzHGnoyr_zBqHyr_vAsB m,
  262. LPCSTR ProcName
  263. )
  264. {
  265. static HMODULE s_moduleUnicows;
  266. static BOOL s_fUnicowsInitialized;
  267. FARPROC Proc = NULL;
  268. HMODULE hModule;
  269. /*
  270. get unicows.dll loaded on-demand
  271. */
  272. if (!s_fUnicowsInitialized)
  273. {
  274. if ((GetVersion() & 0x80000000) != 0)
  275. {
  276. GetFileAttributesW(L"???.???");
  277. s_moduleUnicows = GetModuleHandleA("Unicows.dll");
  278. }
  279. s_fUnicowsInitialized = TRUE;
  280. }
  281. /*
  282. always call GetProcAddress(unicows) before the usual .dll
  283. */
  284. if (s_moduleUnicows != NULL)
  285. {
  286. Proc = GetProcAddress(s_moduleUnicows, ProcName);
  287. if (Proc != NULL)
  288. goto Exit;
  289. }
  290. hModule = m->WinbaseIsolationAwarePrivateybNQRQzbQhYR;
  291. if (hModule == NULL)
  292. {
  293. hModule = (((GetVersion() & 0x80000000) != 0) ? (*c->WinbaseIsolationAwarePrivateybNQn)(c->WinbaseIsolationAwarePrivateANZRn) : (*c->WinbaseIsolationAwarePrivateybNQJ)(c->WinbaseIsolationAwarePrivateANZRJ));
  294. if (hModule == NULL)
  295. goto Exit;
  296. m->WinbaseIsolationAwarePrivateybNQRQzbQhYR = hModule;
  297. }
  298. Proc = GetProcAddress(hModule, ProcName);
  299. Exit:
  300. return Proc;
  301. }
  302. ISOLATION_AWARE_INLINE BOOL WINAPI WinbaseIsolationAwarePrivatetRgzlnPgpgk(void)
  303. /*
  304. The correctness of this function depends on it being statically
  305. linked into its clients.
  306. This function is private to functions present in this header.
  307. Do not use it.
  308. */
  309. {
  310. BOOL fResult = FALSE;
  311. ACTIVATION_CONTEXT_BASIC_INFORMATION actCtxBasicInfo;
  312. ULONG_PTR ulpCookie = 0;
  313. if (IsolationAwarePrivateT_SqbjaYRiRY)
  314. {
  315. fResult = TRUE;
  316. goto Exit;
  317. }
  318. if (WinbaseIsolationAwarePrivateT_UnPgpgk != INVALID_HANDLE_VALUE)
  319. {
  320. fResult = TRUE;
  321. goto Exit;
  322. }
  323. if (!IsolationAwareQueryActCtxW(
  324. QUERY_ACTCTX_FLAG_ACTCTX_IS_ADDRESS
  325. | QUERY_ACTCTX_FLAG_NO_ADDREF,
  326. &WinbaseIsolationAwarePrivateT_UnPgpgk,
  327. NULL,
  328. ActivationContextBasicInformation,
  329. &actCtxBasicInfo,
  330. sizeof(actCtxBasicInfo),
  331. NULL
  332. ))
  333. goto Exit;
  334. /*
  335. If QueryActCtxW returns NULL, try CreateActCtx(3).
  336. */
  337. if (actCtxBasicInfo.hActCtx == NULL)
  338. {
  339. ACTCTXW actCtx;
  340. WCHAR rgchFullModulePath[MAX_PATH + 2];
  341. DWORD dw;
  342. HMODULE hmodSelf;
  343. PGET_MODULE_HANDLE_EXW pfnGetModuleHandleExW;
  344. pfnGetModuleHandleExW = (PGET_MODULE_HANDLE_EXW)WinbaseIsolationAwarePrivatetRgCebPnQQeRff_xReaRYQP_QYY("GetModuleHandleExW");
  345. if (pfnGetModuleHandleExW == NULL)
  346. goto Exit;
  347. if (!(*pfnGetModuleHandleExW)(
  348. GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT
  349. | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
  350. (LPCWSTR)&WinbaseIsolationAwarePrivateT_UnPgpgk,
  351. &hmodSelf
  352. ))
  353. goto Exit;
  354. rgchFullModulePath[WINBASE_NUMBER_OF(rgchFullModulePath) - 1] = 0;
  355. rgchFullModulePath[WINBASE_NUMBER_OF(rgchFullModulePath) - 2] = 0;
  356. dw = GetModuleFileNameW(hmodSelf, rgchFullModulePath, WINBASE_NUMBER_OF(rgchFullModulePath)-1);
  357. if (dw == 0)
  358. goto Exit;
  359. if (rgchFullModulePath[WINBASE_NUMBER_OF(rgchFullModulePath) - 2] != 0)
  360. {
  361. SetLastError(ERROR_BUFFER_OVERFLOW);
  362. goto Exit;
  363. }
  364. actCtx.cbSize = sizeof(actCtx);
  365. actCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
  366. actCtx.lpSource = rgchFullModulePath;
  367. actCtx.lpResourceName = (LPCWSTR)(ULONG_PTR)3;
  368. actCtx.hModule = hmodSelf;
  369. actCtxBasicInfo.hActCtx = IsolationAwareCreateActCtxW(&actCtx);
  370. if (actCtxBasicInfo.hActCtx == INVALID_HANDLE_VALUE)
  371. {
  372. const DWORD dwLastError = GetLastError();
  373. if ((dwLastError != ERROR_RESOURCE_DATA_NOT_FOUND) &&
  374. (dwLastError != ERROR_RESOURCE_TYPE_NOT_FOUND) &&
  375. (dwLastError != ERROR_RESOURCE_LANG_NOT_FOUND) &&
  376. (dwLastError != ERROR_RESOURCE_NAME_NOT_FOUND))
  377. goto Exit;
  378. actCtxBasicInfo.hActCtx = NULL;
  379. }
  380. WinbaseIsolationAwarePrivateT_SpeRNgRQnPgpgk = TRUE;
  381. }
  382. WinbaseIsolationAwarePrivateT_UnPgpgk = actCtxBasicInfo.hActCtx;
  383. #define ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION (2)
  384. if (IsolationAwareActivateActCtx(actCtxBasicInfo.hActCtx, &ulpCookie))
  385. {
  386. __try
  387. {
  388. ACTCTX_SECTION_KEYED_DATA actCtxSectionKeyedData;
  389. actCtxSectionKeyedData.cbSize = sizeof(actCtxSectionKeyedData);
  390. if (IsolationAwareFindActCtxSectionStringW(0, NULL, ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION, L"Comctl32.dll", &actCtxSectionKeyedData))
  391. {
  392. /* get button, edit, etc. registered */
  393. LoadLibraryW(L"Comctl32.dll");
  394. }
  395. }
  396. __finally
  397. {
  398. IsolationAwareDeactivateActCtx(0, ulpCookie);
  399. }
  400. }
  401. fResult = TRUE;
  402. Exit:
  403. return fResult;
  404. }
  405. ISOLATION_AWARE_INLINE BOOL WINAPI IsolationAwareInit(void)
  406. /*
  407. The correctness of this function depends on it being statically
  408. linked into its clients.
  409. Call this from DllMain(DLL_PROCESS_ATTACH) if you use id 3 and wish to avoid a race condition that
  410. can cause an hActCtx leak.
  411. Call this from your .exe's initialization if you use id 3 and wish to avoid a race condition that
  412. can cause an hActCtx leak.
  413. If you use id 2, this function fetches data from your .dll
  414. that you do not need to worry about cleaning up.
  415. */
  416. {
  417. return WinbaseIsolationAwarePrivatetRgzlnPgpgk();
  418. }
  419. ISOLATION_AWARE_INLINE void WINAPI IsolationAwareCleanup(void)
  420. /*
  421. Call this from DllMain(DLL_PROCESS_DETACH), if you use id 3, to avoid a leak.
  422. Call this from your .exe's cleanup to possibly avoid apparent (but not actual) leaks, if use id 3.
  423. This function does nothing, safely, if you use id 2.
  424. */
  425. {
  426. HANDLE hActCtx;
  427. if (WinbaseIsolationAwarePrivateT_SpYRNahcpNYYRQ)
  428. return;
  429. /* IsolationAware* calls made from here on out will OutputDebugString
  430. and use the process default activation context instead of id 3 or will
  431. continue to successfully use id 2 (but still OutputDebugString).
  432. */
  433. WinbaseIsolationAwarePrivateT_SpYRNahcpNYYRQ = TRUE;
  434. /* There is no cleanup to do if we did not CreateActCtx but only called QueryActCtx.
  435. */
  436. if (!WinbaseIsolationAwarePrivateT_SpeRNgRQnPgpgk)
  437. return;
  438. hActCtx = WinbaseIsolationAwarePrivateT_UnPgpgk;
  439. WinbaseIsolationAwarePrivateT_UnPgpgk = NULL; /* process default */
  440. if (hActCtx == INVALID_HANDLE_VALUE)
  441. return;
  442. if (hActCtx == NULL)
  443. return;
  444. IsolationAwareReleaseActCtx(hActCtx);
  445. }
  446. ISOLATION_AWARE_INLINE BOOL WINAPI IsolationAwarePrivatenPgViNgRzlnPgpgk(ULONG_PTR* pulpCookie)
  447. /*
  448. This function is private to functions present in this header and other headers.
  449. */
  450. {
  451. BOOL fResult = FALSE;
  452. if (WinbaseIsolationAwarePrivateT_SpYRNahcpNYYRQ)
  453. {
  454. const static char debugString[] = "IsolationAware function called after IsolationAwareCleanup\n";
  455. OutputDebugStringA(debugString);
  456. }
  457. if (IsolationAwarePrivateT_SqbjaYRiRY)
  458. {
  459. fResult = TRUE;
  460. goto Exit;
  461. }
  462. /* Do not call Init if Cleanup has been called. */
  463. if (!WinbaseIsolationAwarePrivateT_SpYRNahcpNYYRQ)
  464. {
  465. if (!WinbaseIsolationAwarePrivatetRgzlnPgpgk())
  466. goto Exit;
  467. }
  468. /* If Cleanup has been called and id3 was in use, this will activate NULL. */
  469. if (!IsolationAwareActivateActCtx(WinbaseIsolationAwarePrivateT_UnPgpgk, pulpCookie))
  470. goto Exit;
  471. fResult = TRUE;
  472. Exit:
  473. if (!fResult)
  474. {
  475. const DWORD dwLastError = GetLastError();
  476. if (dwLastError == ERROR_PROC_NOT_FOUND
  477. || dwLastError == ERROR_CALL_NOT_IMPLEMENTED
  478. )
  479. {
  480. IsolationAwarePrivateT_SqbjaYRiRY = TRUE;
  481. fResult = TRUE;
  482. }
  483. }
  484. return fResult;
  485. }
  486. #undef WINBASE_NUMBER_OF
  487. ISOLATION_AWARE_INLINE FARPROC WINAPI WinbaseIsolationAwarePrivatetRgCebPnQQeRff_xReaRYQP_QYY(LPCSTR pszProcName)
  488. /* This function is shared by the other stubs in this header. */
  489. {
  490. static HMODULE s_module;
  491. /* Use GetModuleHandle instead of LoadLibrary on kernel32.dll because */
  492. /* we already necessarily have a reference on kernel32.dll. */
  493. const static IsolationAwarePrivatepBAFGnAG_zBqHyr_vAsB
  494. c = { IsolationAwarePrivatezltRgzbQhYRuNaQYRn, IsolationAwarePrivatezltRgzbQhYRuNaQYRJ, "Kernel32.dll", L"Kernel32.dll" };
  495. static IsolationAwarePrivatezHGnoyr_zBqHyr_vAsB m;
  496. return IsolationAwarePrivatezltRgCebPnQQeRff(&c, &m, pszProcName);
  497. }
  498. #endif /* ISOLATION_AWARE_USE_STATIC_LIBRARY */
  499. #define ActivateActCtx IsolationAwareActivateActCtx
  500. #define CreateActCtxW IsolationAwareCreateActCtxW
  501. #define DeactivateActCtx IsolationAwareDeactivateActCtx
  502. #define FindActCtxSectionStringW IsolationAwareFindActCtxSectionStringW
  503. #define LoadLibraryA IsolationAwareLoadLibraryA
  504. #define LoadLibraryExA IsolationAwareLoadLibraryExA
  505. #define LoadLibraryExW IsolationAwareLoadLibraryExW
  506. #define LoadLibraryW IsolationAwareLoadLibraryW
  507. #define QueryActCtxW IsolationAwareQueryActCtxW
  508. #define ReleaseActCtx IsolationAwareReleaseActCtx
  509. #endif /* ISOLATION_AWARE_ENABLED */
  510. #endif /* RC */
  511. #if defined(__cplusplus)
  512. } /* __cplusplus */
  513. #endif