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:
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
||||||
** Distributed under the terms of the NewOS License.
|
** Distributed under the terms of the NewOS License.
|
||||||
*/
|
*/
|
||||||
@@ -8,7 +8,9 @@
|
|||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <stage2.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);
|
int heap_init_postsem(kernel_args *ka);
|
||||||
void *kmalloc(unsigned int size);
|
void *kmalloc(unsigned int size);
|
||||||
void kfree(void *address);
|
void kfree(void *address);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
/* Heap + other assorted stuff. Needs cleanup */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||||
** Distributed under the terms of the NewOS License.
|
** Distributed under the terms of the NewOS License.
|
||||||
@@ -108,15 +106,13 @@ dump_bin_list(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
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
|
const unsigned int page_entries = PAGE_SIZE / sizeof(struct heap_page);
|
||||||
// the NewOS fix for this... -- axeld.
|
|
||||||
|
|
||||||
// set some global pointers
|
// set some global pointers
|
||||||
heap_alloc_table = (struct heap_page *)new_heap_base;
|
heap_alloc_table = (struct heap_page *)new_heap_base;
|
||||||
heap_size = new_heap_size;
|
heap_size = ((uint64)HEAP_SIZE * page_entries / (page_entries + 1)) & ~(PAGE_SIZE-1);
|
||||||
heap_base = PAGE_ALIGN((unsigned int)heap_alloc_table + (heap_size / PAGE_SIZE) * sizeof(struct heap_page));
|
heap_base = (unsigned int)heap_alloc_table + PAGE_ALIGN(heap_size / page_entries);
|
||||||
heap_base_ptr = heap_base;
|
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);
|
dprintf("heap_alloc_table = %p, heap_base = 0x%lx, heap_size = 0x%lx\n", heap_alloc_table, heap_base, heap_size);
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define HEAP_SIZE 0x00400000
|
|
||||||
|
|
||||||
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
|
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
|
||||||
#define ROUNDOWN(a, b) (((a) / (b)) * (b))
|
#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
|
// map in the new heap and initialize it
|
||||||
heap_base = vm_alloc_from_ka_struct(ka, HEAP_SIZE, LOCK_KERNEL|LOCK_RW);
|
heap_base = vm_alloc_from_ka_struct(ka, HEAP_SIZE, LOCK_KERNEL|LOCK_RW);
|
||||||
dprintf("heap at 0x%lx\n", heap_base);
|
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
|
// initialize the free page list and physical page mapper
|
||||||
vm_page_init(ka);
|
vm_page_init(ka);
|
||||||
|
|||||||
Reference in New Issue
Block a user