Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

super.c File Reference

#include "mi.h"
#include "zwapi.h"

Go to the source code of this file.

Classes

struct  _MMSUPER_SECTION

Defines

#define MM_MAX_SUPERSECTION_COUNT   (32)
#define STATUS_TOO_MANY_SECTIONS   ((NTSTATUS)0xC0033333)
#define STATUS_INCOMPLETE_MAP   ((NTSTATUS)0xC0033334)

Typedefs

typedef _MMSUPER_SECTION MMSUPER_SECTION
typedef _MMSUPER_SECTIONPMMSUPER_SECTION

Functions

VOID MiSuperSectionDelete (PVOID Object)
BOOLEAN MiSuperSectionInitialization ()
NTSTATUS NtCreateSuperSection (OUT PHANDLE SuperSectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN ULONG Count, IN HANDLE SectionHandles[])
NTSTATUS NtOpenSuperSection (OUT PHANDLE SuperSectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,)
NTSTATUS NtMapViewOfSuperSection (IN HANDLE SuperSectionHandle, IN HANDLE ProcessHandle, IN OUT PULONG Count, OUT PVOID BaseAddress[], OUT ULONG ViewSize[], IN SECTION_INHERIT InheritDisposition,)

Variables

POBJECT_TYPE MmSuperSectionObjectType
GENERIC_MAPPING MiSectionMapping


Define Documentation

#define MM_MAX_SUPERSECTION_COUNT   (32)
 

Definition at line 39 of file super.c.

Referenced by NtCreateSuperSection(), and NtMapViewOfSuperSection().

#define STATUS_INCOMPLETE_MAP   ((NTSTATUS)0xC0033334)
 

Definition at line 44 of file super.c.

Referenced by NtMapViewOfSuperSection().

#define STATUS_TOO_MANY_SECTIONS   ((NTSTATUS)0xC0033333)
 

Definition at line 43 of file super.c.

Referenced by NtCreateSuperSection().


Typedef Documentation

typedef struct _MMSUPER_SECTION MMSUPER_SECTION
 

Referenced by NtCreateSuperSection().

typedef struct _MMSUPER_SECTION * PMMSUPER_SECTION
 

Referenced by MiSuperSectionDelete(), NtCreateSuperSection(), and NtMapViewOfSuperSection().


Function Documentation

VOID MiSuperSectionDelete PVOID  Object  ) 
 

Definition at line 535 of file super.c.

References LOCK_PFN, MiSuperSectionDelete(), ObDereferenceObject, PMMSUPER_SECTION, _MMSUPER_SECTION::SectionPointers, and UNLOCK_PFN.

Referenced by MiSuperSectionDelete(), and MiSuperSectionInitialization().

00541 : 00542 00543 00544 This routine is called by the object management procedures whenever 00545 the last reference to a super section object has been removed. 00546 This routine dereferences the associated segment objects. 00547 00548 Arguments: 00549 00550 Object - a pointer to the body of the supersection object. 00551 00552 Return Value: 00553 00554 None. 00555 00556 --*/ 00557 00558 { 00559 PMMSUPER_SECTION SuperSection; 00560 PCONTROL_AREA ControlArea; 00561 KIRQL OldIrql; 00562 ULONG i = 0; 00563 00564 SuperSection = (PMMSUPER_SECTION)Object; 00565 00566 do { 00567 00568 // 00569 // For each section increment the number of section references 00570 // count. 00571 // 00572 00573 ControlArea = SuperSection->SectionPointers[i]->Segment->ControlArea; 00574 00575 LOCK_PFN (OldIrql); 00576 ControlArea->NumberOfSectionReferences -= 1; 00577 ControlArea->NumberOfUserReferences -= 1; 00578 UNLOCK_PFN (OldIrql); 00579 ObDereferenceObject (SuperSection->SectionPointers[i]); 00580 i++; 00581 00582 } while (i < SuperSection->NumberOfSections); 00583 00584 return; 00585 }

BOOLEAN MiSuperSectionInitialization  ) 
 

Definition at line 588 of file super.c.

References FALSE, L, MiSectionMapping, MiSuperSectionDelete(), MmSuperSectionObjectType, NT_SUCCESS, NULL, ObCreateObjectType(), PagedPool, RtlInitUnicodeString(), and TRUE.

00593 : 00594 00595 This function creates the section object type descriptor at system 00596 initialization and stores the address of the object type descriptor 00597 in global storage. 00598 00599 Arguments: 00600 00601 None. 00602 00603 Return Value: 00604 00605 TRUE - Initialization was successful. 00606 00607 FALSE - Initialization Failed. 00608 00609 00610 00611 --*/ 00612 00613 { 00614 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; 00615 UNICODE_STRING TypeName; 00616 00617 // 00618 // Initialize the common fields of the Object Type Initializer record 00619 // 00620 00621 RtlZeroMemory( &ObjectTypeInitializer, sizeof( ObjectTypeInitializer ) ); 00622 ObjectTypeInitializer.Length = sizeof( ObjectTypeInitializer ); 00623 ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK; 00624 ObjectTypeInitializer.GenericMapping = MiSectionMapping; 00625 ObjectTypeInitializer.PoolType = PagedPool; 00626 00627 // 00628 // Initialize string descriptor. 00629 // 00630 00631 RtlInitUnicodeString (&TypeName, L"SuperSection"); 00632 00633 // 00634 // Create the section object type descriptor 00635 // 00636 00637 ObjectTypeInitializer.ValidAccessMask = SECTION_ALL_ACCESS; 00638 ObjectTypeInitializer.DeleteProcedure = MiSuperSectionDelete; 00639 ObjectTypeInitializer.GenericMapping = MiSectionMapping; 00640 ObjectTypeInitializer.UseDefaultObject = TRUE; 00641 if ( !NT_SUCCESS(ObCreateObjectType(&TypeName, 00642 &ObjectTypeInitializer, 00643 (PSECURITY_DESCRIPTOR) NULL, 00644 &MmSuperSectionObjectType 00645 )) ) { 00646 return FALSE; 00647 } 00648 00649 return TRUE; 00650 00651 } }

NTSTATUS NtCreateSuperSection OUT PHANDLE  SuperSectionHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL,
IN ULONG  Count,
IN HANDLE  SectionHandles[]
 

Definition at line 56 of file super.c.

References _SEGMENT::ControlArea, Count, EXCEPTION_EXECUTE_HANDLER, ExSystemExceptionFilter(), FALSE, KernelMode, KPROCESSOR_MODE, LOCK_PFN, MM_MAX_SUPERSECTION_COUNT, MmSectionObjectType, MMSUPER_SECTION, MmSuperSectionObjectType, NT_SUCCESS, NTSTATUS(), NULL, _CONTROL_AREA::NumberOfSectionReferences, _CONTROL_AREA::NumberOfUserReferences, ObCreateObject(), ObDereferenceObject, ObInsertObject(), ObjectAttributes, ObReferenceObjectByHandle(), PMMSUPER_SECTION, ProbeForWriteHandle, PSECTION, RefCount, _CONTROL_AREA::Segment, Status, STATUS_TOO_MANY_SECTIONS, and UNLOCK_PFN.

00066 : 00067 00068 This routine creates a super section object. A supersection 00069 object consists a group of sections that are mapped as images. 00070 00071 Arguments: 00072 00073 SuperSectionHandle - Returns a handle to the created supersection. 00074 00075 DesiredAccess - Supplies the desired access for the super section. 00076 00077 ObjectAttributes - Supplies the object attributes for the super 00078 section. 00079 00080 Count - Supplies the number of sections contained in the section 00081 handle array. 00082 00083 SectionHandles[] - Supplies the section handles to place into 00084 the supersection. 00085 00086 00087 Return Value: 00088 00089 Returns the status 00090 00091 TBS 00092 00093 --*/ 00094 00095 { 00096 NTSTATUS Status; 00097 PSECTION Section; 00098 PCONTROL_AREA ControlArea; 00099 HANDLE CapturedHandle; 00100 HANDLE CapturedHandles[MM_MAX_SUPERSECTION_COUNT]; 00101 PMMSUPER_SECTION SuperSection; 00102 KPROCESSOR_MODE PreviousMode; 00103 ULONG RefCount; 00104 ULONG i; 00105 KIRQL OldIrql; 00106 00107 if (Count > MM_MAX_SUPERSECTION_COUNT) { 00108 return STATUS_TOO_MANY_SECTIONS; 00109 } 00110 00111 try { 00112 00113 if (PreviousMode != KernelMode) { 00114 ProbeForWriteHandle (SuperSectionHandle); 00115 } 00116 00117 i= 0; 00118 do { 00119 CapturedHandles[i] = SectionHandles[i]; 00120 i += 1; 00121 } while (i < Count); 00122 00123 } except (ExSystemExceptionFilter()) { 00124 00125 // 00126 // If an exception occurs during the probe or capture 00127 // of the initial values, then handle the exception and 00128 // return the exception code as the status value. 00129 // 00130 00131 return GetExceptionCode(); 00132 } 00133 00134 Status = ObCreateObject (PreviousMode, 00135 MmSuperSectionObjectType, 00136 ObjectAttributes, 00137 PreviousMode, 00138 NULL, 00139 sizeof(MMSUPER_SECTION) + 00140 (sizeof(PSECTION) * (Count - 1)), 00141 sizeof(MMSUPER_SECTION) + 00142 (sizeof(PSECTION) * (Count - 1)), 00143 0, 00144 (PVOID *)&SuperSection); 00145 00146 if (!NT_SUCCESS(Status)) { 00147 return Status; 00148 } 00149 00150 SuperSection->NumberOfSections = Count; 00151 00152 i = 0; 00153 RefCount = 0; 00154 do { 00155 00156 // 00157 // Get a referenced pointer to the specified objects with 00158 // the desired access. 00159 // 00160 00161 Status = ObReferenceObjectByHandle(CapturedHandles[i], 00162 DesiredAccess, 00163 MmSectionObjectType, 00164 PreviousMode, 00165 (PVOID *)&Section, 00166 NULL); 00167 00168 if (NT_SUCCESS(Status) != FALSE) { 00169 if (Section->u.Flags.Image == 0) { 00170 00171 // 00172 // This is not an image section, return an error. 00173 // 00174 00175 Status = STATUS_SECTION_NOT_IMAGE; 00176 goto ServiceFailed; 00177 } 00178 RefCount += 1; 00179 SuperSection->SectionPointers[i] = Section; 00180 } else { 00181 goto ServiceFailed; 00182 } 00183 00184 i += 1; 00185 } while (i < Count); 00186 00187 i= 0; 00188 do { 00189 00190 // 00191 // For each section increment the number of section references 00192 // count. 00193 // 00194 00195 ControlArea = SuperSection->SectionPointers[i]->Segment->ControlArea; 00196 00197 LOCK_PFN (OldIrql); 00198 ControlArea->NumberOfSectionReferences += 1; 00199 ControlArea->NumberOfUserReferences += 1; 00200 UNLOCK_PFN (OldIrql); 00201 i++; 00202 00203 } while (i < Count); 00204 00205 00206 Status = ObInsertObject (SuperSection, 00207 NULL, 00208 DesiredAccess, 00209 0, 00210 (PVOID *)NULL, 00211 &CapturedHandle); 00212 00213 try { 00214 *SuperSectionHandle = CapturedHandle; 00215 } except (EXCEPTION_EXECUTE_HANDLER) { 00216 return Status; 00217 } 00218 return Status; 00219 00220 ServiceFailed: 00221 while (RefCount > 0) { 00222 RefCount -= 1; 00223 ObDereferenceObject(SuperSection->SectionPointers[RefCount]); 00224 } 00225 00226 // 00227 // Delete the supersection object as it was never inserted into 00228 // a handle table. 00229 // 00230 00231 ObDereferenceObject (SuperSection); 00232 return Status; 00233 }

NTSTATUS NtMapViewOfSuperSection IN HANDLE  SuperSectionHandle,
IN HANDLE  ProcessHandle,
IN OUT PULONG  Count,
OUT PVOID  BaseAddress[],
OUT ULONG  ViewSize[],
IN SECTION_INHERIT  InheritDisposition
 

Definition at line 311 of file super.c.

References Count, ExSystemExceptionFilter(), FALSE, KernelMode, KPROCESSOR_MODE, MM_MAX_SUPERSECTION_COUNT, MmMapViewOfSection(), MmSuperSectionObjectType, NT_SUCCESS, NTSTATUS(), NULL, ObDereferenceObject, ObReferenceObjectByHandle(), PMMSUPER_SECTION, ProbeForWrite(), ProbeForWriteUlong, PsProcessType, Status, and STATUS_INCOMPLETE_MAP.

00322 : 00323 00324 This routine maps into the specified process a view of each 00325 section contained within the supersection. 00326 00327 Arguments: 00328 00329 SuperSectionHandle - Supplies a handle to the supersection. 00330 00331 ProcessHandle - Supplies a handle to the process in which to 00332 map the supersection's sections. 00333 00334 Count - Supplies the number of elements in the BaseAddress and 00335 ViewSize arrays, returns the number of views actually 00336 mapped. 00337 00338 00339 BaseAddresses[] - Returns the base address of each view that was mapped. 00340 00341 ViewSize[] - Returns the view size of each view that was mapped. 00342 00343 InheritDisposition - Supplies the inherit disposition to be applied 00344 to each section which is contained in the 00345 super section. 00346 00347 Return Value: 00348 00349 Returns the status 00350 00351 TBS 00352 00353 --*/ 00354 00355 { 00356 NTSTATUS Status; 00357 PVOID CapturedBases[MM_MAX_SUPERSECTION_COUNT]; 00358 ULONG CapturedViews[MM_MAX_SUPERSECTION_COUNT]; 00359 PMMSUPER_SECTION SuperSection; 00360 KPROCESSOR_MODE PreviousMode; 00361 ULONG i; 00362 ULONG CapturedCount; 00363 ULONG NumberMapped; 00364 PEPROCESS Process; 00365 LARGE_INTEGER LargeZero = {0,0}; 00366 00367 00368 PreviousMode = KeGetPreviousMode(); 00369 00370 try { 00371 ProbeForWriteUlong (Count); 00372 CapturedCount = *Count; 00373 00374 if (PreviousMode != KernelMode) { 00375 ProbeForWrite (BaseAddress, 00376 sizeof(PVOID) * CapturedCount, 00377 sizeof(PVOID)); 00378 ProbeForWrite (ViewSize, 00379 sizeof(ULONG) * CapturedCount, 00380 sizeof(ULONG)); 00381 } 00382 00383 } except (ExSystemExceptionFilter()) { 00384 00385 // 00386 // If an exception occurs during the probe or capture 00387 // of the initial values, then handle the exception and 00388 // return the exception code as the status value. 00389 // 00390 00391 return GetExceptionCode(); 00392 } 00393 00394 Status = ObReferenceObjectByHandle ( ProcessHandle, 00395 PROCESS_VM_OPERATION, 00396 PsProcessType, 00397 PreviousMode, 00398 (PVOID *)&Process, 00399 NULL ); 00400 if (!NT_SUCCESS(Status)) { 00401 return Status; 00402 } 00403 00404 // 00405 // Reference the supersection object. 00406 // 00407 00408 Status = ObReferenceObjectByHandle ( SuperSectionHandle, 00409 SECTION_MAP_EXECUTE, 00410 MmSuperSectionObjectType, 00411 PreviousMode, 00412 (PVOID *)&SuperSection, 00413 NULL ); 00414 00415 if (!NT_SUCCESS(Status)) { 00416 ObDereferenceObject (Process); 00417 return Status; 00418 } 00419 00420 if (CapturedCount < SuperSection->NumberOfSections) { 00421 ObDereferenceObject (Process); 00422 ObDereferenceObject (SuperSection); 00423 return STATUS_BUFFER_TOO_SMALL; 00424 } 00425 00426 NumberMapped = 0; 00427 do { 00428 00429 // 00430 // For each section within the supersection, map a view in 00431 // the specified process. 00432 // 00433 00434 Status = MmMapViewOfSection (SuperSection->SectionPointers[i], 00435 Process, 00436 &CapturedBases[i], 00437 0, 00438 0, 00439 &LargeZero, 00440 &CapturedViews[i], 00441 InheritDisposition, 00442 0, 00443 PAGE_EXECUTE); 00444 00445 if (NT_SUCCESS (Status) == FALSE) { 00446 Status = STATUS_INCOMPLETE_MAP; 00447 break; 00448 } 00449 NumberMapped++; 00450 } while (NumberMapped < SuperSection->NumberOfSections); 00451 00452 // 00453 // Dereference the supersection and the process. 00454 // 00455 00456 ObDereferenceObject (SuperSection); 00457 ObDereferenceObject (Process); 00458 00459 try { 00460 *Count = NumberMapped; 00461 i = 0; 00462 00463 do { 00464 00465 // 00466 // Store the captured view base and sizes for each section 00467 // that was mapped. 00468 // 00469 00470 BaseAddress[i] = CapturedBases[i]; 00471 ViewSize[i] = CapturedViews[i]; 00472 00473 i++; 00474 } while (i < NumberMapped); 00475 00476 } except (ExSystemExceptionFilter()) { 00477 NOTHING; 00478 } 00479 00480 return(Status); 00481 }

NTSTATUS NtOpenSuperSection OUT PHANDLE  SuperSectionHandle,
IN ACCESS_MASK  DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes  OPTIONAL
 

Definition at line 237 of file super.c.

References EXCEPTION_EXECUTE_HANDLER, Handle, KernelMode, KPROCESSOR_MODE, MmSuperSectionObjectType, NTSTATUS(), NULL, ObjectAttributes, ObOpenObjectByName(), ProbeForWriteHandle, and Status.

00245 : 00246 00247 This routine opens a super section object. A supersection 00248 object consists a group of sections that are mapped as images. 00249 00250 Arguments: 00251 00252 SuperSectionHandle - Returns a handle to the created supersection. 00253 00254 DesiredAccess - Supplies the desired access for the super section. 00255 00256 ObjectAttributes - Supplies the object attributes for the super 00257 section. 00258 00259 00260 Return Value: 00261 00262 Returns the status 00263 00264 TBS 00265 00266 --*/ 00267 00268 { 00269 HANDLE Handle; 00270 KPROCESSOR_MODE PreviousMode; 00271 NTSTATUS Status; 00272 00273 // 00274 // Get previous processor mode and probe output arguments if necessary. 00275 // 00276 00277 PreviousMode = KeGetPreviousMode(); 00278 if (PreviousMode != KernelMode) { 00279 try { 00280 ProbeForWriteHandle(SuperSectionHandle); 00281 } except (EXCEPTION_EXECUTE_HANDLER) { 00282 return GetExceptionCode(); 00283 } 00284 } 00285 00286 // 00287 // Open handle to the super section object with the specified desired 00288 // access. 00289 // 00290 00291 Status = ObOpenObjectByName (ObjectAttributes, 00292 MmSuperSectionObjectType, 00293 PreviousMode, 00294 NULL, 00295 DesiredAccess, 00296 NULL, 00297 &Handle 00298 ); 00299 00300 try { 00301 *SuperSectionHandle = Handle; 00302 } except (EXCEPTION_EXECUTE_HANDLER) { 00303 return Status; 00304 } 00305 00306 return Status; 00307 }


Variable Documentation

GENERIC_MAPPING MiSectionMapping
 

Definition at line 47 of file super.c.

Referenced by MiSectionInitialization(), and MiSuperSectionInitialization().

POBJECT_TYPE MmSuperSectionObjectType
 

Definition at line 41 of file super.c.

Referenced by MiSuperSectionInitialization(), NtCreateSuperSection(), NtMapViewOfSuperSection(), and NtOpenSuperSection().


Generated on Sat May 15 19:45:42 2004 for test by doxygen 1.3.7