ReactOS 0.4.15-dev-5669-g09dde2c
vdmmain.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for vdmmain.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI Ki386VdmEnablePentiumExtentions (IN BOOLEAN Enable)
 
VOID NTAPI KeI386VdmInitialize (VOID)
 
NTSTATUS NTAPI VdmpInitialize (PVOID ControlData)
 
NTSTATUS NTAPI NtVdmControl (IN ULONG ControlCode, IN PVOID ControlData)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file vdmmain.c.

Function Documentation

◆ KeI386VdmInitialize()

VOID NTAPI KeI386VdmInitialize ( VOID  )

Definition at line 42 of file vdmmain.c.

43{
48 UCHAR KeyValueInfo[sizeof(KEY_VALUE_BASIC_INFORMATION) + 30];
50
51 /* Make sure that there is a WOW key */
53 L"\\Registry\\Machine\\System\\CurrentControlSet\\"
54 L"Control\\Wow");
56 &Name,
58 NULL,
59 NULL);
61 if (!NT_SUCCESS(Status)) return;
62
63 /* Check if VME is enabled */
64 RtlInitUnicodeString(&Name, L"DisableVme");
65 Status = ZwQueryValueKey(RegHandle,
66 &Name,
68 &KeyValueInfo,
69 sizeof(KeyValueInfo),
71 if (!NT_SUCCESS(Status))
72 {
73 /* Not present, so check if the CPU supports VME */
74 if (KeGetPcr()->Prcb->FeatureBits & KF_V86_VIS)
75 {
76 /* Enable them. FIXME: Use IPI */
79 }
80 }
81
82 /* Close the key */
84}
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KF_V86_VIS
Definition: ketypes.h:143
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
struct _KEY_VALUE_BASIC_INFORMATION KEY_VALUE_BASIC_INFORMATION
@ KeyValueBasicInformation
Definition: nt_native.h:1180
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
BOOLEAN KeI386VirtualIntExtensions
Definition: v86vdm.c:24
#define L(x)
Definition: ntvdm.h:50
#define KeGetPcr()
Definition: ke.h:26
uint32_t ULONG
Definition: typedefs.h:59
VOID NTAPI Ki386VdmEnablePentiumExtentions(IN BOOLEAN Enable)
Definition: vdmmain.c:23
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:78
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by Phase1InitializationDiscard().

◆ Ki386VdmEnablePentiumExtentions()

VOID NTAPI Ki386VdmEnablePentiumExtentions ( IN BOOLEAN  Enable)

Definition at line 23 of file vdmmain.c.

24{
25 ULONG EFlags, Cr4;
26
27 /* Save interrupt state and disable them */
28 EFlags = __readeflags();
29 _disable();
30
31 /* Enable or disable VME as required */
32 Cr4 = __readcr4();
33 __writecr4(Enable ? Cr4 | CR4_VME : Cr4 & ~CR4_VME);
34
35 /* Restore interrupt state */
36 __writeeflags(EFlags);
37}
void __cdecl _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1669
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1825
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1799
#define CR4_VME
Definition: ketypes.h:84
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142

Referenced by KeI386VdmInitialize().

◆ NtVdmControl()

NTSTATUS NTAPI NtVdmControl ( IN ULONG  ControlCode,
IN PVOID  ControlData 
)

Definition at line 173 of file vdmmain.c.

175{
177 PAGED_CODE();
178
179 /* Check which control code this is */
180 switch (ControlCode)
181 {
182 /* VDM Execution start */
184
185 /* Call the sub-function */
187 break;
188
189 case VdmInitialize:
190
191 /* Call the init sub-function */
192 Status = VdmpInitialize(ControlData);
193 break;
194
195 default:
196
197 /* Unsupported */
198 DPRINT1("Unknown VDM call: %lx\n", ControlCode);
200 }
201
202 /* Return the status */
203 return Status;
204}
#define PAGED_CODE()
#define DPRINT1
Definition: precomp.h:8
@ VdmInitialize
Definition: ketypes.h:508
@ VdmStartExecution
Definition: ketypes.h:505
NTSTATUS NTAPI VdmpStartExecution(VOID)
Definition: vdmexec.c:171
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI VdmpInitialize(PVOID ControlData)
Definition: vdmmain.c:88
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

◆ VdmpInitialize()

NTSTATUS NTAPI VdmpInitialize ( PVOID  ControlData)

Definition at line 88 of file vdmmain.c.

89{
91 UNICODE_STRING PhysMemName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
93 HANDLE PhysMemHandle;
95 volatile PVOID NullAddress = NULL;
98
99 /* Open the physical memory section */
101 &PhysMemName,
103 NULL,
104 NULL);
105 Status = ZwOpenSection(&PhysMemHandle,
108 if (!NT_SUCCESS(Status))
109 {
110 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
111 return Status;
112 }
113
114 /* Map the BIOS and device registers into the address space */
115 Offset.QuadPart = 0;
117 BaseAddress = 0;
118 Status = ZwMapViewOfSection(PhysMemHandle,
121 0,
122 ViewSize,
123 &Offset,
124 &ViewSize,
125 ViewUnmap,
126 0,
128 if (!NT_SUCCESS(Status))
129 {
130 DPRINT1("Couldn't map physical memory (%x)\n", Status);
131 ZwClose(PhysMemHandle);
132 return Status;
133 }
134
135 /* Enter SEH */
137 {
138 /* Copy the first physical page into the first virtual page */
139 RtlMoveMemory(NullAddress, BaseAddress, ViewSize);
140 }
142 {
143 /* Fail */
144 DPRINT1("Couldn't copy first page (%x)\n", Status);
145 ZwClose(PhysMemHandle);
146 ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
148 }
149 _SEH2_END;
150
151 /* Close physical memory section handle */
152 ZwClose(PhysMemHandle);
153
154 /* Unmap the section */
155 Status = ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
156
157 if (!NT_SUCCESS(Status))
158 {
159 DPRINT1("Couldn't unmap the section (%x)\n", Status);
160 return Status;
161 }
162
163 return STATUS_SUCCESS;
164}
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSYSAPI NTSTATUS NTAPI ZwOpenSection(_Out_ PHANDLE SectionHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:408
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define NtCurrentProcess()
Definition: nt_native.h:1657
@ ViewUnmap
Definition: nt_native.h:1279
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264

Referenced by NtVdmControl().