 Timestamp:
 Sep 16, 2009, 10:14:11 PM (10 years ago)
 Branches:
 4.10, 4.11, master
 Children:
 ee3b1c13
 Parents:
 e0b66438
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpukit/score/src/heapwalk.c
re0b66438 r8a2944ab 29 29 #include <rtems/bspIo.h> 30 30 31 static void _Heap_Walk_printk( int source, bool dump, bool error, const char *fmt, ... ) 32 { 33 if ( dump ) { 34 va_list ap; 35 36 if ( error ) { 37 printk( "FAIL[%d]: ", source ); 38 } else { 39 printk( "PASS[%d]: ", source ); 40 } 41 42 va_start( ap, fmt ); 43 vprintk( fmt, ap ); 44 va_end( ap ); 45 } 31 typedef (*Heap_Walk_printer)(int, bool, const char*, ...); 32 33 static void _Heap_Walk_print_nothing( 34 int source, 35 bool error, 36 const char *fmt, 37 ... 38 ) 39 { 40 /* Do nothing */ 41 } 42 43 static void _Heap_Walk_print( int source, bool error, const char *fmt, ... ) 44 { 45 va_list ap; 46 47 if ( error ) { 48 printk( "FAIL[%d]: ", source ); 49 } else { 50 printk( "PASS[%d]: ", source ); 51 } 52 53 va_start( ap, fmt ); 54 vprintk( fmt, ap ); 55 va_end( ap ); 46 56 } 47 57 48 58 static bool _Heap_Walk_check_free_list( 49 59 int source, 50 bool dump,60 Heap_Walk_printer printer, 51 61 Heap_Control *heap 52 62 ) … … 60 70 while ( free_block != free_list_tail ) { 61 71 if ( !_Heap_Is_block_in_heap( heap, free_block ) ) { 62 _Heap_Walk_printk( 63 source, 64 dump, 72 (*printer)( 73 source, 65 74 true, 66 75 "free block 0x%08x: not in heap\n", … … 74 83 !_Heap_Is_aligned( _Heap_Alloc_area_of_block( free_block ), page_size ) 75 84 ) { 76 _Heap_Walk_printk( 77 source, 78 dump, 85 (*printer)( 86 source, 79 87 true, 80 88 "free block 0x%08x: alloc area not page aligned\n", … … 86 94 87 95 if ( _Heap_Is_used( free_block ) ) { 88 _Heap_Walk_printk( 89 source, 90 dump, 96 (*printer)( 97 source, 91 98 true, 92 99 "free block 0x%08x: is used\n", … … 98 105 99 106 if ( free_block>prev != prev_block ) { 100 _Heap_Walk_printk( 101 source, 102 dump, 107 (*printer)( 108 source, 103 109 true, 104 110 "free block 0x%08x: invalid previous block 0x%08x\n", … … 137 143 static bool _Heap_Walk_check_control( 138 144 int source, 139 bool dump,145 Heap_Walk_printer printer, 140 146 Heap_Control *heap 141 147 ) … … 148 154 Heap_Block *const last_block = heap>last_block; 149 155 150 _Heap_Walk_printk(156 (*printer)( 151 157 source, 152 dump,153 158 false, 154 159 "page size %u, min block size %u\n" … … 163 168 164 169 if ( page_size == 0 ) { 165 _Heap_Walk_printk( source, dump, true, "page size is zero\n" );170 (*printer)( source, true, "page size is zero\n" ); 166 171 167 172 return false; … … 169 174 170 175 if ( !_Addresses_Is_aligned( (void *) page_size ) ) { 171 _Heap_Walk_printk( 172 source, 173 dump, 176 (*printer)( 177 source, 174 178 true, 175 179 "page size %u not CPU aligned\n", … … 181 185 182 186 if ( !_Heap_Is_aligned( min_block_size, page_size ) ) { 183 _Heap_Walk_printk( 184 source, 185 dump, 187 (*printer)( 188 source, 186 189 true, 187 190 "min block size %u not page aligned\n", … … 195 198 !_Heap_Is_aligned( _Heap_Alloc_area_of_block( first_block ), page_size ) 196 199 ) { 197 _Heap_Walk_printk( 198 source, 199 dump, 200 (*printer)( 201 source, 200 202 true, 201 203 "first block 0x%08x: alloc area not page aligned\n", … … 207 209 208 210 if ( !_Heap_Is_prev_used( first_block ) ) { 209 _Heap_Walk_printk( 210 source, 211 dump, 211 (*printer)( 212 source, 212 213 true, 213 214 "first block: HEAP_PREV_BLOCK_USED is cleared\n" … … 218 219 219 220 if ( first_block>prev_size != page_size ) { 220 _Heap_Walk_printk( 221 source, 222 dump, 221 (*printer)( 222 source, 223 223 true, 224 224 "first block: prev size %u != page size %u\n", … … 231 231 232 232 if ( _Heap_Is_free( last_block ) ) { 233 _Heap_Walk_printk( 234 source, 235 dump, 233 (*printer)( 234 source, 236 235 true, 237 236 "last block: is free\n" … … 241 240 } 242 241 243 return _Heap_Walk_check_free_list( source, dump, heap );242 return _Heap_Walk_check_free_list( source, printer, heap ); 244 243 } 245 244 246 245 static bool _Heap_Walk_check_free_block( 247 246 int source, 248 bool dump,247 Heap_Walk_printer printer, 249 248 Heap_Control *heap, 250 249 Heap_Block *block … … 259 258 Heap_Block *const next_block = _Heap_Block_at( block, block_size ); 260 259 261 _Heap_Walk_printk(260 (*printer)( 262 261 source, 263 dump,264 262 false, 265 263 "block 0x%08x: prev 0x%08x%s, next 0x%08x%s\n", … … 276 274 277 275 if ( block_size != next_block>prev_size ) { 278 _Heap_Walk_printk( 279 source, 280 dump, 276 (*printer)( 277 source, 281 278 true, 282 279 "block 0x%08x: size %u != size %u (in next block 0x%08x)\n", … … 291 288 292 289 if ( !prev_used ) { 293 _Heap_Walk_printk( 294 source, 295 dump, 290 (*printer)( 291 source, 296 292 true, 297 293 "block 0x%08x: two consecutive blocks are free\n", … … 303 299 304 300 if ( !_Heap_Walk_is_in_free_list( heap, block ) ) { 305 _Heap_Walk_printk( 306 source, 307 dump, 301 (*printer)( 302 source, 308 303 true, 309 304 "block 0x%08x: free block not in free list\n", … … 327 322 Heap_Block *const last_block = heap>last_block; 328 323 Heap_Block *block = heap>first_block; 324 Heap_Walk_printer printer = dump ? 325 _Heap_Walk_print : _Heap_Walk_print_nothing; 329 326 330 327 if ( !_System_state_Is_up( _System_state_Get() ) ) { … … 332 329 } 333 330 334 if ( !_Heap_Walk_check_control( source, dump, heap ) ) {331 if ( !_Heap_Walk_check_control( source, printer, heap ) ) { 335 332 return false; 336 333 } … … 344 341 345 342 if ( prev_used ) { 346 _Heap_Walk_printk( 347 source, 348 dump, 343 (*printer)( 344 source, 349 345 false, 350 346 "block 0x%08x: size %u\n", … … 353 349 ); 354 350 } else { 355 _Heap_Walk_printk( 356 source, 357 dump, 351 (*printer)( 352 source, 358 353 false, 359 354 "block 0x%08x: size %u, prev_size %u\n", … … 365 360 366 361 if ( !_Heap_Is_block_in_heap( heap, next_block ) ) { 367 _Heap_Walk_printk( 368 source, 369 dump, 362 (*printer)( 363 source, 370 364 true, 371 365 "block 0x%08x: next block 0x%08x not in heap\n", … … 378 372 379 373 if ( !_Heap_Is_aligned( block_size, page_size ) ) { 380 _Heap_Walk_printk( 381 source, 382 dump, 374 (*printer)( 375 source, 383 376 true, 384 377 "block 0x%08x: block size %u not page aligned\n", … … 391 384 392 385 if ( block_size < min_block_size ) { 393 _Heap_Walk_printk( 394 source, 395 dump, 386 (*printer)( 387 source, 396 388 true, 397 389 "block 0x%08x: size %u < min block size %u\n", … … 405 397 406 398 if ( next_block_begin <= block_begin ) { 407 _Heap_Walk_printk( 408 source, 409 dump, 399 (*printer)( 400 source, 410 401 true, 411 402 "block 0x%08x: next block 0x%08x is not a successor\n", … … 418 409 419 410 if ( !_Heap_Is_prev_used( next_block ) ) { 420 if ( !_Heap_Walk_check_free_block( source, dump, heap, block ) ) {411 if ( !_Heap_Walk_check_free_block( source, printer, heap, block ) ) { 421 412 return false; 422 413 }
Note: See TracChangeset
for help on using the changeset viewer.