Changes in uspace/lib/c/generic/malloc.c [c828803:e7c3fa0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/malloc.c
rc828803 re7c3fa0 110 110 111 111 #define AREA_LAST_BLOCK_HEAD(area) \ 112 ((uintptr_t) BLOCK_HEAD(((heap_block_foot_t *) 112 ((uintptr_t) BLOCK_HEAD(((heap_block_foot_t *)AREA_LAST_BLOCK_FOOT(area)))) 113 113 114 114 /** Get header in heap block. … … 349 349 return false; 350 350 351 heap_block_head_t *last_head = 352 (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area); 351 heap_block_head_t *last_head = (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area); 353 352 354 353 if (last_head->free) { … … 652 651 653 652 /** Try to enlarge any of the heap areas. 654 * 655 * If successful, allocate block of the given size in the area.653 * If successful, allocate block of the given size in the area. 654 * 656 655 * Should be called only inside the critical section. 657 656 * 658 * @param size 657 * @param size Gross size of item to allocate (bytes). 659 658 * @param align Memory address alignment. 660 *661 * @return Allocated block.662 * @return NULL on failure.663 659 * 664 660 */ … … 667 663 if (size == 0) 668 664 return NULL; 669 665 670 666 /* First try to enlarge some existing area */ 671 667 for (heap_area_t *area = first_heap_area; area != NULL; 672 668 area = area->next) { 673 669 674 670 if (area_grow(area, size + align)) { 675 heap_block_head_t *first = 676 (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area); 677 678 void *addr = 679 malloc_area(area, first, NULL, size, align); 671 heap_block_head_t *first = (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area); 672 673 void *addr = malloc_area(area, first, NULL, size, align); 680 674 malloc_assert(addr != NULL); 681 675 return addr; … … 685 679 /* Eventually try to create a new area */ 686 680 if (area_create(AREA_OVERHEAD(size + align))) { 687 heap_block_head_t *first = 688 (heap_block_head_t *) AREA_FIRST_BLOCK_HEAD(last_heap_area); 689 690 void *addr = 691 malloc_area(last_heap_area, first, NULL, size, align); 681 heap_block_head_t *first = (heap_block_head_t *) AREA_FIRST_BLOCK_HEAD(last_heap_area); 682 683 void *addr = malloc_area(last_heap_area, first, NULL, size, align); 692 684 malloc_assert(addr != NULL); 693 685 return addr; … … 715 707 716 708 size_t falign = lcm(align, BASE_ALIGN); 717 709 718 710 /* Check for integer overflow. */ 719 711 if (falign < align) 720 712 return NULL; 721 722 /* 723 * The size of the allocated block needs to be naturally 724 * aligned, because the footer structure also needs to reside 725 * on a naturally aligned address in order to avoid unaligned 726 * memory accesses. 727 */ 728 size_t gross_size = GROSS_SIZE(ALIGN_UP(size, BASE_ALIGN)); 713 714 size_t gross_size = GROSS_SIZE(size); 715 716 heap_block_head_t *split; 729 717 730 718 /* Try the next fit approach */ 731 heap_block_head_t *split = next_fit;719 split = next_fit; 732 720 733 721 if (split != NULL) { … … 766 754 void *calloc(const size_t nmemb, const size_t size) 767 755 { 768 // FIXME: Check for overflow769 770 756 void *block = malloc(nmemb * size); 771 757 if (block == NULL) … … 907 893 if (addr == NULL) 908 894 return; 909 895 910 896 futex_down(&malloc_futex); 911 897
Note:
See TracChangeset
for help on using the changeset viewer.