2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief New and delete are special
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-04-07
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2006-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
#include <base/log.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <base/allocator.h>
|
2014-01-23 10:26:04 +01:00
|
|
|
#include <base/sleep.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2014-01-17 11:03:36 +01:00
|
|
|
using Genode::size_t;
|
|
|
|
using Genode::Allocator;
|
2014-01-23 10:26:04 +01:00
|
|
|
using Genode::Deallocator;
|
|
|
|
using Genode::sleep_forever;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2014-01-17 11:03:36 +01:00
|
|
|
|
|
|
|
static void *try_alloc(Allocator *alloc, size_t size)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2014-01-17 11:03:36 +01:00
|
|
|
if (!alloc)
|
|
|
|
throw Allocator::Out_of_memory();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2014-01-17 11:03:36 +01:00
|
|
|
return alloc->alloc(size);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-15 14:40:37 +02:00
|
|
|
void *operator new (__SIZE_TYPE__ s, Allocator *a) { return try_alloc(a, s); }
|
|
|
|
void *operator new [] (__SIZE_TYPE__ s, Allocator *a) { return try_alloc(a, s); }
|
|
|
|
void *operator new (__SIZE_TYPE__ s, Allocator &a) { return a.alloc(s); }
|
|
|
|
void *operator new [] (__SIZE_TYPE__ s, Allocator &a) { return a.alloc(s); }
|
2012-01-26 21:03:49 +01:00
|
|
|
|
|
|
|
|
2014-01-23 10:26:04 +01:00
|
|
|
static void try_dealloc(void *ptr, Deallocator &dealloc)
|
2012-01-26 21:03:49 +01:00
|
|
|
{
|
|
|
|
/*
|
2014-01-23 10:26:04 +01:00
|
|
|
* Log error and block on the attempt to use an allocator that relies on
|
|
|
|
* the size argument.
|
2012-01-26 21:03:49 +01:00
|
|
|
*/
|
2014-01-23 10:26:04 +01:00
|
|
|
if (dealloc.need_size_for_free()) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("C++ runtime: delete called with allocator, which needs "
|
|
|
|
"'size' on free. Blocking before leaking memory...");
|
2014-01-23 10:26:04 +01:00
|
|
|
sleep_forever();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* size not required, so call with dummy size */
|
|
|
|
dealloc.free(ptr, 0);
|
2012-01-26 21:03:49 +01:00
|
|
|
}
|
|
|
|
|
2012-10-18 04:57:40 +02:00
|
|
|
|
2014-01-23 10:26:04 +01:00
|
|
|
void operator delete (void *ptr, Deallocator *dealloc) { try_dealloc(ptr, *dealloc); }
|
|
|
|
void operator delete (void *ptr, Deallocator &dealloc) { try_dealloc(ptr, dealloc); }
|
|
|
|
|
|
|
|
|
2012-10-18 04:57:40 +02:00
|
|
|
/*
|
|
|
|
* The 'delete (void *)' operator gets referenced by compiler generated code,
|
|
|
|
* so it must be publicly defined in the 'cxx' library. These compiler
|
|
|
|
* generated calls seem to get executed only subsequently to explicit
|
|
|
|
* 'delete (void *)' calls in application code, which are not supported by the
|
|
|
|
* 'cxx' library, so the 'delete (void *)' implementation in the 'cxx' library
|
|
|
|
* does not have to do anything. Applications should use the 'delete (void *)'
|
|
|
|
* implementation of the 'stdcxx' library instead. To make this possible, the
|
|
|
|
* 'delete (void *)' implementation in the 'cxx' library must be 'weak'.
|
|
|
|
*/
|
2019-09-16 18:07:32 +02:00
|
|
|
__attribute__((weak)) void operator delete (void *) noexcept
|
2012-10-18 04:57:40 +02:00
|
|
|
{
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("cxx: operator delete (void *) called - not implemented. "
|
|
|
|
"A working implementation is available in the 'stdcxx' library.");
|
2012-10-18 04:57:40 +02:00
|
|
|
}
|
2019-05-07 13:21:23 +02:00
|
|
|
|
|
|
|
__attribute__((weak)) void operator delete (void *, unsigned long)
|
|
|
|
{
|
|
|
|
Genode::error("cxx: operator delete (void *, unsigned long) called - not implemented. "
|
|
|
|
"A working implementation is available in the 'stdcxx' library.");
|
|
|
|
}
|