ReactOS 0.4.15-dev-8339-g4028de8
vdm.h File Reference
#include <win/vdm.h>
Include dependency graph for vdm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _VDM_CONSOLE_RECORD
 
struct  _VDM_DOS_RECORD
 

Macros

#define VDM_POLICY_KEY_NAME   L"Software\\Policies\\Microsoft\\Windows\\AppCompat"
 
#define VDM_DISALLOWED_VALUE_NAME   L"VDMDisallowed"
 

Typedefs

typedef struct _VDM_CONSOLE_RECORD VDM_CONSOLE_RECORD
 
typedef struct _VDM_CONSOLE_RECORDPVDM_CONSOLE_RECORD
 
typedef struct _VDM_DOS_RECORD VDM_DOS_RECORD
 
typedef struct _VDM_DOS_RECORDPVDM_DOS_RECORD
 

Functions

NTSTATUS BaseSrvGetConsoleRecord (HANDLE ConsoleHandle, PVDM_CONSOLE_RECORD *Record)
 
NTSTATUS GetConsoleRecordBySessionId (ULONG TaskId, PVDM_CONSOLE_RECORD *Record)
 
BOOLEAN BaseSrvIsVdmAllowed (VOID)
 
VOID BaseInitializeVDM (VOID)
 
VOID BaseSrvCleanupVDMResources (IN PCSR_PROCESS CsrProcess)
 

Macro Definition Documentation

◆ VDM_DISALLOWED_VALUE_NAME

#define VDM_DISALLOWED_VALUE_NAME   L"VDMDisallowed"

Definition at line 17 of file vdm.h.

◆ VDM_POLICY_KEY_NAME

#define VDM_POLICY_KEY_NAME   L"Software\\Policies\\Microsoft\\Windows\\AppCompat"

Definition at line 16 of file vdm.h.

Typedef Documentation

◆ PVDM_CONSOLE_RECORD

◆ PVDM_DOS_RECORD

◆ VDM_CONSOLE_RECORD

◆ VDM_DOS_RECORD

Function Documentation

◆ BaseInitializeVDM()

VOID BaseInitializeVDM ( VOID  )

Definition at line 587 of file vdm.c.

588{
589 /* Initialize the list head */
591
592 /* Initialize the critical sections */
595}
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
LIST_ENTRY VDMConsoleListHead
Definition: vdm.c:21
RTL_CRITICAL_SECTION DosCriticalSection
Definition: vdm.c:22
RTL_CRITICAL_SECTION WowCriticalSection
Definition: vdm.c:23

Referenced by CSR_SERVER_DLL_INIT().

◆ BaseSrvCleanupVDMResources()

VOID BaseSrvCleanupVDMResources ( IN PCSR_PROCESS  CsrProcess)

Definition at line 296 of file vdm.c.

297{
298 ULONG ProcessId = HandleToUlong(CsrProcess->ClientId.UniqueProcess);
299 PVDM_CONSOLE_RECORD ConsoleRecord = NULL;
300 PVDM_DOS_RECORD DosRecord;
302
303 /* Enter the critical section */
305
306 /* Search for a record that has the same process handle */
308 while (i != &VDMConsoleListHead)
309 {
310 ConsoleRecord = CONTAINING_RECORD(i, VDM_CONSOLE_RECORD, Entry);
311 i = i->Flink;
312
313 if (ConsoleRecord->ProcessId == ProcessId)
314 {
315 if (ConsoleRecord->ServerEvent)
316 {
317 NtClose(ConsoleRecord->ServerEvent);
318 ConsoleRecord->ServerEvent = NULL;
319 }
320
321 /* Cleanup the DOS records */
322 while (!IsListEmpty(&ConsoleRecord->DosListHead))
323 {
324 DosRecord = CONTAINING_RECORD(ConsoleRecord->DosListHead.Flink,
326
327 /* Set the event and close it */
328 if (DosRecord->ServerEvent)
329 {
330 NtSetEvent(DosRecord->ServerEvent, NULL);
331 NtClose(DosRecord->ServerEvent);
332 DosRecord->ServerEvent = NULL;
333 }
334
335 /* Remove the DOS entry */
336 if (DosRecord->CommandInfo) BaseSrvFreeVDMInfo(DosRecord->CommandInfo);
337 RemoveEntryList(&DosRecord->Entry);
338 RtlFreeHeap(BaseSrvHeap, 0, DosRecord);
339 }
340
341 /* Remove the console record */
342 RemoveEntryList(&ConsoleRecord->Entry);
343 BaseSrvDestroyConsoleRecord(ConsoleRecord);
344 }
345 }
346
347 /* Leave the critical section */
349}
HANDLE BaseSrvHeap
Definition: init.c:29
#define HandleToUlong(h)
Definition: basetsd.h:79
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define NULL
Definition: types.h:112
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2711
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSTATUS NTAPI NtSetEvent(IN HANDLE EventHandle, OUT PLONG PreviousState OPTIONAL)
Definition: event.c:455
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
HANDLE ServerEvent
Definition: vdm.h:24
LIST_ENTRY Entry
Definition: vdm.h:21
LIST_ENTRY DosListHead
Definition: vdm.h:31
ULONG ProcessId
Definition: vdm.h:26
HANDLE ServerEvent
Definition: vdm.h:39
LIST_ENTRY Entry
Definition: vdm.h:36
PVDM_COMMAND_INFO CommandInfo
Definition: vdm.h:41
VOID BaseSrvDestroyConsoleRecord(PVDM_CONSOLE_RECORD ConsoleRecord)
Definition: vdm.c:71
VOID BaseSrvFreeVDMInfo(PVDM_COMMAND_INFO CommandInfo)
Definition: vdm.c:280
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
PKPROCESS CsrProcess
Definition: videoprt.c:39

Referenced by BaseClientDisconnectRoutine().

◆ BaseSrvGetConsoleRecord()

NTSTATUS BaseSrvGetConsoleRecord ( HANDLE  ConsoleHandle,
PVDM_CONSOLE_RECORD Record 
)

Definition at line 49 of file vdm.c.

50{
52 PVDM_CONSOLE_RECORD CurrentRecord = NULL;
53
54 /* NULL is not a valid console handle */
55 if (ConsoleHandle == NULL) return STATUS_INVALID_PARAMETER;
56
57 /* Search for a record that has the same console handle */
58 for (i = VDMConsoleListHead.Flink; i != &VDMConsoleListHead; i = i->Flink)
59 {
61 if (CurrentRecord->ConsoleHandle == ConsoleHandle) break;
62 }
63
64 /* Check if nothing was found */
65 if (i == &VDMConsoleListHead) CurrentRecord = NULL;
66
67 *Record = CurrentRecord;
68 return CurrentRecord ? STATUS_SUCCESS : STATUS_NOT_FOUND;
69}
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_NOT_FOUND
Definition: shellext.h:72
HANDLE ConsoleHandle
Definition: vdm.h:22
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD * Record
Definition: ketypes.h:268

Referenced by CSR_API().

◆ BaseSrvIsVdmAllowed()

BOOLEAN BaseSrvIsVdmAllowed ( VOID  )

Definition at line 142 of file vdm.c.

143{
145 BOOLEAN VdmAllowed = TRUE;
147 UNICODE_STRING KeyName, ValueName, MachineKeyName;
149 UCHAR ValueBuffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(ULONG)];
151 ULONG ActualSize;
152
153 /* Initialize the unicode strings */
154 RtlInitUnicodeString(&MachineKeyName, L"\\Registry\\Machine");
157
159 &MachineKeyName,
161 NULL,
162 NULL);
163
164 /* Open the local machine key */
166 if (!NT_SUCCESS(Status)) return FALSE;
167
169 &KeyName,
171 RootKey,
172 NULL);
173
174 /* Open the policy key in the local machine hive, if it exists */
176 {
177 /* Read the value, if it's set */
179 &ValueName,
181 ValueInfo,
182 sizeof(ValueBuffer),
183 &ActualSize)))
184 {
185 if (*((PULONG)ValueInfo->Data))
186 {
187 /* The VDM has been disabled in the registry */
188 VdmAllowed = FALSE;
189 }
190 }
191
193 }
194
195 /* Close the local machine key */
197
198 /* If it's disabled system-wide, there's no need to check the user key */
199 if (!VdmAllowed) return FALSE;
200
201 /* Open the current user key of the client */
202 if (!CsrImpersonateClient(NULL)) return VdmAllowed;
205
206 /* If that fails, return the system-wide setting */
207 if (!NT_SUCCESS(Status)) return VdmAllowed;
208
210 &KeyName,
212 RootKey,
213 NULL);
214
215 /* Open the policy key in the current user hive, if it exists */
217 {
218 /* Read the value, if it's set */
220 &ValueName,
222 ValueInfo,
223 sizeof(ValueBuffer),
224 &ActualSize)))
225 {
226 if (*((PULONG)ValueInfo->Data))
227 {
228 /* The VDM has been disabled in the registry */
229 VdmAllowed = FALSE;
230 }
231 }
232
234 }
235
236 return VdmAllowed;
237}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI CsrImpersonateClient(IN PCSR_THREAD CsrThread)
Definition: procsup.c:932
BOOLEAN NTAPI CsrRevertToSelf(VOID)
Definition: procsup.c:1057
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI RtlOpenCurrentUser(_In_ ACCESS_MASK DesiredAccess, _Out_ PHANDLE KeyHandle)
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
#define L(x)
Definition: ntvdm.h:50
static PMEMKEY RootKey
Definition: registry.c:55
#define VDM_POLICY_KEY_NAME
Definition: vdm.h:16
#define VDM_DISALLOWED_VALUE_NAME
Definition: vdm.h:17
uint32_t * PULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by CSR_API().

◆ GetConsoleRecordBySessionId()

NTSTATUS GetConsoleRecordBySessionId ( ULONG  TaskId,
PVDM_CONSOLE_RECORD Record 
)

Definition at line 94 of file vdm.c.

95{
97 PVDM_CONSOLE_RECORD CurrentRecord = NULL;
98
99 /* Search for a record that has the same console handle */
100 for (i = VDMConsoleListHead.Flink; i != &VDMConsoleListHead; i = i->Flink)
101 {
102 CurrentRecord = CONTAINING_RECORD(i, VDM_CONSOLE_RECORD, Entry);
103 if (CurrentRecord->SessionId == TaskId) break;
104 }
105
106 /* Check if nothing was found */
107 if (i == &VDMConsoleListHead) CurrentRecord = NULL;
108
109 *Record = CurrentRecord;
110 return CurrentRecord ? STATUS_SUCCESS : STATUS_NOT_FOUND;
111}
ULONG SessionId
Definition: vdm.h:30

Referenced by CSR_API().