Fixed the overflow bug in heap.c that would occur on allocation of all the memory of the heap.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@442 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
notion 2002-07-25 14:49:29 +00:00
parent 25f0d23bad
commit 66554a4c98
3 changed files with 9 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/*
/*
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
@ -8,7 +8,9 @@
#include <kernel.h>
#include <stage2.h>
int heap_init(addr new_heap_base, unsigned int new_heap_size);
#define HEAP_SIZE 0x00400000
int heap_init(addr new_heap_base);
int heap_init_postsem(kernel_args *ka);
void *kmalloc(unsigned int size);
void kfree(void *address);

View File

@ -1,5 +1,3 @@
/* Heap + other assorted stuff. Needs cleanup */
/*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
@ -108,15 +106,13 @@ dump_bin_list(int argc, char **argv)
*/
int
heap_init(addr new_heap_base, unsigned int new_heap_size)
heap_init(addr new_heap_base)
{
// ToDo: the heap size may overflow in certain circumstances, but I didn't like
// the NewOS fix for this... -- axeld.
const unsigned int page_entries = PAGE_SIZE / sizeof(struct heap_page);
// set some global pointers
heap_alloc_table = (struct heap_page *)new_heap_base;
heap_size = new_heap_size;
heap_base = PAGE_ALIGN((unsigned int)heap_alloc_table + (heap_size / PAGE_SIZE) * sizeof(struct heap_page));
heap_size = ((uint64)HEAP_SIZE * page_entries / (page_entries + 1)) & ~(PAGE_SIZE-1);
heap_base = (unsigned int)heap_alloc_table + PAGE_ALIGN(heap_size / page_entries);
heap_base_ptr = heap_base;
dprintf("heap_alloc_table = %p, heap_base = 0x%lx, heap_size = 0x%lx\n", heap_alloc_table, heap_base, heap_size);

View File

@ -35,8 +35,6 @@
#include <stdlib.h>
#include <stdio.h>
#define HEAP_SIZE 0x00400000
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
#define ROUNDOWN(a, b) (((a) / (b)) * (b))
@ -1667,7 +1665,7 @@ int vm_init(kernel_args *ka)
// map in the new heap and initialize it
heap_base = vm_alloc_from_ka_struct(ka, HEAP_SIZE, LOCK_KERNEL|LOCK_RW);
dprintf("heap at 0x%lx\n", heap_base);
heap_init(heap_base, HEAP_SIZE);
heap_init(heap_base);
// initialize the free page list and physical page mapper
vm_page_init(ka);