From 03f0f385679fb7713f897e042383ec01f53d2249 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Fri, 18 Nov 2016 17:00:37 +0100 Subject: [PATCH] cxx: avoid warnings about cxx exception memory Avoids warnings like Warning: 2 dangling allocations at allocator destruction time during noux process destruction. --- repos/base/src/lib/cxx/malloc_free.cc | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/repos/base/src/lib/cxx/malloc_free.cc b/repos/base/src/lib/cxx/malloc_free.cc index 81eda0c318..f8b8e93a0b 100644 --- a/repos/base/src/lib/cxx/malloc_free.cc +++ b/repos/base/src/lib/cxx/malloc_free.cc @@ -22,14 +22,21 @@ /* base-internal includes */ #include +#include using namespace Genode; -static Lazy_volatile_object &cxx_heap() +static Heap *cxx_heap_ptr; + + +static Heap &cxx_heap() { - static Lazy_volatile_object heap; - return heap; + class Cxx_heap_uninitialized : Exception { }; + if (!cxx_heap_ptr) + throw Cxx_heap_uninitialized(); + + return *cxx_heap_ptr; } @@ -42,16 +49,15 @@ static Lazy_volatile_object &cxx_heap() */ void Genode::init_cxx_heap(Env &env) { - if (cxx_heap().constructed()) return; - /* * Exception frames are small. Hence, a small static backing store suffices * for the cxx heap partition in the normal case. The 'env.ram()' session * is used only if the demand exceeds the capacity of the 'initial_block'. */ static char initial_block[1024*sizeof(long)]; - cxx_heap().construct(&env.ram(), &env.rm(), - Heap::UNLIMITED, initial_block, sizeof(initial_block)); + + cxx_heap_ptr = unmanaged_singleton(&env.ram(), &env.rm(), Heap::UNLIMITED, + initial_block, sizeof(initial_block)); } @@ -71,7 +77,7 @@ extern "C" void *malloc(unsigned size) */ unsigned long real_size = size + sizeof(Block_header); void *addr = 0; - if (!cxx_heap()->alloc(real_size, &addr)) + if (!cxx_heap().alloc(real_size, &addr)) return 0; *(Block_header *)addr = real_size; @@ -92,7 +98,7 @@ extern "C" void free(void *ptr) if (!ptr) return; unsigned long *addr = ((unsigned long *)ptr) - 1; - cxx_heap()->free(addr, *addr); + cxx_heap().free(addr, *addr); }