My Project
Loading...
Searching...
No Matches
omDebugTrack.c
Go to the documentation of this file.
1/*******************************************************************
2 * File: omDebug.c
3 * Purpose: implementation of main omDebug functions
4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann)
5 * Created: 11/99
6 *******************************************************************/
7#include <limits.h>
8#include <string.h>
9#include "omConfig.h"
10
11#ifdef HAVE_OMALLOC
12#include "omDerivedConfig.h"
13
14#ifdef OM_HAVE_TRACK
15#include "omDefaultConfig.h"
16#include "omalloc.h"
17
18/*******************************************************************
19 *
20 * Declarations
21 *
22 *******************************************************************/
23omBinPage om_JustFreedPage = NULL;
24omSpecBin om_SpecTrackBin = NULL;
25
26/* number of bytes for padding before addr: needs to > 0 and a multiple of OM_SIZEOF_STRICT_ALIGNMENT */
27#ifndef OM_MIN_SIZEOF_FRONT_PATTERN
28#define OM_MIN_SIZEOF_FRONT_PATTERN (OM_MIN_SIZEWOF_FRONT_PATTERN*SIZEOF_STRICT_ALIGNMENT)
29#endif
30/* number of bytes for padding after addr: needs to be a multiple of OM_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)
33#endif
34
35struct omTrackAddr_s;
36typedef struct omTrackAddr_s omTrackAddr_t;
37typedef omTrackAddr_t * omTrackAddr;
38struct omTrackAddr_s
39{
40 void* next; /* reserved for page->current queue */
41 char track; /* > 0; determines size of header */
43 #ifdef OM_TRACK_FILE_LINE
44 short alloc_line;
45 const char* alloc_file;
46 #endif
47 #ifdef OM_TRACK_RETURN
48 const char* alloc_r;
49 #endif
50 #ifdef OM_TRACK_BACKTRACE
51 #define OM_TRACK_ADDR_MEM_1 alloc_frames
52
53 /* track > 1 */
54 char* alloc_frames[OM_MAX_KEPT_FRAMES];
55 #else
56 #define OM_TRACK_ADDR_MEM_1 bin_size
57 #endif
58 #define OM_TRACK_ADDR_MEM_2 bin_size
59
60 /* track > 2 */
61 void* bin_size;
62 #ifdef OM_TRACK_CUSTOM
63 void* custom;
64 #endif
65 #ifdef OM_TRACK_FILE_LINE
66 #define OM_TRACK_ADDR_MEM_3 free_line
67
68 /* track > 3 */
69 short free_line;
70 const char* free_file;
71 #endif
72 #ifdef OM_TRACK_RETURN
73 #ifndef OM_TRACK_ADDR_MEM_3
74 #define OM_TRACK_ADDR_MEM_3 free_r
75 #endif
76 const void* free_r;
77 #endif
78 #ifdef OM_TRACK_BACKTRACE
79 #define OM_TRACK_ADDR_MEM_4 free_frames
80
81 /* track > 4 */
82 void* free_frames[OM_MAX_KEPT_FRAMES];
83 #endif
84};
85
86static omError_t omDoCheckTrackAddr(omTrackAddr d_addr, void* addr, void* bin_size, omTrackFlags_t flags, char level,
87 omError_t report_error, OM_FLR_DECL);
88static int omCheckFlags(omTrackFlags_t flag);
89static int omCheckPattern(char* s, char p, size_t size);
90
91#define OM_TRACK_MAX 5
92static struct omTrackAddr_s track_addr; /* this is only needed to determine OM_SIZEOF_TRACK_ADDR(i) */
93#if 0
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)
99#endif
100
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)
106#else
107#define OM_SIZEOF_TRACK_ADDR_4 OM_SIZEOF_TRACK_ADDR_5
108#endif
109#define OM_SIZEOF_TRACK_ADDR_5 OM_STRICT_ALIGN_SIZE(sizeof(struct omTrackAddr_s)+OM_MIN_SIZEOF_FRONT_PATTERN)
110
111#define OM_SIZEOF_TRACK_ADDR(i) \
112(i > 3 ? \
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)))
115
116OM_INLINE_LOCAL omTrackAddr omOutAddr_2_TrackAddr(void* addr);
117
118#define _omOutSize_2_TrackAddrSize(size, track) \
119 (size + OM_SIZEOF_TRACK_ADDR(track) + (track > 2 ? OM_MIN_SIZEOF_BACK_PATTERN : 0))
120
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))
129
130/* assume track > 2 */
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)))
140
141
142#ifdef OM_INTERNAL_DEBUG
143static size_t omTrackAddr_2_SizeOfTrackAddrHeader(omTrackAddr d_addr)
144{
145 size_t size;
146 omAssume(omIsTrackAddr(d_addr) && omOutAddr_2_TrackAddr(d_addr) == d_addr &&
147 d_addr->track > 0 && d_addr->track <= 5);
148 size = _omTrackAddr_2_SizeOfTrackAddrHeader(d_addr);
149 return size;
150}
151static void* omTrackAddr_2_FrontPattern(omTrackAddr d_addr)
152{
153 void* addr;
154 omAssume(omIsTrackAddr(d_addr) && omOutAddr_2_TrackAddr(d_addr) == d_addr &&
155 d_addr->track > 2 && d_addr->track <= 5);
156 addr = _omTrackAddr_2_FrontPattern(d_addr);
157 return addr;
158}
159static size_t omTrackAddr_2_SizeOfFrontPattern(omTrackAddr d_addr)
160{
161 size_t size;
162 omAssume(omIsTrackAddr(d_addr) && omOutAddr_2_TrackAddr(d_addr) == 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);
166 omAssume(size > 0);
167 return size;
168}
169static char* omTrackAddr_2_BackPattern(omTrackAddr d_addr)
170{
171 char* addr;
172 omAssume(omIsTrackAddr(d_addr) && omOutAddr_2_TrackAddr(d_addr) == 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);
176 return addr;
177}
178static size_t omTrackAddr_2_SizeOfBackPattern(omTrackAddr d_addr)
179{
180 size_t size;
181 omAssume(omIsTrackAddr(d_addr) && omOutAddr_2_TrackAddr(d_addr) == d_addr &&
182 d_addr->track > 2 && d_addr->track <= 5);
183 size = _omTrackAddr_2_SizeOfBackPattern(d_addr);
184 omAssume(size > 0 && OM_ALIGN_SIZE(size) == size);
185 return size;
186}
187static size_t omTrack3Addr_2_OutSize(omTrackAddr d_addr)
188{
189 size_t size;
190 omAssume(omIsTrackAddr(d_addr) && omOutAddr_2_TrackAddr(d_addr) == d_addr &&
191 d_addr->track > 2 && d_addr->track <= 5);
192 omAssume(d_addr->flags > 0 && d_addr->flags < OM_FMAX &&
193 ! ((d_addr->flags & OM_FBIN) && (d_addr->flags & OM_FSIZE)));
194
195 size = _omTrack3Addr_2_OutSize(d_addr);
196 return size;
197}
198static size_t omTrackAddr_2_OutSize(omTrackAddr d_addr)
199{
200 size_t size;
201 omAssume(omIsTrackAddr(d_addr) && omOutAddr_2_TrackAddr(d_addr) == d_addr &&
202 d_addr->track > 0 && d_addr->track <= 5);
203
204 size = _omTrackAddr_2_OutSize(d_addr);
205 return size;
206}
207static size_t omOutSize_2_TrackAddrSize(size_t size, char track)
208{
209 size_t da_size;
210 omAssume(track > 0 && track <= 5);
211 da_size = _omOutSize_2_TrackAddrSize(size, track);
212 return da_size;
213}
214#else
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
223#endif
224
225OM_INLINE_LOCAL omTrackAddr omOutAddr_2_TrackAddr(void* addr)
226{
227 omTrackAddr d_addr;
228 char* page = omGetPageOfAddr(addr);
229 size_t size = omGetTopBinOfPage((omBinPage) page)->sizeW << LOG_SIZEOF_LONG;
230
232
234 d_addr = (omTrackAddr) ((unsigned long) page + (unsigned long) ((((unsigned long)addr - (unsigned long)page) / size)*size));
235 return d_addr;
236}
237
238size_t omOutSizeOfTrackAddr(void* addr)
239{
240 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
241 omAssume(omIsTrackAddr(addr));
242 return omTrackAddr_2_OutSize(d_addr);
243}
244
245void* omAddr_2_OutAddr(void* addr)
246{
247 if (omIsTrackAddr(addr))
248 {
249 return omTrackAddr_2_OutAddr(omOutAddr_2_TrackAddr(addr));
250 }
251 else
252 {
253 return addr;
254 }
255}
256
257/*******************************************************************
258 *
259 * Low level allocation/free routines: do the actual work,
260 * no checks/tests, assume that everything in
261 * environment is ok
262 *
263 *******************************************************************/
264
265static omTrackAddr _omAllocTrackAddr(size_t d_size)
266{
267 omTrackAddr d_addr;
268 omBin bin;
269
270 if (d_size <= OM_MAX_BLOCK_SIZE)
271 bin = omSmallSize2TrackBin(d_size);
272 else
273 bin = omGetSpecTrackBin(d_size);
274
275 __omTypeAllocBin(omTrackAddr, d_addr, bin);
276
277 omAssume(bin->current_page == omGetPageOfAddr(d_addr));
278
279 omSetTrackOfUsedBlocks(bin->current_page->used_blocks);
280
281 return d_addr;
282}
283void* omAllocTrackAddr(void* bin_size,
284 omTrackFlags_t flags, char track, OM_FLR_DECL)
285{
286 void* o_addr;
287 size_t o_size = (flags & OM_FBIN ? ((omBin)bin_size)->sizeW << LOG_SIZEOF_LONG :
288 (bin_size != NULL ? OM_ALIGN_SIZE((size_t) bin_size) : OM_ALIGN_SIZE(1)));
289 omTrackAddr d_addr;
290 size_t d_size;
291 if (track <= 0) track = 1;
292 else if (track > 5) track = 5;
293
294 if ((flags & OM_FBIN) && !omIsStaticNormalBin((omBin)bin_size))
295 /* Need to set track >= 3 such that bin_size is kept: Needed
296 for om_KeptAddr */
297 track = (track > 3 ? track : 3);
298 d_size = omOutSize_2_TrackAddrSize(o_size, track);
299
300 d_addr = _omAllocTrackAddr(d_size);
301 d_addr->next = (void*)-1;
302 d_addr->track = track;
303 d_addr->flags = flags | OM_FUSED;
304 if (om_Opts.MarkAsStatic)
305 d_addr->flags |= OM_FSTATIC;
306
307#ifdef OM_TRACK_FILE_LINE
308 d_addr->alloc_file = f;
309 d_addr->alloc_line = (l > SHRT_MAX || l < 0 ? 0 : l);
310#endif
311#ifdef OM_TRACK_RETURN
312 d_addr->alloc_r = r;
313#endif
314
315 o_addr = omTrackAddr_2_OutAddr(d_addr);
316 if (track > 1)
317 {
318#ifdef OM_INTERNAL_DEBUG
319#define FROM_FRAMES 0
320#else
321#define FROM_FRAMES 2
322#endif
323
324#ifdef OM_TRACK_BACKTRACE
325 omGetBackTrace((void **)d_addr->alloc_frames, FROM_FRAMES, OM_MAX_KEPT_FRAMES);
326#endif
327
328 if (track > 2)
329 {
330 if (flags & OM_FBIN && ((omBin) bin_size)->sticky)
331 {
332 d_addr->bin_size = (void*)(((omBin) bin_size)->sizeW<<LOG_SIZEOF_LONG);
333 d_addr->flags &= ~OM_FBIN;
334 d_addr->flags |= OM_FSIZE;
335 }
336 else
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);
339
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));
343
344#ifdef OM_TRACK_CUSTOM
345 d_addr->custom = NULL;
346#endif
347 if (track > 3)
348 {
349#ifdef OM_TRACK_FILE_LINE
350 d_addr->free_line = -1;
351 d_addr->free_file = (char*) -1;
352#endif
353#ifdef OM_TRACK_RETURN
354 d_addr->free_r = (void*) -1;
355#endif
356
357#ifdef OM_TRACK_BACKTRACE
358 if (track > 4)
359 memset(&d_addr->free_frames, 0, OM_MAX_KEPT_FRAMES*SIZEOF_VOIDP);
360#endif
361 }
362 }
363 }
364 if (flags & OM_FZERO) omMemsetW(o_addr, 0, o_size >> LOG_SIZEOF_LONG);
365 return o_addr;
366}
367
368
369void* omMarkAsFreeTrackAddr(void* addr, int keep, omTrackFlags_t *flags, OM_FLR_DECL)
370{
371 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
372 omAssume(omIsTrackAddr(addr));
373
374 d_addr->next = (void*) -1;
375 if (d_addr->track > 2)
376 {
377 if (d_addr->flags & OM_FUSED)
378 {
379 memset(omTrackAddr_2_OutAddr(d_addr), OM_FREE_PATTERN, omTrackAddr_2_OutSize(d_addr));
380 if (d_addr->track > 3)
381 {
382#ifdef OM_TRACK_FILE_LINE
383 d_addr->free_line = l;
384 d_addr->free_file = f;
385#endif
386#ifdef OM_TRACK_RETURN
387 d_addr->free_r = r;
388#endif
389
390#ifdef OM_TRACK_BACKTRACE
391 if (d_addr->track > 4)
392 omGetBackTrace(d_addr->free_frames, FROM_FRAMES, OM_MAX_KEPT_FRAMES);
393#endif
394 }
395 }
396 else
397 {
398 omAssume(d_addr->flags & OM_FKEPT);
399 }
400 }
401 if (d_addr->flags & OM_FKEEP) *flags |= OM_FKEEP;
402 d_addr->flags &= ~OM_FUSED;
403 if (keep) d_addr->flags |= OM_FKEPT;
404 else d_addr->flags &= ~OM_FKEPT;
405
406 return(void*) d_addr;
407}
408
409void omFreeTrackAddr(void* d_addr)
410{
411 omBinPage page;
412 omBin bin;
413
414 omAssume(omIsBinPageAddr(d_addr));
415 omAssume(d_addr != NULL && omIsTrackAddr(d_addr));
416 d_addr = omOutAddr_2_TrackAddr(d_addr);
417
418 page = omGetBinPageOfAddr((void*) d_addr);
419 bin = omGetTopBinOfPage(page);
420 /* Ok, here is how it works:
421 1. we unset the first bit of used_blocks
422 ==> used_blocks >= 0
423 2. we do a normal free
424 3. if page of addr was freed, then om_JustFreedPage
425 is != NULL ==> nothing to be done by us
426 else
427 page is still active ==> reset first bit of used_blocks
428 */
429
430 omUnsetTrackOfUsedBlocks(page->used_blocks);
431
432 om_JustFreedPage = NULL;
433
434 __omFreeBinAddr(d_addr);
435
436 if (page != om_JustFreedPage)
437 omSetTrackOfUsedBlocks(page->used_blocks);
438 else
439 {
440 /* Still need to check wheter we need to get rid of SpecBin */
441 if (bin->last_page == NULL && ! omIsStaticTrackBin(bin))
442 omDeleteSpecBin(&bin);
443 }
444}
445
446/*******************************************************************
447 *
448 * Checking a Track Addr
449 *
450 *
451 *******************************************************************/
452
453omError_t omCheckTrackAddr(void* addr, void* bin_size, omTrackFlags_t flags, char level,
454 omError_t report, OM_FLR_DECL)
455{
456 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
457 omAssume(omIsTrackAddr(addr));
458 omAssume(! omCheckPtr(addr, 0, OM_FLR));
459
460 omAddrCheckReturnCorrupted(d_addr->track < 1 || d_addr->track > OM_TRACK_MAX);
461 omAddrCheckReturnError((flags & OM_FUSED) && omTrackAddr_2_OutAddr(d_addr) != addr, omError_FalseAddrOrMemoryCorrupted);
462
464 level, report, OM_FLR_VAL));
465 return omDoCheckTrackAddr(d_addr, addr, bin_size, flags, level, report, OM_FLR_VAL);
466}
467
468
469static omError_t omDoCheckTrackAddr(omTrackAddr d_addr, void* addr, void* bin_size, omTrackFlags_t flags, char level,
470 omError_t report, OM_FLR_DECL)
471{
472 if (flags & OM_FUSED)
473 omAddrCheckReturnError(d_addr->next != ((void*) -1), omError_FreedAddrOrMemoryCorrupted);
474 else
475 omAddrCheckReturnError(d_addr->next != NULL && omCheckPtr(d_addr->next, omError_MaxError, OM_FLR_VAL),
477 omAddrCheckReturnCorrupted(omCheckFlags(d_addr->flags));
478
481
482 if (flags & OM_FBINADDR && flags & OM_FSIZE)
483 omAddrCheckReturnError(omTrackAddr_2_OutSize(d_addr) != (size_t) bin_size, omError_WrongSize);
484
485 if (d_addr->track > 2)
486 {
487 if (d_addr->flags & OM_FBIN)
488 {
489 omAddrCheckReturnCorrupted(!omIsKnownTopBin((omBin) d_addr->bin_size, 1));
490 }
491 else
492 {
493 omAssume(d_addr->flags & OM_FSIZE);
494
495 omAddrCheckReturnCorrupted(!OM_IS_ALIGNED(d_addr->bin_size));
496 omAddrCheckReturnCorrupted((size_t) d_addr->bin_size >
497 omSizeOfBinAddr(d_addr)
498 - omTrackAddr_2_SizeOfTrackAddrHeader(d_addr)
499 - OM_MIN_SIZEOF_BACK_PATTERN);
500 /* Hmm .. here I'd love to have a stricter bound */
501 omAddrCheckReturnCorrupted((size_t) d_addr->bin_size < SIZEOF_OM_ALIGNMENT);
502 }
503
504 omAddrCheckReturnError((flags & OM_FBINADDR) && !((d_addr->flags & OM_FBIN) || ((size_t) d_addr->bin_size <= OM_MAX_BLOCK_SIZE)), omError_NotBinAddr);
505
506 if (flags & OM_FBIN)
507 {
508 if (d_addr->flags & OM_FBIN)
509 omAddrCheckReturnError(((omBin) d_addr->bin_size)->sizeW != ((omBin) bin_size)->sizeW, omError_WrongBin);
510 else
511 omAddrCheckReturnError((((omBin) bin_size)->sizeW << LOG_SIZEOF_LONG) != OM_ALIGN_SIZE((size_t) d_addr->bin_size), omError_WrongBin);
512 }
513 else if (flags & OM_FSIZE)
514 {
515 if (d_addr->flags & OM_FBIN)
516 {
517 omAddrCheckReturnError((((omBin) d_addr->bin_size)->sizeW << LOG_SIZEOF_LONG) < ((size_t) bin_size), omError_WrongSize);
518 }
519 else
520 {
521 omAddrCheckReturnError((size_t) d_addr->bin_size < (size_t) bin_size, omError_WrongSize);
522 }
523 }
524
525 omAddrCheckReturnError(omCheckPattern(omTrackAddr_2_FrontPattern(d_addr), OM_FRONT_PATTERN,omTrackAddr_2_SizeOfFrontPattern(d_addr)),omError_FrontPattern);
526 omAddrCheckReturnError(omCheckPattern(omTrackAddr_2_BackPattern(d_addr), OM_BACK_PATTERN,omTrackAddr_2_SizeOfBackPattern(d_addr)),omError_BackPattern);
527 if (! (d_addr->flags & OM_FUSED))
528 omAddrCheckReturnError(omCheckPattern(omTrackAddr_2_OutAddr(addr), OM_FREE_PATTERN, omTrackAddr_2_OutSize(d_addr)),omError_FreePattern);
529
530 if (d_addr->track > 3)
531 {
532#ifdef OM_TRACK_FILE_LINE
533 if (d_addr->flags & OM_FUSED)
534 {
535 omAddrCheckReturnCorrupted(d_addr->free_line != -1);
536 omAddrCheckReturnCorrupted(d_addr->free_file != (void*) -1);
537 }
538 else
539 {
540 omAddrCheckReturnCorrupted(d_addr->free_line < 0);
541 omAddrCheckReturnCorrupted(d_addr->free_file == (void*) -1);
542 }
543#endif
544#ifdef OM_TRACK_RETURN
545 omAddrCheckReturnCorrupted((d_addr->flags & OM_FUSED)
546 && (d_addr->free_r != (void*) -1));
547#endif
548 }
549 }
550 else
551 {
552 /* track < 2 */
553 if (flags & OM_FBIN)
554 {
555 size_t size = omTrackAddr_2_OutSize(d_addr);
557 omAddrCheckReturnError(size < (((omBin)bin_size)->sizeW<<LOG_SIZEOF_LONG), omError_WrongBin);
558 }
559 else if (flags & OM_FSIZE
560 && (!(flags & OM_FSLOPPY)
561 || (size_t)bin_size > 0))
562 {
563 omAddrCheckReturnError(omTrackAddr_2_OutSize(d_addr) < (size_t) bin_size, omError_WrongSize);
564 }
565 else if (flags & OM_FBINADDR)
566 {
567 size_t size = omTrackAddr_2_OutSize(d_addr);
569 }
570 }
571 return omError_NoError;
572}
573
574static int omCheckFlags(omTrackFlags_t flag)
575{
576 if (flag > OM_FMAX) return 1;
577 if (! ((flag & OM_FBIN) ^ (flag & OM_FSIZE))) return 1;
578 if (flag & OM_FUSED && flag & OM_FKEPT) return 1;
579 return 0;
580}
581
582static int omCheckPattern(char* s, char p, size_t size)
583{
584 int i;
585 for (i=0; i<size; i++)
586 {
587 if (s[i] != p)
588 return 1;
589 }
590 return 0;
591}
592
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
596#else
597#define OM_ALLOC_FRAMES(d) NULL
598#define OM_FREE_FRAMES(d) NULL
599#endif
600
601void omPrintTrackAddrInfo(FILE* fd, void* addr, int max_frames)
602{
603 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
604 omAssume(d_addr->track > 0);
605 if (max_frames <= 0) return;
606 if (! (d_addr->flags & OM_FUSED))
607 {
608 fputs(" freed\n",fd);
609 return;
610 }
611
612 if (max_frames > OM_MAX_KEPT_FRAMES) max_frames = OM_MAX_KEPT_FRAMES;
613
614 fputs(" allocated at ",fd);
615 if (! _omPrintBackTrace((void **)OM_ALLOC_FRAMES(d_addr),
616 (d_addr->track > 1 ? max_frames : 0),
617 fd,
618 OM_FLR_ARG(d_addr->alloc_file, d_addr->alloc_line, d_addr->alloc_r)))
619 fputs(" ??",fd);
620 if (d_addr->track > 1)
621 {
622 if (d_addr->track > 3 && ! (d_addr->flags & OM_FUSED))
623 {
624 fputs("\n freed at ",fd);
625 if (! _omPrintBackTrace(OM_FREE_FRAMES(d_addr),
626 (d_addr->track > 4 ? max_frames : 0),
627 fd,
628 OM_FLR_ARG(d_addr->free_file, d_addr->free_line, d_addr->free_r)))
629 fputs(" ??",fd);
630 }
631 }
632 fputc('\n',fd);
633 fflush(fd);
634}
635
636/*******************************************************************
637 *
638 * Misc routines for marking, etc.
639 *
640 *******************************************************************/
641int omIsStaticTrackAddr(void* addr)
642{
643 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
644 omAssume(omIsTrackAddr(addr));
645
646 return (d_addr->flags & OM_FSTATIC);
647}
648
649omBin omGetOrigSpecBinOfTrackAddr(void* addr)
650{
651 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
652 omAssume(omIsTrackAddr(addr));
653
654 if (d_addr->track > 2 && (d_addr->flags & OM_FBIN))
655 {
656 omBin bin = (omBin) d_addr->bin_size;
657 if (omIsSpecBin(bin)) return bin;
658 }
659 return NULL;
660}
661
662void omMarkAsStaticAddr(void* addr)
663{
664 if (omIsTrackAddr(addr))
665 {
666 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
667 d_addr->flags |= OM_FSTATIC;
668 }
669}
670
671void omUnMarkAsStaticAddr(void* addr)
672{
673 if (omIsTrackAddr(addr))
674 {
675 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
676 d_addr->flags &= ~OM_FSTATIC;
677 }
678}
679
680static void _omMarkAsStatic(void* addr)
681{
682 omTrackAddr d_addr = (omTrackAddr) addr;
683 if (!omCheckPtr(addr, omError_MaxError, OM_FLR))
684 {
685 omAssume(omIsTrackAddr(addr) && omOutAddr_2_TrackAddr(addr) == d_addr);
686 d_addr->flags |= OM_FSTATIC;
687 }
688}
689
690static void _omUnMarkAsStatic(void* addr)
691{
692 omTrackAddr d_addr = (omTrackAddr) addr;
693 omAssume(omIsTrackAddr(addr) && omOutAddr_2_TrackAddr(addr) == d_addr);
694 d_addr->flags &= ~OM_FSTATIC;
695}
696
698{
699 omIterateTroughAddrs(0, 1, _omUnMarkAsStatic, NULL);
700}
701
703{
704 omIterateTroughAddrs(0, 1, _omMarkAsStatic, NULL);
705}
706
707#ifdef OM_TRACK_CUSTOM
708void omSetCustomOfTrackAddr(void* addr, void* value)
709{
710 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
711 omAssume(omIsTrackAddr(addr));
712
713 if (d_addr->track > 2)
714 {
715 d_addr->custom = value;
716 }
717}
718
719void* omGetCustomOfTrackAddr(void* addr)
720{
721 omTrackAddr d_addr = omOutAddr_2_TrackAddr(addr);
722 omAssume(omIsTrackAddr(addr));
723
724 if (d_addr->track > 2)
725 {
726 return d_addr->custom;
727 }
728 else
729 {
730 return NULL;
731 }
732}
733#endif
734
735#endif /* OM_HAVE_TRACK */
736
737#ifndef OM_NDEBUG
738
739#ifndef OM_HAVE_TRACK
740#include "omalloc.h"
741#endif
742
743int omIsInKeptAddrList(void* addr)
744{
745 void* ptr = om_KeptAddr;
746 int ret = 0;
747
748#ifdef OM_HAVE_TRACK
749 if (omIsTrackAddr(addr))
750 addr = omOutAddr_2_TrackAddr(addr);
751#endif
752
753 if (om_LastKeptAddr != NULL)
755
756 while (ptr != NULL)
757 {
758 if (ptr == addr)
759 {
760 ret = 1; break;
761 }
762 ptr = *((void**) ptr);
763 }
764
765 if (om_LastKeptAddr != NULL)
766 *((void**) om_LastKeptAddr) = NULL;
767
768 return ret;
769}
770#endif /*!OM_NDEBUG*/
771#endif
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
int level(const CanonicalForm &f)
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
FILE * f
Definition: checklibs.c:9
const CanonicalForm int s
Definition: facAbsFact.cc:51
if(!FE_OPT_NO_SHELL_FLAG)(void) system(sys)
ListNode * next
Definition: janet.h:31
#define __omFreeBinAddr(addr)
#define SIZEOF_OM_BIN_PAGE_HEADER
#define __omTypeAllocBin(type, addr, bin)
#define omGetTopBinOfPage(page)
#define omSizeOfBinAddr(addr)
#define omGetBinPageOfAddr(addr)
Definition: omBinPage.h:22
#define omIsBinPageAddr(addr)
Definition: omBinPage.h:68
#define omGetPageOfAddr(addr)
Definition: omBinPage.h:19
#define omIsKnownTopBin(bin, normal_bin)
Definition: omBin.h:55
#define omIsSpecBin(bin)
Definition: omBin.h:47
#define omIsStaticNormalBin(bin)
Definition: omBin.h:43
#define omDeleteSpecBin(bin_ptr)
Definition: omBin.h:15
#define omIsStaticTrackBin(bin)
Definition: omBin.h:56
int omIsInKeptAddrList(void *addr)
Definition: omDebugTrack.c:743
void * om_AlwaysKeptAddrs
Definition: omDebug.c:31
void * om_KeptAddr
Definition: omDebug.c:28
void * om_LastKeptAddr
Definition: omDebug.c:30
#define OM_FBINADDR
Definition: omDebug.h:40
#define OM_FMAX
Definition: omDebug.h:44
void omUnMarkMemoryAsStatic()
#define OM_FSLOPPY
Definition: omDebug.h:39
#define OM_FKEPT
Definition: omDebug.h:35
#define OM_FSTATIC
Definition: omDebug.h:36
#define OM_FZERO
Definition: omDebug.h:37
void * omAddr_2_OutAddr(void *addr)
#define OM_FSIZE
Definition: omDebug.h:33
#define OM_FBIN
Definition: omDebug.h:32
omError_t omCheckPtr(const void *ptr, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:136
#define omAddrCheckReturnError(cond, error)
Definition: omDebug.h:186
unsigned short omTrackFlags_t
Definition: omDebug.h:45
#define omIsStaticTrackAddr(addr)
Definition: omDebug.h:150
#define omIsTrackAddr(addr)
Definition: omDebug.h:12
#define omAddrCheckReturnCorrupted(cond)
Definition: omDebug.h:188
void omIterateTroughAddrs(int normal, int track, void(*CallBackUsed)(void *), void(*CallBackFree)(void *))
Definition: omDebugCheck.c:503
void omUnMarkAsStaticAddr(void *addr)
omError_t omDoCheckBinAddr(void *addr, void *bin_size, omTrackFlags_t flags, char level, omError_t report, OM_FLR_DECL)
Definition: omDebugCheck.c:198
#define OM_FUSED
Definition: omDebug.h:34
#define omCheckReturn(cond)
Definition: omDebug.h:170
#define OM_FKEEP
Definition: omDebug.h:41
#define omAssume(x)
Definition: omError.h:85
@ omError_WrongSize
Definition: omError.h:26
@ omError_BackPattern
Definition: omError.h:38
@ omError_MaxError
Definition: omError.h:42
@ omError_FrontPattern
Definition: omError.h:39
@ omError_FreedAddr
Definition: omError.h:27
@ omError_UnknownBin
Definition: omError.h:30
@ omError_FreedAddrOrMemoryCorrupted
Definition: omError.h:28
@ omError_NotBinAddr
Definition: omError.h:31
@ omError_WrongBin
Definition: omError.h:29
@ omError_NoError
Definition: omError.h:18
@ omError_FreePattern
Definition: omError.h:37
@ omError_FalseAddrOrMemoryCorrupted
Definition: omError.h:25
enum omError_e omError_t
Definition: omError.h:44
#define omGetBackTrace(bt, s, max)
#define NULL
Definition: omList.c:12
#define omMemsetW(P1, W, L)
Definition: omMemOps.h:161
omOpts_t om_Opts
Definition: omOpts.c:13
int _omPrintBackTrace(void **bt, int max, FILE *fd, OM_FLR_DECL)
Definition: omRet2Info.c:200
omBinPage_t * omBinPage
Definition: omStructs.h:16
omBin_t * omBin
Definition: omStructs.h:12
omSpecBin_t * omSpecBin
Definition: omStructs.h:30
#define OM_MAX_BLOCK_SIZE
Definition: omTables.c:31
int status int void size_t count int const void size_t count const char int flags
Definition: si_signals.h:73
int status int fd
Definition: si_signals.h:59
#define omMarkAsStaticAddr(A)
Definition: xalloc.h:245
#define omMarkMemoryAsStatic()
Definition: xalloc.h:234