Changeset 13f2461 in mainline for uspace/lib/c/generic/malloc.c


Ignore:
Timestamp:
2011-05-21T15:45:48Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9d47440, e06e2716
Parents:
faeb7cc
Message:

Merge the functionality of assert_abort() and assert_static_abort() into
assert_abort().

Print the unexpanded message to klog first. Then try to print the
message and the stack trace to standard output using printf. Use the
same unabbreviated message wording for both klog and stdout. If a
nested or a parallel assert is detected, send the message only to klog
and then abort.

Re-introduce malloc_assert() to up the malloc_futex. This appears to be
inevitable if we want to print to stdout. To prevent undesired macro
expansion, call assert_abort() from malloc_assert() directly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/malloc.c

    rfaeb7cc r13f2461  
    188188static futex_t malloc_futex = FUTEX_INITIALIZER;
    189189
     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
    190206/** Initialize a heap block
    191207 *
     
    228244        heap_block_head_t *head = (heap_block_head_t *) addr;
    229245       
    230         assert_static(head->magic == HEAP_BLOCK_HEAD_MAGIC);
     246        malloc_assert(head->magic == HEAP_BLOCK_HEAD_MAGIC);
    231247       
    232248        heap_block_foot_t *foot = BLOCK_FOOT(head);
    233249       
    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);
    236252}
    237253
     
    247263        heap_area_t *area = (heap_area_t *) addr;
    248264       
    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);
    254270}
    255271
     
    382398       
    383399        block_check((void *) last_head);
    384         assert_static(last_head->area == area);
     400        malloc_assert(last_head->area == area);
    385401       
    386402        if (last_head->free) {
     
    395411               
    396412                block_check((void *) first_head);
    397                 assert_static(first_head->area == area);
     413                malloc_assert(first_head->area == area);
    398414               
    399415                size_t shrink_size = ALIGN_DOWN(last_head->size, PAGE_SIZE);
     
    497513static void split_mark(heap_block_head_t *cur, const size_t size)
    498514{
    499         assert_static(cur->size >= size);
     515        malloc_assert(cur->size >= size);
    500516       
    501517        /* See if we should split the block. */
     
    533549{
    534550        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);
    537553       
    538554        for (heap_block_head_t *cur = first_block; (void *) cur < area->end;
     
    661677static void *malloc_internal(const size_t size, const size_t align)
    662678{
    663         assert_static(first_heap_area != NULL);
     679        malloc_assert(first_heap_area != NULL);
    664680       
    665681        if (align == 0)
     
    786802       
    787803        block_check(head);
    788         assert_static(!head->free);
     804        malloc_assert(!head->free);
    789805       
    790806        heap_area_t *area = head->area;
    791807       
    792808        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);
    795811       
    796812        void *ptr = NULL;
     
    863879       
    864880        block_check(head);
    865         assert_static(!head->free);
     881        malloc_assert(!head->free);
    866882       
    867883        heap_area_t *area = head->area;
    868884       
    869885        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);
    872888       
    873889        /* Mark the block itself as free. */
Note: See TracChangeset for help on using the changeset viewer.