2002-07-25 14:49:29 +00:00
|
|
|
/*
|
2006-03-13 17:18:15 +00:00
|
|
|
* Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de.
|
2005-05-26 09:11:30 +00:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
* Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
2008-02-10 21:00:13 +00:00
|
|
|
#ifndef _KERNEL_HEAP_H
|
|
|
|
#define _KERNEL_HEAP_H
|
2005-05-26 09:11:30 +00:00
|
|
|
|
2004-10-18 15:23:34 +00:00
|
|
|
#include <OS.h>
|
2003-05-03 16:03:26 +00:00
|
|
|
|
2008-10-20 14:24:46 +00:00
|
|
|
#include "kernel_debug_config.h"
|
|
|
|
|
|
|
|
|
2008-02-10 21:00:13 +00:00
|
|
|
// allocate 16MB initial heap for the kernel
|
2008-02-18 01:04:19 +00:00
|
|
|
#define INITIAL_HEAP_SIZE 16 * 1024 * 1024
|
2008-07-01 23:19:35 +00:00
|
|
|
// grow by another 4MB each time the heap runs out of memory
|
|
|
|
#define HEAP_GROW_SIZE 4 * 1024 * 1024
|
2008-06-18 19:55:51 +00:00
|
|
|
// allocate a dedicated 1MB area for dynamic growing
|
|
|
|
#define HEAP_DEDICATED_GROW_SIZE 1 * 1024 * 1024
|
2008-07-01 23:19:35 +00:00
|
|
|
// use areas for allocations bigger than 1MB
|
|
|
|
#define HEAP_AREA_USE_THRESHOLD 1 * 1024 * 1024
|
2002-08-05 17:22:19 +00:00
|
|
|
|
2002-07-25 14:49:29 +00:00
|
|
|
|
2008-08-14 00:40:40 +00:00
|
|
|
typedef struct heap_class_s {
|
|
|
|
const char *name;
|
|
|
|
uint32 initial_percentage;
|
|
|
|
size_t max_allocation_size;
|
|
|
|
size_t page_size;
|
|
|
|
size_t min_bin_size;
|
|
|
|
size_t bin_alignment;
|
|
|
|
uint32 min_count_per_page;
|
|
|
|
size_t max_waste_per_page;
|
|
|
|
} heap_class;
|
|
|
|
|
|
|
|
typedef struct heap_allocator_s heap_allocator;
|
|
|
|
|
|
|
|
|
2004-10-18 15:23:34 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-06-18 19:55:51 +00:00
|
|
|
// malloc_nogrow disallows waiting for a grow to happen - only to be used by
|
|
|
|
// vm functions that may deadlock on a triggered area creation
|
|
|
|
void *malloc_nogrow(size_t size);
|
|
|
|
|
2004-10-18 15:23:34 +00:00
|
|
|
void *memalign(size_t alignment, size_t size);
|
|
|
|
|
2008-03-09 17:44:55 +00:00
|
|
|
void deferred_free(void* block);
|
|
|
|
|
2008-03-29 23:55:34 +00:00
|
|
|
void* malloc_referenced(size_t size);
|
|
|
|
void* malloc_referenced_acquire(void* data);
|
|
|
|
void malloc_referenced_release(void* data);
|
|
|
|
|
2008-08-14 00:40:40 +00:00
|
|
|
heap_allocator* heap_create_allocator(const char* name, addr_t base,
|
|
|
|
size_t size, const heap_class* heapClass);
|
|
|
|
void* heap_memalign(heap_allocator* heap, size_t alignment, size_t size);
|
|
|
|
status_t heap_free(heap_allocator* heap, void* address);
|
|
|
|
|
2008-08-21 03:04:12 +00:00
|
|
|
#if KERNEL_HEAP_LEAK_CHECK
|
|
|
|
void heap_set_get_caller(heap_allocator* heap, addr_t (*getCaller)());
|
|
|
|
#endif
|
|
|
|
|
2006-03-19 15:02:21 +00:00
|
|
|
status_t heap_init(addr_t heapBase, size_t heapSize);
|
2008-02-10 21:00:13 +00:00
|
|
|
status_t heap_init_post_sem();
|
|
|
|
status_t heap_init_post_thread();
|
2004-10-18 15:23:34 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2002-07-09 12:24:59 +00:00
|
|
|
|
2008-07-22 20:36:32 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
#include <new>
|
|
|
|
|
2008-10-22 14:46:20 +00:00
|
|
|
#include <util/SinglyLinkedList.h>
|
|
|
|
|
|
|
|
|
2008-07-22 20:36:32 +00:00
|
|
|
static const struct nogrow_t {
|
|
|
|
} nogrow = {};
|
|
|
|
|
|
|
|
inline void*
|
2008-10-17 08:32:42 +00:00
|
|
|
operator new(size_t size, const nogrow_t& nogrow) throw()
|
2008-07-22 20:36:32 +00:00
|
|
|
{
|
|
|
|
return malloc_nogrow(size);
|
|
|
|
}
|
|
|
|
|
2008-10-22 14:46:20 +00:00
|
|
|
|
|
|
|
class DeferredDeletable : public SinglyLinkedListLinkImpl<DeferredDeletable> {
|
|
|
|
public:
|
|
|
|
virtual ~DeferredDeletable();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void deferred_delete(DeferredDeletable* deletable);
|
|
|
|
|
|
|
|
|
2008-07-22 20:36:32 +00:00
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
|
2002-10-29 23:03:47 +00:00
|
|
|
#endif /* _KERNEL_MEMHEAP_H */
|