Changeset 13f2461 in mainline for uspace/lib/c/generic/malloc.c
- Timestamp:
- 2011-05-21T15:45:48Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9d47440, e06e2716
- Parents:
- faeb7cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/malloc.c
rfaeb7cc r13f2461 188 188 static futex_t malloc_futex = FUTEX_INITIALIZER; 189 189 190 #ifndef NDEBUG 191 192 #define malloc_assert(expr) \ 193 do { \ 194 if (!(expr)) {\ 195 futex_up(&malloc_futex); \ 196 assert_abort(#expr, __FILE__, STR2(__LINE__)); \ 197 } \ 198 } while (0) 199 200 #else /* NDEBUG */ 201 202 #define malloc_assert(expr) 203 204 #endif /* NDEBUG */ 205 190 206 /** Initialize a heap block 191 207 * … … 228 244 heap_block_head_t *head = (heap_block_head_t *) addr; 229 245 230 assert_static(head->magic == HEAP_BLOCK_HEAD_MAGIC);246 malloc_assert(head->magic == HEAP_BLOCK_HEAD_MAGIC); 231 247 232 248 heap_block_foot_t *foot = BLOCK_FOOT(head); 233 249 234 assert_static(foot->magic == HEAP_BLOCK_FOOT_MAGIC);235 assert_static(head->size == foot->size);250 malloc_assert(foot->magic == HEAP_BLOCK_FOOT_MAGIC); 251 malloc_assert(head->size == foot->size); 236 252 } 237 253 … … 247 263 heap_area_t *area = (heap_area_t *) addr; 248 264 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);265 malloc_assert(area->magic == HEAP_AREA_MAGIC); 266 malloc_assert(addr == area->start); 267 malloc_assert(area->start < area->end); 268 malloc_assert(((uintptr_t) area->start % PAGE_SIZE) == 0); 269 malloc_assert(((uintptr_t) area->end % PAGE_SIZE) == 0); 254 270 } 255 271 … … 382 398 383 399 block_check((void *) last_head); 384 assert_static(last_head->area == area);400 malloc_assert(last_head->area == area); 385 401 386 402 if (last_head->free) { … … 395 411 396 412 block_check((void *) first_head); 397 assert_static(first_head->area == area);413 malloc_assert(first_head->area == area); 398 414 399 415 size_t shrink_size = ALIGN_DOWN(last_head->size, PAGE_SIZE); … … 497 513 static void split_mark(heap_block_head_t *cur, const size_t size) 498 514 { 499 assert_static(cur->size >= size);515 malloc_assert(cur->size >= size); 500 516 501 517 /* See if we should split the block. */ … … 533 549 { 534 550 area_check((void *) area); 535 assert_static((void *) first_block >= (void *) AREA_FIRST_BLOCK_HEAD(area));536 assert_static((void *) first_block < area->end);551 malloc_assert((void *) first_block >= (void *) AREA_FIRST_BLOCK_HEAD(area)); 552 malloc_assert((void *) first_block < area->end); 537 553 538 554 for (heap_block_head_t *cur = first_block; (void *) cur < area->end; … … 661 677 static void *malloc_internal(const size_t size, const size_t align) 662 678 { 663 assert_static(first_heap_area != NULL);679 malloc_assert(first_heap_area != NULL); 664 680 665 681 if (align == 0) … … 786 802 787 803 block_check(head); 788 assert_static(!head->free);804 malloc_assert(!head->free); 789 805 790 806 heap_area_t *area = head->area; 791 807 792 808 area_check(area); 793 assert_static((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));794 assert_static((void *) head < area->end);809 malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area)); 810 malloc_assert((void *) head < area->end); 795 811 796 812 void *ptr = NULL; … … 863 879 864 880 block_check(head); 865 assert_static(!head->free);881 malloc_assert(!head->free); 866 882 867 883 heap_area_t *area = head->area; 868 884 869 885 area_check(area); 870 assert_static((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));871 assert_static((void *) head < area->end);886 malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area)); 887 malloc_assert((void *) head < area->end); 872 888 873 889 /* Mark the block itself as free. */
Note:
See TracChangeset
for help on using the changeset viewer.