mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-23 01:08:55 +00: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
This commit is contained in:
committed by
Christian Helmuth
parent
a5d3aa8373
commit
17c79a9e23
@ -57,7 +57,7 @@ class Lx_kit::Slab_backend_alloc : public Lx::Slab_backend_alloc,
|
||||
bool _alloc_block()
|
||||
{
|
||||
if (_index == ELEMENTS) {
|
||||
PERR("Slab-backend exhausted!");
|
||||
Genode::error("slab backend exhausted!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ class Lx_kit::Slab_backend_alloc : public Lx::Slab_backend_alloc,
|
||||
|
||||
done = _alloc_block();
|
||||
if (!done) {
|
||||
PERR("Backend allocator exhausted\n");
|
||||
Genode::error("backend allocator exhausted");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ class Lx_kit::Slab_backend_alloc : public Lx::Slab_backend_alloc,
|
||||
return _base + i * V_BLOCK_SIZE + phys - _ds_phys[i];
|
||||
}
|
||||
|
||||
PWRN("virt_addr(0x%lx) - no translation", phys);
|
||||
Genode::warning("virt_addr(", Genode::Hex(phys), ") - no translation");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -273,13 +273,14 @@ class Lx_kit::Malloc : public Lx::Malloc
|
||||
msb = SLAB_STOP_LOG2;
|
||||
|
||||
if (msb > SLAB_STOP_LOG2) {
|
||||
PERR("Slab too large %u reqested %zu cached %d", 1U << msb, size, _cached);
|
||||
Genode::error("slab too large ",
|
||||
1UL << msb, "reqested ", size, " cached ", (int)_cached);
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr_t addr = _allocator[msb - SLAB_START_LOG2]->alloc();
|
||||
if (!addr) {
|
||||
PERR("Failed to get slab for %u", 1 << msb);
|
||||
Genode::error("failed to get slab for ", 1 << msb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -320,7 +321,7 @@ class Lx_kit::Malloc : public Lx::Malloc
|
||||
{
|
||||
void *addr;
|
||||
if (!_back_allocator.alloc(size, &addr)) {
|
||||
PERR("Large back end allocation failed (%zu bytes)", size);
|
||||
Genode::error("large back end allocation failed (", size, " bytes)");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -96,8 +96,8 @@ void *Lx::ioremap(addr_t phys_addr, unsigned long size,
|
||||
|
||||
if (r->phys_range(phys_addr, size)) {
|
||||
void * const virt = (void *)(r->virt() + phys_addr - r->phys());
|
||||
PLOG("ioremap: return sub range phys 0x%lx (size %lx) to virt 0x%lx",
|
||||
(long)phys_addr, (long)size, (long)virt);
|
||||
log("ioremap: return sub range phys ", Hex(phys_addr), " "
|
||||
"(size ", size, ") to virt ", virt);
|
||||
return virt;
|
||||
}
|
||||
}
|
||||
@ -108,8 +108,8 @@ void *Lx::ioremap(addr_t phys_addr, unsigned long size,
|
||||
size, offset);
|
||||
|
||||
if (!ds_cap.valid()) {
|
||||
PERR("Failed to request I/O memory: [%lx,%lx)", phys_addr,
|
||||
phys_addr + size);
|
||||
error("failed to request I/O memory: ",
|
||||
Hex_range<addr_t>(phys_addr, size));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -119,8 +119,8 @@ void *Lx::ioremap(addr_t phys_addr, unsigned long size,
|
||||
|
||||
ranges.insert(io_mem);
|
||||
|
||||
PLOG("ioremap: mapped phys 0x%lx (size %lx) to virt 0x%lx",
|
||||
(long)phys_addr, (long)size, (long)io_mem->virt());
|
||||
log("ioremap: mapped phys ", Hex(phys_addr), " (size ", size, ") "
|
||||
"to virt ", Hex(io_mem->virt()));
|
||||
|
||||
return (void *)io_mem->virt();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* \brief Linux kit memory allocator
|
||||
* \brief Linux kit printf backend
|
||||
* \author Sebastian Sumpf
|
||||
* \date 2016-04-20
|
||||
*/
|
||||
@ -11,10 +11,6 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/console.h>
|
||||
#include <base/printf.h>
|
||||
|
||||
/* local includes */
|
||||
#include <lx_emul.h>
|
||||
|
||||
@ -26,7 +22,6 @@ namespace Lx {
|
||||
|
||||
extern "C" int stdout_write(const char *s);
|
||||
|
||||
static const bool verbose_console = false;
|
||||
|
||||
/**
|
||||
* Format string command representation
|
||||
@ -347,7 +342,7 @@ class Lx::Console
|
||||
switch (cmd.type) {
|
||||
|
||||
case Format_command::INT:
|
||||
|
||||
|
||||
if (cmd.length == Format_command::LONG_LONG)
|
||||
_out_signed<long long>(numeric_arg, cmd.base);
|
||||
else
|
||||
@ -434,8 +429,6 @@ class Lx::Console
|
||||
|
||||
void lx_printf(char const *fmt, ...)
|
||||
{
|
||||
if (verbose_console)
|
||||
PDBG("[%p] %s", __builtin_return_address(0), fmt);
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
Lx::Console::c().vprintf(fmt, va);
|
||||
|
@ -16,13 +16,12 @@
|
||||
/* Genode includes */
|
||||
#include <base/env.h>
|
||||
#include <base/lock.h>
|
||||
#include <base/printf.h>
|
||||
#include <base/log.h>
|
||||
#include <base/sleep.h>
|
||||
#include <base/thread.h>
|
||||
#include <timer_session/connection.h>
|
||||
|
||||
/* Linux emulation environment includes */
|
||||
#include <lx_kit/internal/debug.h>
|
||||
#include <lx_kit/scheduler.h>
|
||||
|
||||
#include <lx_kit/timer.h>
|
||||
@ -84,7 +83,6 @@ class Lx_kit::Scheduler : public Lx::Scheduler
|
||||
|
||||
void entry()
|
||||
{
|
||||
PWRN("Scheduler::Logger is up");
|
||||
_timer.msleep(1000 * _interval);
|
||||
while (true) {
|
||||
_scheduler.log_state("LOGGER");
|
||||
@ -108,7 +106,7 @@ class Lx_kit::Scheduler : public Lx::Scheduler
|
||||
Lx::Task *current() override
|
||||
{
|
||||
if (!_current) {
|
||||
PERR("BUG: _current is zero!");
|
||||
Genode::error("BUG: _current is zero!");
|
||||
Genode::sleep_forever();
|
||||
}
|
||||
|
||||
@ -168,7 +166,7 @@ class Lx_kit::Scheduler : public Lx::Scheduler
|
||||
}
|
||||
|
||||
if (!at_least_one) {
|
||||
PWRN("schedule() called without runnable tasks");
|
||||
Genode::warning("schedule() called without runnable tasks");
|
||||
log_state("SCHEDULE");
|
||||
}
|
||||
|
||||
@ -181,9 +179,11 @@ class Lx_kit::Scheduler : public Lx::Scheduler
|
||||
unsigned i;
|
||||
Lx::Task *t;
|
||||
for (i = 0, t = _present_list.first(); t; t = t->next(), ++i) {
|
||||
Genode::printf("%s [%u] prio: %u state: %s%u%s %s\n",
|
||||
prefix, i, t->priority(), _state_color(t->state()),
|
||||
t->state(), _ansi_esc_reset(), t->name());
|
||||
Genode::log(prefix, " [", i, "] "
|
||||
"prio: ", (int)t->priority(), " "
|
||||
"state: ", _state_color(t->state()), (int)t->state(),
|
||||
_ansi_esc_reset(), " ",
|
||||
t->name());
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -202,7 +202,8 @@ Lx::Task::Task(void (*func)(void*), void *arg, char const *name,
|
||||
scheduler.add(this);
|
||||
|
||||
if (verbose)
|
||||
PDBG("name: '%s' func: %p arg: %p prio: %u t: %p", name, func, arg, priority, this);
|
||||
Genode::log("name: '", name, "' " "func: ", func, " "
|
||||
"arg: ", arg, " prio: ", (int)priority, " t: ", this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -250,7 +250,7 @@ class Lx_kit::Timer : public Lx::Timer
|
||||
{
|
||||
Context *ctx = _find_context(timer);
|
||||
if (!ctx) {
|
||||
PERR("schedule unknown timer %p", timer);
|
||||
Genode::error("schedule unknown timer ", timer);
|
||||
return -1; /* XXX better use 0 as rv? */
|
||||
}
|
||||
|
||||
|
@ -168,5 +168,5 @@ Lx::Work * Lx::Work::alloc_work_queue(Genode::Allocator *alloc, char const *name
|
||||
|
||||
void Lx::Work::free_work_queue(Lx::Work *w)
|
||||
{
|
||||
PERR("%s: IMPLEMENT ME", __func__);
|
||||
Genode::error(__func__, ": IMPLEMENT ME");
|
||||
}
|
||||
|
Reference in New Issue
Block a user