ReactOS 0.4.15-dev-8127-g6338913
usrheap.h
Go to the documentation of this file.
1#pragma once
2
3typedef struct _WIN32HEAP WIN32HEAP, *PWIN32HEAP;
4
5/*
6typedef struct _W32HEAP_USER_MAPPING
7{
8 struct _W32HEAP_USER_MAPPING* Next;
9 PVOID KernelMapping;
10 PVOID UserMapping;
11 ULONG_PTR Limit;
12 ULONG Count;
13} W32HEAP_USER_MAPPING, *PW32HEAP_USER_MAPPING;
14*/
15
16/* User heap */
19
22 IN OUT PVOID *SystemBase,
24
27
30 OUT PVOID* KernelMapping,
32
33static __inline PVOID
35{
36 /* User heap has no lock, using global user lock instead. */
40 Bytes);
41}
42
43static __inline BOOL
45{
46 /* User heap has no lock, using global user lock instead. */
50 lpMem);
51}
52
53static __inline PVOID
56{
57#if 0
58 /* NOTE: ntoskrnl doesn't export RtlReAllocateHeap... */
61 lpMem,
62 Bytes);
63#else
64 SIZE_T PrevSize;
65 PVOID pNew;
66
67 /* User heap has no lock, using global user lock instead. */
69
70 PrevSize = RtlSizeHeap(GlobalUserHeap,
72 lpMem);
73
74 if (PrevSize == Bytes)
75 return lpMem;
76
79 Bytes);
80 if (pNew != NULL)
81 {
82 if (PrevSize < Bytes)
83 Bytes = PrevSize;
84
85 RtlCopyMemory(pNew,
86 lpMem,
87 Bytes);
88
91 lpMem);
92 }
93
94 return pNew;
95#endif
96}
97
98static __inline PVOID
100{
102
103 /* The first mapping entry is the global user heap mapping */
104 return (PVOID)(((ULONG_PTR)lpMem - (ULONG_PTR)GlobalUserHeap) +
105 (ULONG_PTR)W32Process->HeapMappings.UserMapping);
106}
107
108/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T)
Definition: heap.c:2667
_In_ UINT Bytes
Definition: mmcopy.h:9
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI SIZE_T NTAPI RtlSizeHeap(_In_ PVOID HeapHandle, _In_ ULONG Flags, _In_ PVOID MemoryPointer)
#define HEAP_NO_SERIALIZE
Definition: nt_native.h:1692
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
BOOL FASTCALL UserIsEnteredExclusive(VOID)
Definition: ntuser.c:224
static GENERIC_MAPPING UserMapping
Definition: samrpc.c:48
W32HEAP_USER_MAPPING HeapMappings
Definition: win32.h:290
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
NTSTATUS UnmapGlobalUserHeap(IN PEPROCESS Process)
Definition: usrheap.c:236
static __inline PVOID UserHeapAlloc(SIZE_T Bytes)
Definition: usrheap.h:34
static __inline PVOID UserHeapAddressToUser(PVOID lpMem)
Definition: usrheap.h:99
struct _WIN32HEAP WIN32HEAP
Definition: usrheap.h:3
PWIN32HEAP UserCreateHeap(OUT PVOID *SectionObject, IN OUT PVOID *SystemBase, IN SIZE_T HeapSize)
Definition: usrheap.c:181
NTSTATUS MapGlobalUserHeap(IN PEPROCESS Process, OUT PVOID *KernelMapping, OUT PVOID *UserMapping)
Definition: usrheap.c:266
static __inline BOOL UserHeapFree(PVOID lpMem)
Definition: usrheap.h:44
HANDLE GlobalUserHeap
Definition: usrheap.c:25
static __inline PVOID UserHeapReAlloc(PVOID lpMem, SIZE_T Bytes)
Definition: usrheap.h:54
struct _WIN32HEAP * PWIN32HEAP
Definition: usrheap.h:3
PVOID GlobalUserHeapSection
Definition: usrheap.c:26
SIZE_T WINAPI HeapSize(HANDLE, DWORD, LPCVOID)