Quick and dirty fix to allow our heap to allocate more than 64kB.

However, it will never free those allocations again.
This fixes the problems due to Rudolf's recent driver updates.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15248 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-30 19:28:46 +00:00
parent 983af123cd
commit 6aae81b3e1
+16 -8
View File
@@ -280,7 +280,8 @@ check_wall_daemon(void *arg, int iteration)
#endif /* USE_CHECKING_WALL */ #endif /* USE_CHECKING_WALL */
static void dump_bin(int bin_index) static void
dump_bin(int bin_index)
{ {
struct heap_bin *bin = &bins[bin_index]; struct heap_bin *bin = &bins[bin_index];
unsigned int *temp; unsigned int *temp;
@@ -375,8 +376,10 @@ raw_alloc(unsigned int size, int bin_index)
addr_t addr; addr_t addr;
new_heap_ptr = heap_base_ptr + PAGE_ALIGN(size); new_heap_ptr = heap_base_ptr + PAGE_ALIGN(size);
if (new_heap_ptr > heap_base + heap_size) if (new_heap_ptr > heap_base + heap_size) {
panic("heap overgrew itself!\n"); panic("heap overgrew itself!\n");
return NULL;
}
for (addr = heap_base_ptr; addr < new_heap_ptr; addr += B_PAGE_SIZE) { for (addr = heap_base_ptr; addr < new_heap_ptr; addr += B_PAGE_SIZE) {
page = &heap_alloc_table[(addr - heap_base) / B_PAGE_SIZE]; page = &heap_alloc_table[(addr - heap_base) / B_PAGE_SIZE];
@@ -448,10 +451,9 @@ memalign(size_t alignment, size_t size)
break; break;
if (bin_index == bin_count) { if (bin_index == bin_count) {
// XXX fix the raw alloc later. address = raw_alloc(size, bin_index);
//address = raw_alloc(size, bin_index); dprintf("heap: allocated big chunk (%ld bytes), it will never be freed!\n",
panic("malloc: asked to allocate too much for now (%lu bytes)!\n", size); size);
goto out;
} else { } else {
if (bins[bin_index].free_list != NULL) { if (bins[bin_index].free_list != NULL) {
address = bins[bin_index].free_list; address = bins[bin_index].free_list;
@@ -480,7 +482,6 @@ memalign(size_t alignment, size_t size)
} }
} }
out:
mutex_unlock(&heap_lock); mutex_unlock(&heap_lock);
TRACE(("kmalloc: asked to allocate size %d, returning ptr = %p\n", size, address)); TRACE(("kmalloc: asked to allocate size %d, returning ptr = %p\n", size, address));
@@ -551,9 +552,10 @@ free(void *address)
TRACE(("free(): page %p: bin_index %d, free_count %d\n", page, page->bin_index, page->free_count)); TRACE(("free(): page %p: bin_index %d, free_count %d\n", page, page->bin_index, page->free_count));
if (page[0].bin_index >= bin_count) if (page[0].bin_index > bin_count)
panic("free(): page %p: invalid bin_index %d\n", page, page->bin_index); panic("free(): page %p: invalid bin_index %d\n", page, page->bin_index);
if (page[0].bin_index < bin_count) {
bin = &bins[page[0].bin_index]; bin = &bins[page[0].bin_index];
if (bin->element_size <= B_PAGE_SIZE && (addr_t)address % bin->element_size != 0) if (bin->element_size <= B_PAGE_SIZE && (addr_t)address % bin->element_size != 0)
@@ -593,6 +595,12 @@ free(void *address)
bin->free_list = address; bin->free_list = address;
bin->alloc_count--; bin->alloc_count--;
bin->free_count++; bin->free_count++;
} else {
// this chunk has been allocated via raw_alloc() directly
// TODO: since the heap must be replaced anyway, we don't
// free this allocation anymore... (tracking them would
// require some extra stuff)
}
mutex_unlock(&heap_lock); mutex_unlock(&heap_lock);
} }