diff --git a/build/config_headers/kernel_debug_config.h b/build/config_headers/kernel_debug_config.h index 5029ab6d48..837c8373d2 100644 --- a/build/config_headers/kernel_debug_config.h +++ b/build/config_headers/kernel_debug_config.h @@ -114,6 +114,10 @@ #define USE_SLAB_ALLOCATOR_FOR_MALLOC 1 // Heap implementation based on the slab allocator (for production use). +// Replace the object cache with the guarded heap to force debug features. Also +// requires the use of the guarded heap for malloc. +#define USE_GUARDED_HEAP_FOR_OBJECT_CACHE 0 + // Enables additional sanity checks in the slab allocator's memory manager. #define DEBUG_SLAB_MEMORY_MANAGER_PARANOID_CHECKS 0 diff --git a/headers/private/kernel/heap.h b/headers/private/kernel/heap.h index 72d7e489de..3ac8b8a6e6 100644 --- a/headers/private/kernel/heap.h +++ b/headers/private/kernel/heap.h @@ -13,6 +13,15 @@ #include "kernel_debug_config.h" +#if USE_GUARDED_HEAP_FOR_MALLOC && USE_GUARDED_HEAP_FOR_OBJECT_CACHE + +// This requires a lot of up-front memory to boot at all... +#define INITIAL_HEAP_SIZE 128 * 1024 * 1024 +// ... and a lot of reserves to keep running. +#define HEAP_GROW_SIZE 128 * 1024 * 1024 + +#else // USE_GUARDED_HEAP_FOR_MALLOC && USE_GUARDED_HEAP_FOR_OBJECT_CACHE + // allocate 16MB initial heap for the kernel #define INITIAL_HEAP_SIZE 16 * 1024 * 1024 // grow by another 4MB each time the heap runs out of memory @@ -22,6 +31,8 @@ // use areas for allocations bigger than 1MB #define HEAP_AREA_USE_THRESHOLD 1 * 1024 * 1024 +#endif // !(USE_GUARDED_HEAP_FOR_MALLOC && USE_GUARDED_HEAP_FOR_OBJECT_CACHE) + // allocation/deallocation flags for {malloc,free}_etc() #define HEAP_DONT_WAIT_FOR_MEMORY 0x01 diff --git a/src/system/kernel/guarded_heap.cpp b/src/system/kernel/guarded_heap.cpp index e40b063aa1..ad75803cd4 100644 --- a/src/system/kernel/guarded_heap.cpp +++ b/src/system/kernel/guarded_heap.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -611,7 +612,7 @@ dump_guarded_heap_page(int argc, char** argv) } -// #pragma mark - public API +// #pragma mark - Malloc API status_t @@ -718,4 +719,101 @@ realloc(void* address, size_t newSize) } +#if USE_GUARDED_HEAP_FOR_OBJECT_CACHE + + +// #pragma mark - Slab API + + +void +request_memory_manager_maintenance() +{ +} + + +object_cache* +create_object_cache(const char*, size_t objectSize, size_t, void*, + object_cache_constructor, object_cache_destructor) +{ + return (object_cache*)objectSize; +} + + +object_cache* +create_object_cache_etc(const char*, size_t objectSize, size_t, size_t, size_t, + size_t, uint32, void*, object_cache_constructor, object_cache_destructor, + object_cache_reclaimer) +{ + return (object_cache*)objectSize; +} + + +void +delete_object_cache(object_cache* cache) +{ +} + + +status_t +object_cache_set_minimum_reserve(object_cache* cache, size_t objectCount) +{ + return B_OK; +} + + +void* +object_cache_alloc(object_cache* cache, uint32 flags) +{ + return memalign_etc(0, (size_t)cache, flags); +} + + +void +object_cache_free(object_cache* cache, void* object, uint32 flags) +{ + return free_etc(object, flags); +} + + +status_t +object_cache_reserve(object_cache* cache, size_t objectCount, uint32 flags) +{ + return B_OK; +} + + +void +object_cache_get_usage(object_cache* cache, size_t* _allocatedMemory) +{ + *_allocatedMemory = 0; +} + + +void +slab_init(kernel_args* args) +{ +} + + +void +slab_init_post_area() +{ +} + + +void +slab_init_post_sem() +{ +} + + +void +slab_init_post_thread() +{ +} + + +#endif // USE_GUARDED_HEAP_FOR_OBJECT_CACHE + + #endif // USE_GUARDED_HEAP_FOR_MALLOC diff --git a/src/system/kernel/slab/Slab.cpp b/src/system/kernel/slab/Slab.cpp index 59925dd5e4..8f9bdbe0be 100644 --- a/src/system/kernel/slab/Slab.cpp +++ b/src/system/kernel/slab/Slab.cpp @@ -36,6 +36,9 @@ #include "SmallObjectCache.h" +#if !USE_GUARDED_HEAP_FOR_OBJECT_CACHE + + typedef DoublyLinkedList ObjectCacheList; typedef DoublyLinkedList