Changes in / [7df0c2ff:7deca26] in mainline
- Location:
- uspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/hc.c
r7df0c2ff r7deca26 66 66 .srcarg = 1, 67 67 .dstarg = 2, 68 .value = 068 .value = OHCI_USED_INTERRUPTS 69 69 }, 70 70 { … … 132 132 cmds[0].addr = (void *) ®isters->interrupt_status; 133 133 cmds[3].addr = (void *) ®isters->interrupt_status; 134 OHCI_WR(cmds[1].value, OHCI_USED_INTERRUPTS);135 134 136 135 return EOK; -
uspace/lib/c/generic/malloc.c
r7df0c2ff r7deca26 109 109 (((uintptr_t) (area)->end) - sizeof(heap_block_foot_t)) 110 110 111 #define AREA_LAST_BLOCK_HEAD(area) \112 ((uintptr_t) BLOCK_HEAD(((heap_block_foot_t *)AREA_LAST_BLOCK_FOOT(area))))113 114 111 /** Get header in heap block. 115 112 * … … 349 346 return false; 350 347 351 heap_block_head_t *last_head = (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area); 352 353 if (last_head->free) { 354 /* Add the new space to the last block. */ 355 size_t net_size = (size_t) (end - area->end) + last_head->size; 356 malloc_assert(net_size > 0); 357 block_init(last_head, net_size, true, area); 358 } else { 359 /* Add new free block */ 360 size_t net_size = (size_t) (end - area->end); 361 if (net_size > 0) 362 block_init(area->end, net_size, true, area); 363 } 348 /* Add new free block */ 349 size_t net_size = (size_t) (end - area->end); 350 if (net_size > 0) 351 block_init(area->end, net_size, true, area); 364 352 365 353 /* Update heap area parameters */ … … 367 355 368 356 return true; 357 } 358 359 /** Try to enlarge any of the heap areas 360 * 361 * Should be called only inside the critical section. 362 * 363 * @param size Gross size of item to allocate (bytes). 364 * 365 */ 366 static bool heap_grow(size_t size) 367 { 368 if (size == 0) 369 return true; 370 371 /* First try to enlarge some existing area */ 372 for (heap_area_t *area = first_heap_area; area != NULL; 373 area = area->next) { 374 if (area_grow(area, size)) 375 return true; 376 } 377 378 /* Eventually try to create a new area */ 379 return area_create(AREA_OVERHEAD(size)); 369 380 } 370 381 … … 650 661 } 651 662 652 /** Try to enlarge any of the heap areas.653 * If successful, allocate block of the given size in the area.654 *655 * Should be called only inside the critical section.656 *657 * @param size Gross size of item to allocate (bytes).658 * @param align Memory address alignment.659 *660 */661 static void *heap_grow_and_alloc(size_t size, size_t align)662 {663 if (size == 0)664 return NULL;665 666 /* First try to enlarge some existing area */667 for (heap_area_t *area = first_heap_area; area != NULL;668 area = area->next) {669 670 if (area_grow(area, 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);674 malloc_assert(addr != NULL);675 return addr;676 }677 }678 679 /* Eventually try to create a new area */680 if (area_create(AREA_OVERHEAD(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);684 malloc_assert(addr != NULL);685 return addr;686 }687 688 return NULL;689 }690 691 663 /** Allocate a memory block 692 664 * … … 707 679 708 680 size_t falign = lcm(align, BASE_ALIGN); 709 710 /* Check for integer overflow. */ 711 if (falign < align) 712 return NULL; 713 714 size_t gross_size = GROSS_SIZE(size); 715 681 size_t real_size = GROSS_SIZE(ALIGN_UP(size, falign)); 682 683 bool retry = false; 716 684 heap_block_head_t *split; 685 686 loop: 717 687 718 688 /* Try the next fit approach */ … … 720 690 721 691 if (split != NULL) { 722 void *addr = malloc_area(split->area, split, NULL, gross_size,692 void *addr = malloc_area(split->area, split, NULL, real_size, 723 693 falign); 724 694 … … 733 703 AREA_FIRST_BLOCK_HEAD(area); 734 704 735 void *addr = malloc_area(area, first, split, gross_size,705 void *addr = malloc_area(area, first, split, real_size, 736 706 falign); 737 707 … … 740 710 } 741 711 742 /* Finally, try to grow heap space and allocate in the new area. */ 743 return heap_grow_and_alloc(gross_size, falign); 712 if (!retry) { 713 /* Try to grow the heap space */ 714 if (heap_grow(real_size)) { 715 retry = true; 716 goto loop; 717 } 718 } 719 720 return NULL; 744 721 } 745 722
Note:
See TracChangeset
for help on using the changeset viewer.