ReactOS 0.4.16-dev-927-g467dec4
heapwalk.cpp File Reference
#include <corecrt_internal.h>
#include <malloc.h>
Include dependency graph for heapwalk.cpp:

Go to the source code of this file.

Functions

static int __cdecl try_walk (PROCESS_HEAP_ENTRY *const win32_entry) throw ()
 
int __cdecl _heapwalk (_HEAPINFO *const entry)
 

Function Documentation

◆ _heapwalk()

int __cdecl _heapwalk ( _HEAPINFO *const  entry)

Definition at line 46 of file heapwalk.cpp.

47{
48 // Validation section
50
51 PROCESS_HEAP_ENTRY win32_entry = { 0 };
52 win32_entry.wFlags = 0;
53 win32_entry.iRegionIndex = 0;
54 win32_entry.lpData = entry->_pentry;
55
56 // If _pentry is nullptr, then we're just starting the heap walk:
57 if (win32_entry.lpData == nullptr)
58 {
59 if (!HeapWalk(__acrt_heap, &win32_entry))
60 return _HEAPBADBEGIN;
61 }
62 else
63 {
64 if (entry->_useflag == _USEDENTRY)
65 {
66 if (!HeapValidate(__acrt_heap, 0, entry->_pentry))
67 return _HEAPBADNODE;
68
69 win32_entry.wFlags = PROCESS_HEAP_ENTRY_BUSY;
70 }
71
72 int const status = try_walk(&win32_entry);
73 if (status != _HEAPOK)
74 return status;
75 }
76
77 for (;;)
78 {
79 if (win32_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY)
80 {
81 entry->_pentry = static_cast<int*>(win32_entry.lpData);
82 entry->_size = win32_entry.cbData;
83 entry->_useflag = _USEDENTRY;
84 return _HEAPOK;
85 }
86
87 int const status = try_walk(&win32_entry);
88 if (status != _HEAPOK)
89 return status;
90 }
91}
#define EINVAL
Definition: acclib.h:90
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
#define _HEAPOK
Definition: malloc.h:29
#define _HEAPBADBEGIN
Definition: malloc.h:30
#define _HEAPBADNODE
Definition: malloc.h:31
#define _HEAPBADPTR
Definition: malloc.h:33
#define _USEDENTRY
Definition: malloc.h:37
HANDLE __acrt_heap
Definition: heap_handle.cpp:15
BOOL WINAPI HeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem)
Definition: heapmem.c:156
BOOL WINAPI HeapWalk(HANDLE hHeap, LPPROCESS_HEAP_ENTRY lpEntry)
Definition: heapmem.c:291
static int __cdecl try_walk(PROCESS_HEAP_ENTRY *const win32_entry)
Definition: heapwalk.cpp:15
uint32_t entry
Definition: isohybrid.c:63
Definition: winbase.h:1299
WORD wFlags
Definition: winbase.h:1304
PVOID lpData
Definition: winbase.h:1300
BYTE iRegionIndex
Definition: winbase.h:1303
DWORD cbData
Definition: winbase.h:1301
Definition: ps.c:97
#define PROCESS_HEAP_ENTRY_BUSY
Definition: winbase.h:362

◆ try_walk()

static int __cdecl try_walk ( PROCESS_HEAP_ENTRY *const  win32_entry)
throw (
)
static

Definition at line 15 of file heapwalk.cpp.

16{
17 __try
18 {
19 if (HeapWalk(__acrt_heap, win32_entry))
20 return _HEAPOK;
21
23 return _HEAPEND;
24
25 return _HEAPBADNODE;
26 }
28 {
29 return _HEAPBADNODE;
30 }
32}
#define _HEAPEND
Definition: malloc.h:32
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define __try
Definition: pseh2_64.h:188
#define __except
Definition: pseh2_64.h:189
#define __endtry
Definition: pseh2_64.h:191
#define GetExceptionCode()
Definition: exception.h:68
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:337

Referenced by _heapwalk().