Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 0c33b1d5 in mainline


Ignore:
Timestamp:
2011-05-20T23:58:26Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
955f2a5
Parents:
c263c77
Message:

The malloc_futex should be up'ed when an assert is hit inside malloc().

File:
1 edited

Legend:

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

    rc263c77 r0c33b1d5  
    119119            (((uintptr_t) (head)) + (head)->size - sizeof(heap_block_foot_t)))
    120120
     121#define malloc_assert(expr) \
     122        do { \
     123                if (!(expr)) {\
     124                        futex_up(&malloc_futex); \
     125                        assert((expr)); \
     126                } \
     127        } while (0)
     128
     129
    121130/** Heap area.
    122131 *
     
    228237        heap_block_head_t *head = (heap_block_head_t *) addr;
    229238       
    230         assert(head->magic == HEAP_BLOCK_HEAD_MAGIC);
     239        malloc_assert(head->magic == HEAP_BLOCK_HEAD_MAGIC);
    231240       
    232241        heap_block_foot_t *foot = BLOCK_FOOT(head);
    233242       
    234         assert(foot->magic == HEAP_BLOCK_FOOT_MAGIC);
    235         assert(head->size == foot->size);
     243        malloc_assert(foot->magic == HEAP_BLOCK_FOOT_MAGIC);
     244        malloc_assert(head->size == foot->size);
    236245}
    237246
     
    247256        heap_area_t *area = (heap_area_t *) addr;
    248257       
    249         assert(area->magic == HEAP_AREA_MAGIC);
    250         assert(addr == area->start);
    251         assert(area->start < area->end);
    252         assert(((uintptr_t) area->start % PAGE_SIZE) == 0);
    253         assert(((uintptr_t) area->end % PAGE_SIZE) == 0);
     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);
    254263}
    255264
     
    382391       
    383392        block_check((void *) last_head);
    384         assert(last_head->area == area);
     393        malloc_assert(last_head->area == area);
    385394       
    386395        if (last_head->free) {
     
    395404               
    396405                block_check((void *) first_head);
    397                 assert(first_head->area == area);
     406                malloc_assert(first_head->area == area);
    398407               
    399408                size_t shrink_size = ALIGN_DOWN(last_head->size, PAGE_SIZE);
     
    497506static void split_mark(heap_block_head_t *cur, const size_t size)
    498507{
    499         assert(cur->size >= size);
     508        malloc_assert(cur->size >= size);
    500509       
    501510        /* See if we should split the block. */
     
    533542{
    534543        area_check((void *) area);
    535         assert((void *) first_block >= (void *) AREA_FIRST_BLOCK_HEAD(area));
    536         assert((void *) first_block < area->end);
     544        malloc_assert((void *) first_block >= (void *) AREA_FIRST_BLOCK_HEAD(area));
     545        malloc_assert((void *) first_block < area->end);
    537546       
    538547        for (heap_block_head_t *cur = first_block; (void *) cur < area->end;
     
    661670static void *malloc_internal(const size_t size, const size_t align)
    662671{
    663         assert(first_heap_area != NULL);
     672        malloc_assert(first_heap_area != NULL);
    664673       
    665674        if (align == 0)
     
    786795       
    787796        block_check(head);
    788         assert(!head->free);
     797        malloc_assert(!head->free);
    789798       
    790799        heap_area_t *area = head->area;
    791800       
    792801        area_check(area);
    793         assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));
    794         assert((void *) head < area->end);
     802        malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));
     803        malloc_assert((void *) head < area->end);
    795804       
    796805        void *ptr = NULL;
     
    863872       
    864873        block_check(head);
    865         assert(!head->free);
     874        malloc_assert(!head->free);
    866875       
    867876        heap_area_t *area = head->area;
    868877       
    869878        area_check(area);
    870         assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));
    871         assert((void *) head < area->end);
     879        malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area));
     880        malloc_assert((void *) head < area->end);
    872881       
    873882        /* Mark the block itself as free. */
Note: See TracChangeset for help on using the changeset viewer.