Changeset 955f2a5 in mainline
- Timestamp:
- 2011-05-21T11:26:23Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1b3e854
- Parents:
- 0c33b1d5
- Location:
- uspace/lib/c
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/assert.c
r0c33b1d5 r955f2a5 33 33 #include <assert.h> 34 34 #include <stdio.h> 35 #include <io/klog.h> 35 36 #include <stdlib.h> 36 37 #include <stacktrace.h> … … 44 45 } 45 46 47 void assert_static_abort(const char *msg) 48 { 49 klog_write(msg, str_size(msg)); 50 abort(); 51 } 52 46 53 /** @} 47 54 */ -
uspace/lib/c/generic/malloc.c
r0c33b1d5 r955f2a5 119 119 (((uintptr_t) (head)) + (head)->size - sizeof(heap_block_foot_t))) 120 120 121 #define malloc_assert(expr) \122 do { \123 if (!(expr)) {\124 futex_up(&malloc_futex); \125 assert((expr)); \126 } \127 } while (0)128 129 130 121 /** Heap area. 131 122 * … … 237 228 heap_block_head_t *head = (heap_block_head_t *) addr; 238 229 239 malloc_assert(head->magic == HEAP_BLOCK_HEAD_MAGIC);230 assert_static(head->magic == HEAP_BLOCK_HEAD_MAGIC); 240 231 241 232 heap_block_foot_t *foot = BLOCK_FOOT(head); 242 233 243 malloc_assert(foot->magic == HEAP_BLOCK_FOOT_MAGIC);244 malloc_assert(head->size == foot->size);234 assert_static(foot->magic == HEAP_BLOCK_FOOT_MAGIC); 235 assert_static(head->size == foot->size); 245 236 } 246 237 … … 256 247 heap_area_t *area = (heap_area_t *) addr; 257 248 258 malloc_assert(area->magic == HEAP_AREA_MAGIC);259 malloc_assert(addr == area->start);260 malloc_assert(area->start < area->end);261 malloc_assert(((uintptr_t) area->start % PAGE_SIZE) == 0);262 malloc_assert(((uintptr_t) area->end % PAGE_SIZE) == 0);249 assert_static(area->magic == HEAP_AREA_MAGIC); 250 assert_static(addr == area->start); 251 assert_static(area->start < area->end); 252 assert_static(((uintptr_t) area->start % PAGE_SIZE) == 0); 253 assert_static(((uintptr_t) area->end % PAGE_SIZE) == 0); 263 254 } 264 255 … … 391 382 392 383 block_check((void *) last_head); 393 malloc_assert(last_head->area == area);384 assert_static(last_head->area == area); 394 385 395 386 if (last_head->free) { … … 404 395 405 396 block_check((void *) first_head); 406 malloc_assert(first_head->area == area);397 assert_static(first_head->area == area); 407 398 408 399 size_t shrink_size = ALIGN_DOWN(last_head->size, PAGE_SIZE); … … 506 497 static void split_mark(heap_block_head_t *cur, const size_t size) 507 498 { 508 malloc_assert(cur->size >= size);499 assert_static(cur->size >= size); 509 500 510 501 /* See if we should split the block. */ … … 542 533 { 543 534 area_check((void *) area); 544 malloc_assert((void *) first_block >= (void *) AREA_FIRST_BLOCK_HEAD(area));545 malloc_assert((void *) first_block < area->end);535 assert_static((void *) first_block >= (void *) AREA_FIRST_BLOCK_HEAD(area)); 536 assert_static((void *) first_block < area->end); 546 537 547 538 for (heap_block_head_t *cur = first_block; (void *) cur < area->end; … … 670 661 static void *malloc_internal(const size_t size, const size_t align) 671 662 { 672 malloc_assert(first_heap_area != NULL);663 assert_static(first_heap_area != NULL); 673 664 674 665 if (align == 0) … … 795 786 796 787 block_check(head); 797 malloc_assert(!head->free);788 assert_static(!head->free); 798 789 799 790 heap_area_t *area = head->area; 800 791 801 792 area_check(area); 802 malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));803 malloc_assert((void *) head < area->end);793 assert_static((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area)); 794 assert_static((void *) head < area->end); 804 795 805 796 void *ptr = NULL; … … 872 863 873 864 block_check(head); 874 malloc_assert(!head->free);865 assert_static(!head->free); 875 866 876 867 heap_area_t *area = head->area; 877 868 878 869 area_check(area); 879 malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));880 malloc_assert((void *) head < area->end);870 assert_static((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area)); 871 assert_static((void *) head < area->end); 881 872 882 873 /* Mark the block itself as free. */ -
uspace/lib/c/include/assert.h
r0c33b1d5 r955f2a5 55 55 } while (0) 56 56 57 #define assert_static(expr) \ 58 do { \ 59 if (!(expr)) \ 60 assert_static_abort("Assertion failed (" #expr \ 61 ") in file \"" __FILE__ "\".\n"); \ 62 } while (0) 63 57 64 #else /* NDEBUG */ 58 65 59 66 #define assert(expr) 67 #define assert_static(expr) 60 68 61 69 #endif /* NDEBUG */ … … 63 71 extern void assert_abort(const char *, const char *, unsigned int) 64 72 __attribute__((noreturn)); 73 extern void assert_static_abort(const char *); 74 65 75 66 76 #endif
Note:
See TracChangeset
for help on using the changeset viewer.