12#include "omDerivedConfig.h"
15#include "omDefaultConfig.h"
27#ifndef OM_MIN_SIZEOF_FRONT_PATTERN
28#define OM_MIN_SIZEOF_FRONT_PATTERN (OM_MIN_SIZEWOF_FRONT_PATTERN*SIZEOF_STRICT_ALIGNMENT)
31#ifndef OM_MIN_SIZEOF_BACK_PATTERN
32#define OM_MIN_SIZEOF_BACK_PATTERN (OM_MIN_SIZEWOF_BACK_PATTERN*SIZEOF_STRICT_ALIGNMENT)
36typedef struct omTrackAddr_s omTrackAddr_t;
37typedef omTrackAddr_t * omTrackAddr;
43 #ifdef OM_TRACK_FILE_LINE
45 const char* alloc_file;
47 #ifdef OM_TRACK_RETURN
50 #ifdef OM_TRACK_BACKTRACE
51 #define OM_TRACK_ADDR_MEM_1 alloc_frames
54 char* alloc_frames[OM_MAX_KEPT_FRAMES];
56 #define OM_TRACK_ADDR_MEM_1 bin_size
58 #define OM_TRACK_ADDR_MEM_2 bin_size
62 #ifdef OM_TRACK_CUSTOM
65 #ifdef OM_TRACK_FILE_LINE
66 #define OM_TRACK_ADDR_MEM_3 free_line
70 const char* free_file;
72 #ifdef OM_TRACK_RETURN
73 #ifndef OM_TRACK_ADDR_MEM_3
74 #define OM_TRACK_ADDR_MEM_3 free_r
78 #ifdef OM_TRACK_BACKTRACE
79 #define OM_TRACK_ADDR_MEM_4 free_frames
82 void* free_frames[OM_MAX_KEPT_FRAMES];
89static int omCheckPattern(
char*
s,
char p,
size_t size);
92static struct omTrackAddr_s track_addr;
94#define OM_SIZEOF_TRACK_ADDR_1 OM_STRICT_ALIGN_SIZE(((char*)&track_addr.alloc_frames-(char*)&track_addr))
95#define OM_SIZEOF_TRACK_ADDR_2 OM_STRICT_ALIGN_SIZE(((char*)&track_addr.bin_size-(char*)&track_addr))
96#define OM_SIZEOF_TRACK_ADDR_3 OM_STRICT_ALIGN_SIZE(((char*)&track_addr.free_line-(char*)&track_addr)+OM_MIN_SIZEOF_FRONT_PATTERN)
97#define OM_SIZEOF_TRACK_ADDR_4 OM_STRICT_ALIGN_SIZE(((char*)&track_addr.free_frames-(char*)&track_addr)+OM_MIN_SIZEOF_FRONT_PATTERN)
98#define OM_SIZEOF_TRACK_ADDR_5 OM_STRICT_ALIGN_SIZE(sizeof(struct omTrackAddr_s)+OM_MIN_SIZEOF_FRONT_PATTERN)
101#define OM_SIZEOF_TRACK_ADDR_1 OM_STRICT_ALIGN_SIZE(((char*)&track_addr.OM_TRACK_ADDR_MEM_1-(char*)&track_addr))
102#define OM_SIZEOF_TRACK_ADDR_2 OM_STRICT_ALIGN_SIZE(((char*)&track_addr.OM_TRACK_ADDR_MEM_2-(char*)&track_addr))
103#define OM_SIZEOF_TRACK_ADDR_3 OM_STRICT_ALIGN_SIZE(((char*)&track_addr.OM_TRACK_ADDR_MEM_3-(char*)&track_addr)+OM_MIN_SIZEOF_FRONT_PATTERN)
104#ifdef OM_TRACK_ADDR_MEM_4
105#define OM_SIZEOF_TRACK_ADDR_4 OM_STRICT_ALIGN_SIZE(((char*)&track_addr.OM_TRACK_ADDR_MEM_4-(char*)&track_addr)+OM_MIN_SIZEOF_FRONT_PATTERN)
107#define OM_SIZEOF_TRACK_ADDR_4 OM_SIZEOF_TRACK_ADDR_5
109#define OM_SIZEOF_TRACK_ADDR_5 OM_STRICT_ALIGN_SIZE(sizeof(struct omTrackAddr_s)+OM_MIN_SIZEOF_FRONT_PATTERN)
111#define OM_SIZEOF_TRACK_ADDR(i) \
113 (i == 4 ? OM_SIZEOF_TRACK_ADDR_4 : OM_SIZEOF_TRACK_ADDR_5) : \
114 (i == 3 ? OM_SIZEOF_TRACK_ADDR_3 : (i == 2 ? OM_SIZEOF_TRACK_ADDR_2 : OM_SIZEOF_TRACK_ADDR_1)))
116OM_INLINE_LOCAL omTrackAddr omOutAddr_2_TrackAddr(
void* addr);
118#define _omOutSize_2_TrackAddrSize(size, track) \
119 (size + OM_SIZEOF_TRACK_ADDR(track) + (track > 2 ? OM_MIN_SIZEOF_BACK_PATTERN : 0))
121#define _omTrackAddr_2_SizeOfTrackAddrHeader(d_addr) ((size_t) OM_SIZEOF_TRACK_ADDR(((omTrackAddr) (d_addr))->track))
122#define _omTrackAddr_2_OutSize(d_addr) \
123 (((omTrackAddr) (d_addr))->track > 2 ? \
124 omTrack3Addr_2_OutSize(d_addr) : omSizeOfBinAddr(d_addr) - omTrackAddr_2_SizeOfTrackAddrHeader(d_addr))
125#define _omTrack3Addr_2_OutSize(d_addr) \
126 ((((omTrackAddr) (d_addr))->flags & OM_FBIN) ? \
127 (((omBin)((omTrackAddr) (d_addr))->bin_size)->sizeW) << LOG_SIZEOF_LONG : \
128 ((size_t)((omTrackAddr) (d_addr))->bin_size))
131#define _omTrackAddr_2_FrontPattern(d_addr) \
132 ((void*)((unsigned long)d_addr + omTrackAddr_2_SizeOfTrackAddrHeader(d_addr) - OM_MIN_SIZEOF_FRONT_PATTERN))
133#define _omTrackAddr_2_SizeOfFrontPattern(d_addr) \
134 ((char*) omTrackAddr_2_OutAddr(d_addr) - (char*) omTrackAddr_2_FrontPattern(d_addr))
135#define _omTrackAddr_2_BackPattern(d_addr) \
136 ((char*) ((unsigned long)d_addr + omTrackAddr_2_SizeOfTrackAddrHeader(d_addr) + _omTrack3Addr_2_OutSize(d_addr)))
137#define _omTrackAddr_2_SizeOfBackPattern(d_addr) \
138 ((char*) d_addr + omSizeOfBinAddr(d_addr) - omTrackAddr_2_BackPattern(d_addr))
139#define omTrackAddr_2_OutAddr(d_addr) ((void*)((unsigned long)d_addr + omTrackAddr_2_SizeOfTrackAddrHeader(d_addr)))
142#ifdef OM_INTERNAL_DEBUG
143static size_t omTrackAddr_2_SizeOfTrackAddrHeader(omTrackAddr d_addr)
147 d_addr->track > 0 && d_addr->track <= 5);
148 size = _omTrackAddr_2_SizeOfTrackAddrHeader(d_addr);
151static void* omTrackAddr_2_FrontPattern(omTrackAddr d_addr)
155 d_addr->track > 2 && d_addr->track <= 5);
156 addr = _omTrackAddr_2_FrontPattern(d_addr);
159static size_t omTrackAddr_2_SizeOfFrontPattern(omTrackAddr d_addr)
163 d_addr->track > 2 && d_addr->track <= 5);
164 omAssume((
unsigned long) omTrackAddr_2_OutAddr(d_addr) > (
unsigned long) omTrackAddr_2_FrontPattern(d_addr));
165 size = _omTrackAddr_2_SizeOfFrontPattern(d_addr);
169static char* omTrackAddr_2_BackPattern(omTrackAddr d_addr)
173 d_addr->track > 2 && d_addr->track <= 5);
174 addr = _omTrackAddr_2_BackPattern(d_addr);
175 omAssume(OM_ALIGN_SIZE((
unsigned long) addr) == (
unsigned long) addr);
178static size_t omTrackAddr_2_SizeOfBackPattern(omTrackAddr d_addr)
182 d_addr->track > 2 && d_addr->track <= 5);
183 size = _omTrackAddr_2_SizeOfBackPattern(d_addr);
187static size_t omTrack3Addr_2_OutSize(omTrackAddr d_addr)
191 d_addr->track > 2 && d_addr->track <= 5);
195 size = _omTrack3Addr_2_OutSize(d_addr);
198static size_t omTrackAddr_2_OutSize(omTrackAddr d_addr)
202 d_addr->track > 0 && d_addr->track <= 5);
204 size = _omTrackAddr_2_OutSize(d_addr);
207static size_t omOutSize_2_TrackAddrSize(
size_t size,
char track)
211 da_size = _omOutSize_2_TrackAddrSize(
size, track);
215#define omTrackAddr_2_SizeOfTrackAddrHeader _omTrackAddr_2_SizeOfTrackAddrHeader
216#define omTrackAddr_2_FrontPattern _omTrackAddr_2_FrontPattern
217#define omTrackAddr_2_BackPattern _omTrackAddr_2_BackPattern
218#define omTrack3Addr_2_OutSize _omTrack3Addr_2_OutSize
219#define omTrackAddr_2_OutSize _omTrackAddr_2_OutSize
220#define omOutSize_2_TrackAddrSize _omOutSize_2_TrackAddrSize
221#define omTrackAddr_2_SizeOfFrontPattern _omTrackAddr_2_SizeOfFrontPattern
222#define omTrackAddr_2_SizeOfBackPattern _omTrackAddr_2_SizeOfBackPattern
225OM_INLINE_LOCAL omTrackAddr omOutAddr_2_TrackAddr(
void* addr)
234 d_addr = (omTrackAddr) ((
unsigned long) page + (
unsigned long) ((((
unsigned long)addr - (
unsigned long)page) /
size)*
size));
238size_t omOutSizeOfTrackAddr(
void* addr)
240 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
242 return omTrackAddr_2_OutSize(d_addr);
249 return omTrackAddr_2_OutAddr(omOutAddr_2_TrackAddr(addr));
265static omTrackAddr _omAllocTrackAddr(
size_t d_size)
271 bin = omSmallSize2TrackBin(d_size);
273 bin = omGetSpecTrackBin(d_size);
279 omSetTrackOfUsedBlocks(bin->current_page->used_blocks);
283void* omAllocTrackAddr(
void* bin_size,
288 (bin_size !=
NULL ? OM_ALIGN_SIZE((
size_t) bin_size) : OM_ALIGN_SIZE(1)));
291 if (track <= 0) track = 1;
292 else if (track > 5) track = 5;
297 track = (track > 3 ? track : 3);
298 d_size = omOutSize_2_TrackAddrSize(o_size, track);
300 d_addr = _omAllocTrackAddr(d_size);
301 d_addr->next = (
void*)-1;
302 d_addr->track = track;
307#ifdef OM_TRACK_FILE_LINE
308 d_addr->alloc_file =
f;
309 d_addr->alloc_line = (
l > SHRT_MAX ||
l < 0 ? 0 :
l);
311#ifdef OM_TRACK_RETURN
315 o_addr = omTrackAddr_2_OutAddr(d_addr);
318#ifdef OM_INTERNAL_DEBUG
324#ifdef OM_TRACK_BACKTRACE
325 omGetBackTrace((
void **)d_addr->alloc_frames, FROM_FRAMES, OM_MAX_KEPT_FRAMES);
332 d_addr->bin_size = (
void*)(((
omBin) bin_size)->sizeW<<LOG_SIZEOF_LONG);
333 d_addr->flags &= ~OM_FBIN;
337 d_addr->bin_size = (
flags &
OM_FBIN ? bin_size : (
void*) o_size);
338 omAssume(OM_ALIGN_SIZE((
size_t)d_addr->bin_size) == (
size_t) d_addr->bin_size);
340 memset(omTrackAddr_2_FrontPattern(d_addr), OM_FRONT_PATTERN, omTrackAddr_2_SizeOfFrontPattern(d_addr));
341 if (! (
flags &
OM_FZERO)) memset(o_addr, OM_INIT_PATTERN, o_size);
342 memset(omTrackAddr_2_BackPattern(d_addr), OM_BACK_PATTERN, omTrackAddr_2_SizeOfBackPattern(d_addr));
344#ifdef OM_TRACK_CUSTOM
345 d_addr->custom =
NULL;
349#ifdef OM_TRACK_FILE_LINE
350 d_addr->free_line = -1;
351 d_addr->free_file = (
char*) -1;
353#ifdef OM_TRACK_RETURN
354 d_addr->free_r = (
void*) -1;
357#ifdef OM_TRACK_BACKTRACE
359 memset(&d_addr->free_frames, 0, OM_MAX_KEPT_FRAMES*SIZEOF_VOIDP);
371 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
374 d_addr->next = (
void*) -1;
375 if (d_addr->track > 2)
379 memset(omTrackAddr_2_OutAddr(d_addr), OM_FREE_PATTERN, omTrackAddr_2_OutSize(d_addr));
380 if (d_addr->track > 3)
382#ifdef OM_TRACK_FILE_LINE
383 d_addr->free_line =
l;
384 d_addr->free_file =
f;
386#ifdef OM_TRACK_RETURN
390#ifdef OM_TRACK_BACKTRACE
391 if (d_addr->track > 4)
392 omGetBackTrace(d_addr->free_frames, FROM_FRAMES, OM_MAX_KEPT_FRAMES);
402 d_addr->flags &= ~OM_FUSED;
403 if (keep) d_addr->flags |=
OM_FKEPT;
404 else d_addr->flags &= ~OM_FKEPT;
406 return(
void*) d_addr;
409void omFreeTrackAddr(
void* d_addr)
416 d_addr = omOutAddr_2_TrackAddr(d_addr);
430 omUnsetTrackOfUsedBlocks(page->used_blocks);
432 om_JustFreedPage =
NULL;
436 if (page != om_JustFreedPage)
437 omSetTrackOfUsedBlocks(page->used_blocks);
456 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
464 level, report, OM_FLR_VAL));
465 return omDoCheckTrackAddr(d_addr, addr, bin_size,
flags,
level, report, OM_FLR_VAL);
485 if (d_addr->track > 2)
498 - omTrackAddr_2_SizeOfTrackAddrHeader(d_addr)
499 - OM_MIN_SIZEOF_BACK_PATTERN);
530 if (d_addr->track > 3)
532#ifdef OM_TRACK_FILE_LINE
544#ifdef OM_TRACK_RETURN
546 && (d_addr->free_r != (
void*) -1));
555 size_t size = omTrackAddr_2_OutSize(d_addr);
561 || (
size_t)bin_size > 0))
567 size_t size = omTrackAddr_2_OutSize(d_addr);
582static int omCheckPattern(
char*
s,
char p,
size_t size)
593#ifdef OM_TRACK_BACKTRACE
594#define OM_ALLOC_FRAMES(d_addr) d_addr->alloc_frames
595#define OM_FREE_FRAMES(d_addr) d_addr->free_frames
597#define OM_ALLOC_FRAMES(d) NULL
598#define OM_FREE_FRAMES(d) NULL
601void omPrintTrackAddrInfo(FILE*
fd,
void* addr,
int max_frames)
603 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
605 if (max_frames <= 0)
return;
608 fputs(
" freed\n",
fd);
612 if (max_frames > OM_MAX_KEPT_FRAMES) max_frames = OM_MAX_KEPT_FRAMES;
614 fputs(
" allocated at ",
fd);
616 (d_addr->track > 1 ? max_frames : 0),
618 OM_FLR_ARG(d_addr->alloc_file, d_addr->alloc_line, d_addr->alloc_r)))
620 if (d_addr->track > 1)
622 if (d_addr->track > 3 && ! (d_addr->flags &
OM_FUSED))
624 fputs(
"\n freed at ",
fd);
626 (d_addr->track > 4 ? max_frames : 0),
628 OM_FLR_ARG(d_addr->free_file, d_addr->free_line, d_addr->free_r)))
643 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
649omBin omGetOrigSpecBinOfTrackAddr(
void* addr)
651 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
654 if (d_addr->track > 2 && (d_addr->flags &
OM_FBIN))
666 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
675 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
676 d_addr->flags &= ~OM_FSTATIC;
680static void _omMarkAsStatic(
void* addr)
682 omTrackAddr d_addr = (omTrackAddr) addr;
690static void _omUnMarkAsStatic(
void* addr)
692 omTrackAddr d_addr = (omTrackAddr) addr;
694 d_addr->flags &= ~OM_FSTATIC;
707#ifdef OM_TRACK_CUSTOM
708void omSetCustomOfTrackAddr(
void* addr,
void* value)
710 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
713 if (d_addr->track > 2)
715 d_addr->custom = value;
719void* omGetCustomOfTrackAddr(
void* addr)
721 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
724 if (d_addr->track > 2)
726 return d_addr->custom;
750 addr = omOutAddr_2_TrackAddr(addr);
762 ptr = *((
void**) ptr);
const CanonicalForm int s
if(!FE_OPT_NO_SHELL_FLAG)(void) system(sys)
#define __omFreeBinAddr(addr)
#define SIZEOF_OM_BIN_PAGE_HEADER
#define __omTypeAllocBin(type, addr, bin)
#define omGetTopBinOfPage(page)
#define omSizeOfBinAddr(addr)
#define omGetBinPageOfAddr(addr)
#define omIsBinPageAddr(addr)
#define omGetPageOfAddr(addr)
#define omIsKnownTopBin(bin, normal_bin)
#define omIsStaticNormalBin(bin)
#define omDeleteSpecBin(bin_ptr)
#define omIsStaticTrackBin(bin)
int omIsInKeptAddrList(void *addr)
void * om_AlwaysKeptAddrs
void omUnMarkMemoryAsStatic()
void * omAddr_2_OutAddr(void *addr)
omError_t omCheckPtr(const void *ptr, omError_t report, OM_FLR_DECL)
#define omAddrCheckReturnError(cond, error)
unsigned short omTrackFlags_t
#define omIsStaticTrackAddr(addr)
#define omIsTrackAddr(addr)
#define omAddrCheckReturnCorrupted(cond)
void omIterateTroughAddrs(int normal, int track, void(*CallBackUsed)(void *), void(*CallBackFree)(void *))
void omUnMarkAsStaticAddr(void *addr)
omError_t omDoCheckBinAddr(void *addr, void *bin_size, omTrackFlags_t flags, char level, omError_t report, OM_FLR_DECL)
#define omCheckReturn(cond)
@ omError_FreedAddrOrMemoryCorrupted
@ omError_FalseAddrOrMemoryCorrupted
#define omGetBackTrace(bt, s, max)
#define omMemsetW(P1, W, L)
int _omPrintBackTrace(void **bt, int max, FILE *fd, OM_FLR_DECL)
#define OM_MAX_BLOCK_SIZE
int status int void size_t count int const void size_t count const char int flags
#define omMarkAsStaticAddr(A)
#define omMarkMemoryAsStatic()