Author: mjansen
Date: Sun Jul 2 11:43:54 2017
New Revision: 75262
URL:
http://svn.reactos.org/svn/reactos?rev=75262&view=rev
Log:
[APPHELP] Propagate applied layers to child processes by setting the env var
__COMPAT_LAYER. CORE-13284
Modified:
trunk/reactos/dll/appcompat/apphelp/shimeng.c
Modified: trunk/reactos/dll/appcompat/apphelp/shimeng.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/shim…
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/shimeng.c [iso-8859-1] (original)
+++ trunk/reactos/dll/appcompat/apphelp/shimeng.c [iso-8859-1] Sun Jul 2 11:43:54 2017
@@ -330,8 +330,7 @@
}
-
-VOID SeiAddShim(TAGREF trShimRef, PARRAY pShimRef)
+static VOID SeiAddShim(TAGREF trShimRef, PARRAY pShimRef)
{
TAGREF* Data;
if (!ARRAY_EnsureSize(pShimRef, sizeof(TAGREF), 10))
@@ -342,8 +341,26 @@
pShimRef->Size++;
}
-VOID SeiBuildShimRefArray(HSDB hsdb, SDBQUERYRESULT* pQuery, PARRAY pShimRef)
-{
+static VOID SeiSetLayerEnvVar(LPCWSTR wszLayer)
+{
+ NTSTATUS Status;
+ UNICODE_STRING VarName = RTL_CONSTANT_STRING(L"__COMPAT_LAYER");
+ UNICODE_STRING Value;
+
+ RtlInitUnicodeString(&Value, wszLayer);
+
+ Status = RtlSetEnvironmentVariable(NULL, &VarName, &Value);
+ if (NT_SUCCESS(Status))
+ SHIMENG_INFO("Set env var %wZ=%wZ\n", &VarName, &Value);
+ else
+ SHIMENG_FAIL("Failed to set %wZ: 0x%x\n", &VarName, Status);
+}
+
+#define MAX_LAYER_LENGTH 256
+
+static VOID SeiBuildShimRefArray(HSDB hsdb, SDBQUERYRESULT* pQuery, PARRAY pShimRef)
+{
+ WCHAR wszLayerEnvVar[MAX_LAYER_LENGTH] = { 0 };
DWORD n;
for (n = 0; n < pQuery->dwExeCount; ++n)
@@ -382,7 +399,17 @@
LPCWSTR LayerName = SeiGetStringPtr(pdb, tag, TAG_NAME);
TAGID ShimRef = SdbFindFirstTag(pdb, tag, TAG_SHIM_REF);
if (LayerName)
+ {
+ HRESULT hr;
SeiDbgPrint(SEI_MSG, NULL, "ShimInfo(Layer(%S))\n",
LayerName);
+ if (wszLayerEnvVar[0])
+ StringCchCatW(wszLayerEnvVar, _countof(wszLayerEnvVar), L"
");
+ hr = StringCchCatW(wszLayerEnvVar, _countof(wszLayerEnvVar), LayerName);
+ if (!SUCCEEDED(hr))
+ {
+ SHIMENG_FAIL("Unable to append %S\n", LayerName);
+ }
+ }
while (ShimRef != TAGID_NULL)
{
@@ -396,6 +423,8 @@
/* Handle FLAG_REF */
}
}
+ if (wszLayerEnvVar[0])
+ SeiSetLayerEnvVar(wszLayerEnvVar);
}