ReactOS 0.4.16-dev-197-g92996da
mem.c File Reference
#include <win32k.h>
#include <debug.h>
Include dependency graph for mem.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

_Must_inspect_result_ _When_ (fl &FL_ZERO_MEMORY, _Ret_opt_bytecount_(cjMemSize)) _When_(!(fl &FL_ZERO_MEMORY)
 
_Must_inspect_result_ _Ret_opt_bytecap_ (cjMemSize)
 
VOID APIENTRY EngFreeMem (PVOID pvBaseAddress)
 
_Must_inspect_result_ _Ret_opt_bytecount_ (cjMemSize)
 
VOID APIENTRY EngFreeUserMem (PVOID pvBaseAddress)
 
PVOID APIENTRY HackSecureVirtualMemory (IN PVOID Address, IN SIZE_T Size, IN ULONG ProbeMode, OUT PVOID *SafeAddress)
 
VOID APIENTRY HackUnsecureVirtualMemory (IN PVOID SecureHandle)
 
HANDLE APIENTRY EngSecureMem (PVOID Address, ULONG Length)
 
HANDLE APIENTRY EngSecureMemForRead (PVOID Address, ULONG Length)
 
VOID APIENTRY EngUnsecureMem (HANDLE Mem)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file mem.c.

Function Documentation

◆ _Ret_opt_bytecap_()

_Must_inspect_result_ _Ret_opt_bytecap_ ( cjMemSize  )

Definition at line 19 of file mem.c.

28{
29 PVOID pvBaseAddress;
30
31 pvBaseAddress = ExAllocatePoolWithTag((fl & FL_NONPAGED_MEMORY) ?
34 ulTag);
35
36 if (pvBaseAddress == NULL)
37 return NULL;
38
39 if (fl & FL_ZERO_MEMORY)
40 RtlZeroMemory(pvBaseAddress, cjMemSize);
41
42 return pvBaseAddress;
43}
#define NULL
Definition: types.h:112
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
#define FL_ZERO_MEMORY
Definition: polytest.cpp:58
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ FLONG fl
Definition: winddi.h:1279
_In_ ULONG _In_ ULONG ulTag
Definition: winddi.h:3942
_Must_inspect_result_ _In_ ULONG cjMemSize
Definition: winddi.h:1381
#define FL_NONPAGED_MEMORY
Definition: winddi.h:1359

◆ _Ret_opt_bytecount_()

_Must_inspect_result_ _Ret_opt_bytecount_ ( cjMemSize  )

Definition at line 64 of file mem.c.

72{
73 PVOID pvBaseAddress = NULL;
75
76 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
77 &pvBaseAddress,
78 0,
79 &cjMemSize,
82
83 if (!NT_SUCCESS(Status))
84 {
85 return NULL;
86 }
87
88 /* TODO: Add allocation info to AVL tree (stored inside W32PROCESS structure) */
89 //hSecure = EngSecureMem(pvBaseAddress, cj);
90
91 return pvBaseAddress;
92}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define MEM_RESERVE
Definition: nt_native.h:1314
#define MEM_COMMIT
Definition: nt_native.h:1313

◆ _When_()

_Must_inspect_result_ _When_ ( fl FL_ZERO_MEMORY,
_Ret_opt_bytecount_(cjMemSize  
) &

◆ EngFreeMem()

VOID APIENTRY EngFreeMem ( PVOID  pvBaseAddress)

Definition at line 50 of file mem.c.

51{
52 /* Windows allows to pass NULL */
53 if (pvBaseAddress)
54 {
55 /* Use 0 as tag, which equals a call to ExFreePool */
56 ExFreePoolWithTag(pvBaseAddress, 0);
57 }
58}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109

◆ EngFreeUserMem()

VOID APIENTRY EngFreeUserMem ( PVOID  pvBaseAddress)

Definition at line 99 of file mem.c.

100{
101 SIZE_T cjSize = 0;
102
103 ZwFreeVirtualMemory(NtCurrentProcess(),
104 &pvBaseAddress,
105 &cjSize,
107
108 /* TODO: Remove allocation info from AVL tree */
109}
#define MEM_RELEASE
Definition: nt_native.h:1316
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_In_ ULONG cjSize
Definition: winddi.h:3634

◆ EngSecureMem()

HANDLE APIENTRY EngSecureMem ( PVOID  Address,
ULONG  Length 
)

Definition at line 177 of file mem.c.

178{
179 {// HACK!!!
181 {
183 }
185 {
186 _SEH2_YIELD(return NULL);
187 }
188 _SEH2_END;
189 return (HANDLE)-1;
190 }
192}
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
PVOID NTAPI MmSecureVirtualMemory(IN PVOID Address, IN SIZE_T Length, IN ULONG Mode)
Definition: virtual.c:2794
static WCHAR Address[46]
Definition: ping.c:68
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168

◆ EngSecureMemForRead()

HANDLE APIENTRY EngSecureMemForRead ( PVOID  Address,
ULONG  Length 
)

Definition at line 196 of file mem.c.

197{
198 {// HACK!!!
199 ULONG cPages;
200 volatile BYTE *pjProbe;
201
203 {
207 while(cPages--)
208 {
209 /* Do a read probe */
210 (void)*pjProbe;
211 pjProbe += PAGE_SIZE;
212 }
213 }
215 {
216 _SEH2_YIELD(return NULL);
217 }
218 _SEH2_END;
219 return (HANDLE)-1;
220 }
222}
#define PAGE_READONLY
Definition: compat.h:138
#define PAGE_SIZE
Definition: env_spec_w32.h:49
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
uint32_t ULONG
Definition: typedefs.h:59
#define ALIGN_DOWN_POINTER_BY(ptr, align)
Definition: umtypes.h:82
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
unsigned char BYTE
Definition: xxhash.c:193

◆ EngUnsecureMem()

VOID APIENTRY EngUnsecureMem ( HANDLE  Mem)

Definition at line 228 of file mem.c.

229{
230 if (Mem == (HANDLE)-1) return; // HACK!!!
232}
VOID NTAPI MmUnsecureVirtualMemory(IN PVOID SecureMem)
Definition: virtual.c:2807

◆ HackSecureVirtualMemory()

PVOID APIENTRY HackSecureVirtualMemory ( IN PVOID  Address,
IN SIZE_T  Size,
IN ULONG  ProbeMode,
OUT PVOID SafeAddress 
)

Definition at line 113 of file mem.c.

118{
120 PMDL pmdl;
122
125 else return NULL;
126
128 if (pmdl == NULL)
129 {
130 return NULL;
131 }
132
134 {
136 }
138 {
140 }
142
143 if (!NT_SUCCESS(Status))
144 {
145 IoFreeMdl(pmdl);
146 return NULL;
147 }
148
150
151 if(!*SafeAddress)
152 {
153 MmUnlockPages(pmdl);
154 IoFreeMdl(pmdl);
155 return NULL;
156 }
157
158 return pmdl;
159}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
FP_OP Operation
Definition: fpcontrol.c:150
#define IoFreeMdl
Definition: fxmdl.h:89
#define IoAllocateMdl
Definition: fxmdl.h:88
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1435
@ NormalPagePriority
Definition: imports.h:54
#define UserMode
Definition: asm.h:35
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define STATUS_SUCCESS
Definition: shellext.h:65
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
enum _LOCK_OPERATION LOCK_OPERATION
@ IoReadAccess
Definition: ketypes.h:863
@ IoModifyAccess
Definition: ketypes.h:865
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
_Must_inspect_result_ _In_ _In_ ULONG ProbeMode
Definition: mmfuncs.h:561

◆ HackUnsecureVirtualMemory()

VOID APIENTRY HackUnsecureVirtualMemory ( IN PVOID  SecureHandle)

Definition at line 163 of file mem.c.

165{
166 PMDL pmdl = (PMDL)SecureHandle;
167
168 MmUnlockPages(pmdl);
169 IoFreeMdl(pmdl);
170}
PVOID PMDL
Definition: usb.h:39