ReactOS  0.4.13-dev-92-gf251225
mapping.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _ENGSECTION
 
struct  _FILEVIEW
 
struct  _FONTFILEVIEW
 

Typedefs

typedef struct _ENGSECTION ENGSECTION
 
typedef struct _ENGSECTIONPENGSECTION
 
typedef struct _FILEVIEW FILEVIEW
 
typedef struct _FILEVIEWPFILEVIEW
 
typedef struct _FONTFILEVIEW FONTFILEVIEW
 
typedef struct _FONTFILEVIEWPFONTFILEVIEW
 

Enumerations

enum  { FVF_SYSTEMROOT = 1, FVF_READONLY = 2, FVF_FONTFILE = 4 }
 

Functions

PVOID NTAPI EngMapSectionView (_In_ HANDLE hSection, _In_ SIZE_T cjSize, _In_ ULONG cjOffset, _Out_ PHANDLE phSecure)
 
VOID NTAPI EngUnmapSectionView (_In_ PVOID pvBits, _In_ ULONG cjOffset, _In_ HANDLE hSecure)
 
PVOID NTAPI EngCreateSection (_In_ ULONG fl, _In_ SIZE_T cjSize, _In_ ULONG ulTag)
 
 _Success_ (return!=FALSE) BOOL APIENTRY EngMapSection(_In_ PVOID pvSection
 
_In_ BOOL _In_ HANDLE _When_ (bMap, _Outptr_) PVOID *pvBaseAddress)
 
BOOL APIENTRY EngFreeSectionMem (_In_opt_ PVOID pvSection, _In_opt_ PVOID pvMappedBase)
 
_Check_return_ PFILEVIEW NTAPI EngLoadModuleEx (_In_z_ LPWSTR pwsz, _In_ ULONG cjSizeOfModule, _In_ FLONG fl)
 

Variables

_In_ BOOL bMap
 
_In_ BOOL _In_ HANDLE hProcess
 
_Check_return_ _In_ ULONG fl
 
_Check_return_ _In_ ULONG _In_ SIZE_T cjSize
 
_Check_return_ _In_ ULONG _In_ SIZE_T _In_ ULONG ulTag
 

Typedef Documentation

◆ ENGSECTION

◆ FILEVIEW

◆ FONTFILEVIEW

◆ PENGSECTION

◆ PFILEVIEW

◆ PFONTFILEVIEW

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FVF_SYSTEMROOT 
FVF_READONLY 
FVF_FONTFILE 

Definition at line 36 of file mapping.h.

37 {
38  FVF_SYSTEMROOT = 1,
39  FVF_READONLY = 2,
40  FVF_FONTFILE = 4,
41 };

Function Documentation

◆ _Success_()

_Success_ ( return!  = FALSE)

◆ _When_()

_In_ BOOL _In_ HANDLE _When_ ( bMap  ,
_Outptr_   
)

◆ EngCreateSection()

PVOID NTAPI EngCreateSection ( _In_ ULONG  fl,
_In_ SIZE_T  cjSize,
_In_ ULONG  ulTag 
)

Definition at line 91 of file mapping.c.

95 {
97  PENGSECTION pSection;
98  PVOID pvSectionObject;
99  LARGE_INTEGER liSize;
100 
101  /* Allocate a section object */
102  pSection = EngAllocMem(0, sizeof(ENGSECTION), 'stsU');
103  if (!pSection) return NULL;
104 
105  liSize.QuadPart = cjSize;
106  Status = MmCreateSection(&pvSectionObject,
108  NULL,
109  &liSize,
111  SEC_COMMIT,
112  NULL,
113  NULL);
114  if (!NT_SUCCESS(Status))
115  {
116  DPRINT1("Failed to create a section Status=0x%x\n", Status);
117  EngFreeMem(pSection);
118  return NULL;
119  }
120 
121  /* Set the fields of the section */
122  pSection->ulTag = ulTag;
123  pSection->pvSectionObject = pvSectionObject;
124  pSection->pvMappedBase = NULL;
125  pSection->cjViewSize = cjSize;
126 
127  return pSection;
128 }
#define EngFreeMem
Definition: polytest.cpp:56
LONG NTSTATUS
Definition: precomp.h:26
PVOID pvSectionObject
Definition: mapping.h:4
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define SEC_COMMIT
Definition: mmtypes.h:99
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI MmCreateSection(OUT PVOID *Section, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL, IN PFILE_OBJECT FileObject OPTIONAL)
Definition: section.c:4969
ULONG ulTag
Definition: mapping.h:7
SIZE_T cjViewSize
Definition: mapping.h:6
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
Status
Definition: gdiplustypes.h:24
_In_ ULONG _In_ ULONG ulTag
Definition: winddi.h:3941
#define DPRINT1
Definition: precomp.h:8
_In_ ULONG cjSize
Definition: winddi.h:3634
PVOID pvMappedBase
Definition: mapping.h:5
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304

◆ EngFreeSectionMem()

BOOL APIENTRY EngFreeSectionMem ( _In_opt_ PVOID  pvSection,
_In_opt_ PVOID  pvMappedBase 
)

Definition at line 246 of file mapping.c.

249 {
251  PENGSECTION pSection = pvSection;
252  BOOL bResult = TRUE;
253 
254  /* Did the caller give us a mapping base? */
255  if (pvMappedBase)
256  {
257  Status = MmUnmapViewInSessionSpace(pvMappedBase);
258  if (!NT_SUCCESS(Status))
259  {
260  DPRINT1("MmUnmapViewInSessionSpace failed: 0x%lx\n", Status);
261  bResult = FALSE;
262  }
263  }
264 
265  /* Check if we should free the section as well */
266  if (pSection)
267  {
268  /* Dereference the kernel section */
270 
271  /* Finally free the section memory itself */
272  EngFreeMem(pSection);
273  }
274 
275  return bResult;
276 }
#define TRUE
Definition: types.h:120
#define EngFreeMem
Definition: polytest.cpp:56
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PVOID pvSectionObject
Definition: mapping.h:4
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSTATUS NTAPI MmUnmapViewInSessionSpace(IN PVOID MappedBase)
Definition: section.c:3023
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8

Referenced by _Success_(), SURFACE_AllocSurface(), and SURFACE_vCleanup().

◆ EngLoadModuleEx()

_Check_return_ PFILEVIEW NTAPI EngLoadModuleEx ( _In_z_ LPWSTR  pwsz,
_In_ ULONG  cjSizeOfModule,
_In_ FLONG  fl 
)

Definition at line 329 of file mapping.c.

333 {
334  PFILEVIEW pFileView = NULL;
336  HANDLE hRootDir;
337  UNICODE_STRING ustrFileName;
340  HANDLE hFile;
342  LARGE_INTEGER liSize;
343 
344  if (fl & FVF_FONTFILE)
345  {
346  pFileView = EngAllocMem(0, sizeof(FONTFILEVIEW), 'vffG');
347  }
348  else
349  {
350  pFileView = EngAllocMem(0, sizeof(FILEVIEW), 'liFg');
351  }
352 
353  /* Check for success */
354  if (!pFileView) return NULL;
355 
356  /* Check if the file is relative to system32 */
357  if (fl & FVF_SYSTEMROOT)
358  {
359  hRootDir = ghSystem32Directory;
360  }
361  else
362  {
363  hRootDir = ghRootDirectory;
364  }
365 
366  /* Initialize unicode string and object attributes */
367  RtlInitUnicodeString(&ustrFileName, pwsz);
369  &ustrFileName,
371  hRootDir,
372  NULL);
373 
374  /* Now open the file */
375  Status = ZwCreateFile(&hFile,
378  &IoStatusBlock,
379  NULL,
381  0,
382  FILE_OPEN,
384  NULL,
385  0);
386  if (!NT_SUCCESS(Status))
387  {
388  DPRINT1("Failed to open file, hFile=%p, Status=0x%x\n", hFile, Status);
389  EngFreeMem(pFileView);
390  return NULL;
391  }
392 
393  Status = ZwQueryInformationFile(hFile,
394  &IoStatusBlock,
396  sizeof(FILE_BASIC_INFORMATION),
398  if (NT_SUCCESS(Status))
399  {
400  pFileView->LastWriteTime = FileInformation.LastWriteTime;
401  }
402 
403  /* Create a section from the file */
404  liSize.QuadPart = cjSizeOfModule;
405  Status = MmCreateSection(&pFileView->pSection,
407  NULL,
408  &liSize,
410  SEC_COMMIT,
411  hFile,
412  NULL);
413 
414  /* Close the file handle */
415  ZwClose(hFile);
416 
417  if (!NT_SUCCESS(Status))
418  {
419  DPRINT1("Failed to create a section Status=0x%x\n", Status);
420  EngFreeMem(pFileView);
421  return NULL;
422  }
423 
424 
425  pFileView->pvKView = NULL;
426  pFileView->pvViewFD = NULL;
427  pFileView->cjView = 0;
428 
429  return pFileView;
430 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
LARGE_INTEGER LastWriteTime
Definition: mapping.h:12
HANDLE ghRootDirectory
Definition: mapping.c:15
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define EngFreeMem
Definition: polytest.cpp:56
SIZE_T cjView
Definition: mapping.h:15
LONG NTSTATUS
Definition: precomp.h:26
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define SEC_COMMIT
Definition: mmtypes.h:99
_In_ FLONG fl
Definition: winddi.h:1279
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI MmCreateSection(OUT PVOID *Section, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL, IN PFILE_OBJECT FileObject OPTIONAL)
Definition: section.c:4969
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
PVOID pSection
Definition: mapping.h:16
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
PVOID pvKView
Definition: mapping.h:13
_In_ HANDLE hFile
Definition: mswsock.h:90
HANDLE ghSystem32Directory
Definition: mapping.c:14
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
PVOID pvViewFD
Definition: mapping.h:14
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by _Success_(), EngLoadModule(), and EngLoadModuleForWrite().

◆ EngMapSectionView()

PVOID NTAPI EngMapSectionView ( _In_ HANDLE  hSection,
_In_ SIZE_T  cjSize,
_In_ ULONG  cjOffset,
_Out_ PHANDLE  phSecure 
)

Definition at line 19 of file mapping.c.

24 {
25  LARGE_INTEGER liSectionOffset;
26  PVOID pvBaseAddress;
28 
29  /* Check if the size is ok (for 64 bit) */
30  if (cjSize > ULONG_MAX)
31  {
32  DPRINT1("chSize out of range: 0x%Id\n", cjSize);
33  return NULL;
34  }
35 
36  /* Align the offset at allocation granularity and compensate for the size */
37  liSectionOffset.QuadPart = cjOffset & ~(MM_ALLOCATION_GRANULARITY - 1);
38  cjSize += cjOffset & (MM_ALLOCATION_GRANULARITY - 1);
39 
40  /* Map the section */
41  Status = ZwMapViewOfSection(hSection,
43  &pvBaseAddress,
44  0,
45  cjSize,
46  &liSectionOffset,
47  &cjSize,
48  ViewShare,
49  0,
51  if (!NT_SUCCESS(Status))
52  {
53  DPRINT1("ZwMapViewOfSection failed (0x%lx)\n", Status);
54  return NULL;
55  }
56 
57  /* Secure the section memory */
58  *phSecure = EngSecureMem(pvBaseAddress, (ULONG)cjSize);
59  if (!*phSecure)
60  {
61  ZwUnmapViewOfSection(NtCurrentProcess(), pvBaseAddress);
62  return NULL;
63  }
64 
65  /* Return the address where the requested data starts */
66  return (PUCHAR)pvBaseAddress + (cjOffset & (MM_ALLOCATION_GRANULARITY - 1));
67 }
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG cjSize
Definition: winddi.h:3634
ENGAPI HANDLE APIENTRY EngSecureMem(_In_reads_bytes_(cjLength) PVOID Address, _In_ ULONG cjLength)
_In_ const BITMAPINFO _In_ UINT _In_opt_ HANDLE hSection
Definition: wingdi.h:3217
#define MM_ALLOCATION_GRANULARITY
Definition: mmtypes.h:36
#define ULONG_MAX
Definition: limits.h:44
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304

◆ EngUnmapSectionView()

VOID NTAPI EngUnmapSectionView ( _In_ PVOID  pvBits,
_In_ ULONG  cjOffset,
_In_ HANDLE  hSecure 
)

Definition at line 71 of file mapping.c.

75 {
77 
78  /* Unsecure the memory */
79  EngUnsecureMem(hSecure);
80 
81  /* Calculate the real start of the section view */
82  pvBits = (PUCHAR)pvBits - (cjOffset & (MM_ALLOCATION_GRANULARITY - 1));
83 
84  /* Unmap the section view */
87 }
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define PsGetCurrentProcess
Definition: psfuncs.h:17
NTSTATUS NTAPI MmUnmapViewOfSection(IN PEPROCESS Process, IN PVOID BaseAddress)
Definition: section.c:3051
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
ENGAPI VOID APIENTRY EngUnsecureMem(_In_ HANDLE hSecure)
#define MM_ALLOCATION_GRANULARITY
Definition: mmtypes.h:36

Referenced by SURFACE_vCleanup().

Variable Documentation

◆ bMap

_In_ BOOL bMap

Definition at line 70 of file mapping.h.

Referenced by _Success_().

◆ cjSize

Definition at line 82 of file mapping.h.

◆ fl

Definition at line 82 of file mapping.h.

◆ hProcess

_In_ BOOL _In_ HANDLE hProcess

Definition at line 70 of file mapping.h.

Referenced by _DoDLLInjection(), _Success_(), _tWinMain(), CIconWatcher::AddIconToWatcher(), AllocateUserPhysicalPages(), AssignProcessToJobObject(), BaseCreateStack(), BaseFreeThreadStack(), change_channel_CB(), CheckRemoteDebuggerPresent(), CloseProcessAndVerify_(), CreateRemoteThread(), CsrCreateProcess(), CsrGetProcessLuid(), CsrSbCreateSession(), CsrSetPriorityClass(), CsrSetProcessSecurity(), DebugChannels_FillList(), DebugChannels_OnNotify(), DoSetPriority(), doSymEnumSymbols(), doSymSearch(), DumpEnum(), DumpType(), DumpUDT(), EmptyWorkingSet(), enum_channel(), EnumDirTree(), EnumDirTreeW(), EnumerateLoadedModules(), EnumerateLoadedModules64(), EnumerateLoadedModulesW64(), EnumProcessModules(), ExecuteKill(), ExecutePipeline(), FindModule(), FlushInstructionCache(), FreeUserPhysicalPages(), GetExitCodeProcess(), GetGuiResources(), CIconWatcher::GetListEntry(), GetMappedFileNameA(), GetMappedFileNameW(), GetModuleBaseNameA(), GetModuleBaseNameW(), GetModuleFileNameExA(), GetModuleFileNameExW(), GetModuleInformation(), GetPriorityClass(), GetProcessAffinityMask(), GetProcessHandleCount(), GetProcessImageFileNameA(), GetProcessImageFileNameW(), GetProcessIoCounters(), GetProcessPriorityBoost(), GetProcessTimes(), GetProcessWorkingSetSize(), GetProcessWorkingSetSizeEx(), GetVersionFromProcess(), GetWsChanges(), Ghost_DestroyTarget(), ImageSymToVa(), InitDbgHelp(), InitializeProcessForWsWatch(), IntResolveDesktop(), IsCriticalProcess(), IsWow64Process(), Main(), main(), MiniDumpWriteDump(), NtOpenProcess(), NtUserGetGuiResources(), NtUserWaitForInputIdle(), OpenUserRegistryPathPerProcessId(), PerfDataGetCommandLine(), PerfDataRefresh(), PNP_ReportLogOn(), PrintProcess(), process_find_by_handle(), process_invade_cb(), ProcessKeys(), ProcessList_Update(), ProcessPage_OnEndProcess(), ProcessPage_OnEndProcessTree(), ProcessPageShowContextMenu(), ProcessRunning(), PspCreateProcess(), QueryWorkingSet(), QueryWorkingSetEx(), read_mem(), read_mem64(), ReadProcessMemory(), reg_cb64to32(), RtlpCreateUserStack(), RtlQueryProcessDebugInformation(), SaveProcessHandle(), SetPriorityClass(), SetProcessAffinityMask(), SetProcessPriorityBoost(), SetProcessWorkingSetSize(), SetProcessWorkingSetSizeEx(), StackWalk(), StackWalk64(), START_TEST(), sym_enum(), sym_register_cb(), SymAddSymbol(), SymAddSymbolW(), SymCleanup(), SymEnumerateModules(), SymEnumerateModules64(), SymEnumerateModulesW64(), SymEnumerateSymbols(), SymEnumerateSymbols64(), SymEnumLines(), SymEnumSourceFiles(), SymEnumSourceFilesW(), SymEnumSourceLines(), SymEnumSourceLinesW(), SymEnumSymbols(), SymEnumSymbolsW(), SymEnumTypes(), SymEnumTypesW(), SymFindFileInPath(), SymFindFileInPathW(), SymFromAddr(), SymFromAddrW(), SymFromIndex(), SymFromIndexW(), SymFromName(), SymFunctionTableAccess(), SymFunctionTableAccess64(), SymGetLineFromAddr(), SymGetLineFromAddr64(), SymGetLineFromAddrW64(), SymGetLineFromName(), SymGetLineFromName64(), SymGetLineFromNameW64(), SymGetLineNext(), SymGetLineNext64(), SymGetLinePrev(), SymGetLinePrev64(), SymGetModuleBase(), SymGetModuleBase64(), SymGetModuleInfo(), SymGetModuleInfo64(), SymGetModuleInfoW(), SymGetModuleInfoW64(), SymGetSearchPath(), SymGetSearchPathW(), SymGetSourceFileToken(), SymGetSourceFileTokenW(), SymGetSymFromAddr(), SymGetSymFromAddr64(), SymGetSymFromName(), SymGetSymFromName64(), SymGetSymNext(), SymGetSymNext64(), SymGetSymPrev(), SymGetSymPrev64(), SymGetTypeFromName(), SymGetTypeInfo(), SymInitialize(), SymInitializeW(), SymLoadModule(), SymLoadModule64(), SymLoadModuleEx(), SymLoadModuleExW(), SymRefreshModuleList(), SymRegisterCallback(), SymRegisterCallback64(), SymRegisterCallbackW64(), SymSearch(), SymSearchW(), SymSetContext(), SymSetHomeDirectory(), SymSetHomeDirectoryW(), SymSetScopeFromAddr(), SymSetSearchPath(), SymSetSearchPathW(), SymUnloadModule(), SymUnloadModule64(), TerminateProcess(), test_CreateRemoteThread(), test_NtMapViewOfSection(), test_pack_CREATE_PROCESS_DEBUG_INFO(), test_pack_PROCESS_INFORMATION(), test_QueryInformationJobObject(), test_shell_window(), test_VirtualAllocEx(), TestTerminateProcess(), Toolhelp32ReadProcessMemory(), ModuleData::Update(), UserpCaptureStringParameters(), UserpFormatMessages(), UserpGetClientFileName(), VirtualAllocEx(), VirtualFreeEx(), VirtualProtectEx(), VirtualQueryEx(), WaitForInputIdle(), WaitForSettingsDialog(), WlxAssignShellProtection(), WOWShellExecute(), WriteProcessMemory(), WSPDuplicateSocket(), and wWinMain().

◆ ulTag

Definition at line 82 of file mapping.h.