Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenvdmmain.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/vdm/vdmmain.c 00005 * PURPOSE: VDM Support Services 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 * Aleksey Bragin (aleksey@reactos.org) 00008 */ 00009 00010 /* INCLUDES ******************************************************************/ 00011 00012 #include <ntoskrnl.h> 00013 #define NDEBUG 00014 #include <debug.h> 00015 00016 /* GLOBALS *******************************************************************/ 00017 00018 /* PRIVATE FUNCTIONS *********************************************************/ 00019 00020 VOID 00021 NTAPI 00022 INIT_FUNCTION 00023 Ki386VdmEnablePentiumExtentions(IN BOOLEAN Enable) 00024 { 00025 ULONG EFlags, Cr4; 00026 00027 /* Save interrupt state and disable them */ 00028 EFlags = __readeflags(); 00029 _disable(); 00030 00031 /* Enable or disable VME as required */ 00032 Cr4 = __readcr4(); 00033 __writecr4(Enable ? Cr4 | CR4_VME : Cr4 & ~CR4_VME); 00034 00035 /* Restore interrupt state */ 00036 __writeeflags(EFlags); 00037 } 00038 00039 VOID 00040 NTAPI 00041 INIT_FUNCTION 00042 KeI386VdmInitialize(VOID) 00043 { 00044 NTSTATUS Status; 00045 OBJECT_ATTRIBUTES ObjectAttributes; 00046 HANDLE RegHandle; 00047 UNICODE_STRING Name; 00048 UCHAR KeyValueInfo[sizeof(KEY_VALUE_BASIC_INFORMATION) + 30]; 00049 ULONG ReturnLength; 00050 00051 /* Make sure that there is a WOW key */ 00052 RtlInitUnicodeString(&Name, 00053 L"\\Registry\\Machine\\System\\CurrentControlSet\\" 00054 L"Control\\Wow"); 00055 InitializeObjectAttributes(&ObjectAttributes, 00056 &Name, 00057 OBJ_CASE_INSENSITIVE, 00058 NULL, 00059 NULL); 00060 Status = ZwOpenKey(&RegHandle, KEY_READ, &ObjectAttributes); 00061 if (!NT_SUCCESS(Status)) return; 00062 00063 /* Check if VME is enabled */ 00064 RtlInitUnicodeString(&Name, L"DisableVme"); 00065 Status = ZwQueryValueKey(RegHandle, 00066 &Name, 00067 KeyValueBasicInformation, 00068 &KeyValueInfo, 00069 sizeof(KeyValueInfo), 00070 &ReturnLength); 00071 if (!NT_SUCCESS(Status)) 00072 { 00073 /* Not present, so check if the CPU supports VME */ 00074 if (KeGetPcr()->Prcb->FeatureBits & KF_V86_VIS) 00075 { 00076 /* Enable them. FIXME: Use IPI */ 00077 Ki386VdmEnablePentiumExtentions(TRUE); 00078 KeI386VirtualIntExtensions = TRUE; 00079 } 00080 } 00081 00082 /* Close the key */ 00083 ZwClose(RegHandle); 00084 } 00085 00086 NTSTATUS 00087 NTAPI 00088 INIT_FUNCTION 00089 VdmpInitialize(PVOID ControlData) 00090 { 00091 OBJECT_ATTRIBUTES ObjectAttributes; 00092 UNICODE_STRING PhysMemName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory"); 00093 NTSTATUS Status; 00094 HANDLE PhysMemHandle; 00095 PVOID BaseAddress; 00096 PVOID NullAddress = NULL; 00097 LARGE_INTEGER Offset; 00098 ULONG ViewSize; 00099 00100 /* Open the physical memory section */ 00101 InitializeObjectAttributes(&ObjectAttributes, 00102 &PhysMemName, 00103 0, 00104 NULL, 00105 NULL); 00106 Status = ZwOpenSection(&PhysMemHandle, 00107 SECTION_ALL_ACCESS, 00108 &ObjectAttributes); 00109 if (!NT_SUCCESS(Status)) 00110 { 00111 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n"); 00112 return Status; 00113 } 00114 00115 /* Map the BIOS and device registers into the address space */ 00116 Offset.QuadPart = 0; 00117 ViewSize = PAGE_SIZE; 00118 BaseAddress = 0; 00119 Status = ZwMapViewOfSection(PhysMemHandle, 00120 NtCurrentProcess(), 00121 &BaseAddress, 00122 0, 00123 ViewSize, 00124 &Offset, 00125 &ViewSize, 00126 ViewUnmap, 00127 0, 00128 PAGE_READWRITE); 00129 if (!NT_SUCCESS(Status)) 00130 { 00131 DPRINT1("Couldn't map physical memory (%x)\n", Status); 00132 ZwClose(PhysMemHandle); 00133 return Status; 00134 } 00135 00136 /* Enter SEH */ 00137 _SEH2_TRY 00138 { 00139 /* Copy the first physical page into the first virtual page */ 00140 RtlMoveMemory(NullAddress, BaseAddress, ViewSize); 00141 } 00142 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 00143 { 00144 /* Fail */ 00145 DPRINT1("Couldn't copy first page (%x)\n", Status); 00146 ZwClose(PhysMemHandle); 00147 ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress); 00148 _SEH2_YIELD(return _SEH2_GetExceptionCode()); 00149 } 00150 _SEH2_END; 00151 00152 /* Close physical memory section handle */ 00153 ZwClose(PhysMemHandle); 00154 00155 /* Unmap the section */ 00156 Status = ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress); 00157 00158 if (!NT_SUCCESS(Status)) 00159 { 00160 DPRINT1("Couldn't unmap the section (%x)\n", Status); 00161 return Status; 00162 } 00163 00164 return STATUS_SUCCESS; 00165 } 00166 00167 /* PUBLIC FUNCTIONS **********************************************************/ 00168 00169 /* 00170 * @implemented 00171 */ 00172 NTSTATUS 00173 NTAPI 00174 NtVdmControl(IN ULONG ControlCode, 00175 IN PVOID ControlData) 00176 { 00177 NTSTATUS Status; 00178 PAGED_CODE(); 00179 00180 /* Check which control code this is */ 00181 switch (ControlCode) 00182 { 00183 /* VDM Execution start */ 00184 case VdmStartExecution: 00185 00186 /* Call the sub-function */ 00187 Status = VdmpStartExecution(); 00188 break; 00189 00190 case VdmInitialize: 00191 00192 /* Call the init sub-function */ 00193 Status = VdmpInitialize(ControlData); 00194 break; 00195 00196 default: 00197 00198 /* Unsupported */ 00199 DPRINT1("Unknown VDM call: %lx\n", ControlCode); 00200 Status = STATUS_INVALID_PARAMETER; 00201 } 00202 00203 /* Return the status */ 00204 return Status; 00205 } Generated on Fri May 25 2012 04:36:07 for ReactOS by
1.7.6.1
|