6#define REDZONE_LEFT 0x78
7#define REDZONE_RIGHT 0x87
15} alloc_info, *palloc_info;
18static size_t allocated_memory = 0;
19static LIST_ENTRY alloc_list_head = {&alloc_list_head, &alloc_list_head};
22get_base_ptr(
void *
ptr)
28get_ptr_from_base(palloc_info
info)
37 palloc_info
info = (palloc_info)
ptr;
52check_redzone_region(
void *
ptr,
unsigned char sig,
void **newptr)
57 p = (
unsigned char *)
ptr;
84 palloc_info
info = (palloc_info)
ptr;
86 if (!check_redzone_region(
ptr, REDZONE_LEFT, &
ptr))
89 if (!check_redzone_region(
ptr, REDZONE_RIGHT,
NULL))
94calculate_size_with_redzone(
size_t size)
100add_mem_to_list(
void *
ptr)
102 palloc_info
info = (palloc_info)
ptr;
107del_mem_from_list(
void *
ptr)
109 palloc_info
info = (palloc_info)
ptr;
121 while (
entry != &alloc_list_head)
128 if (!check_redzone_region(
ptr, REDZONE_LEFT, &
ptr))
130 DbgPrint(
" !!! Detected buffer underflow !!!\n");
134 if (!check_redzone_region(
ptr, REDZONE_RIGHT,
NULL))
136 DbgPrint(
" !!! Detected buffer overflow !!!\n");
148 newptr =
malloc(calculate_size_with_redzone(
size));
152 allocated_memory +=
size;
153 add_mem_to_list(newptr);
175 prev_size = ((palloc_info)
ptr)->size;
178 del_mem_from_list(
ptr);
182 allocated_memory +=
size - prev_size;
183 add_mem_to_list(newptr);
187 add_mem_to_list(
ptr);
200 allocated_memory -= ((palloc_info)
ptr)->size;
201 del_mem_from_list(
ptr);
225cmd_checkbuffer_dbg(
void *
ptr,
const char *
file,
int line)
239 DbgPrint(
"CMD: Leaking %lu bytes of memory in %lu blocks! Exit code: %d\n", allocated_memory,
allocations,
code);
#define REDZONE_SIZE(Block)
VOID WINAPI ExitProcess(IN UINT uExitCode)
#define list_entry(ptr, type, member)
#define RemoveEntryList(Entry)
#define InsertTailList(ListHead, Entry)
GLdouble GLdouble GLdouble GLdouble q
unsigned __int3264 UINT_PTR
struct _LIST_ENTRY * Flink
#define CONTAINING_RECORD(address, type, field)