mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-01 15:10:56 +00:00
base/thread.h: guard deref of '_logger()'
The pointer returned by '_logger()' can be a nullptr, in particular while tracing is (temporarily) inhibited. This patch ensures that the 'Thread::trace' accessors never operate on a nullptr. Fixes #5410
This commit is contained in:
parent
a06fd84b75
commit
329dbc56d0
@ -151,6 +151,12 @@ class Genode::Thread
|
|||||||
*/
|
*/
|
||||||
static Trace::Logger *_logger();
|
static Trace::Logger *_logger();
|
||||||
|
|
||||||
|
static void _with_logger(auto const &fn)
|
||||||
|
{
|
||||||
|
Trace::Logger * const ptr = _logger();
|
||||||
|
if (ptr) fn(*ptr);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook for platform-specific constructor supplements
|
* Hook for platform-specific constructor supplements
|
||||||
*
|
*
|
||||||
@ -397,14 +403,6 @@ class Genode::Thread
|
|||||||
*/
|
*/
|
||||||
void join();
|
void join();
|
||||||
|
|
||||||
/**
|
|
||||||
* Log null-terminated string as trace event
|
|
||||||
*/
|
|
||||||
static void trace(char const *cstring)
|
|
||||||
{
|
|
||||||
_logger()->log(cstring, strlen(cstring));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log null-terminated string as trace event using log_output policy
|
* Log null-terminated string as trace event using log_output policy
|
||||||
*
|
*
|
||||||
@ -412,7 +410,10 @@ class Genode::Thread
|
|||||||
*/
|
*/
|
||||||
static bool trace_captured(char const *cstring)
|
static bool trace_captured(char const *cstring)
|
||||||
{
|
{
|
||||||
return _logger()->log_captured(cstring, strlen(cstring));
|
bool result = false;
|
||||||
|
_with_logger([&] (Trace::Logger &l) {
|
||||||
|
result = l.log_captured(cstring, strlen(cstring)); });
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -420,13 +421,21 @@ class Genode::Thread
|
|||||||
*/
|
*/
|
||||||
static void trace(char const *data, size_t len)
|
static void trace(char const *data, size_t len)
|
||||||
{
|
{
|
||||||
_logger()->log(data, len);
|
_with_logger([&] (Trace::Logger &l) { l.log(data, len); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log null-terminated string as trace event
|
||||||
|
*/
|
||||||
|
static void trace(char const *cstring) { trace(cstring, strlen(cstring)); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log trace event as defined in base/trace/events.h
|
* Log trace event as defined in base/trace/events.h
|
||||||
*/
|
*/
|
||||||
static void trace(auto const *event) { _logger()->log(event); }
|
static void trace(auto const *event)
|
||||||
|
{
|
||||||
|
_with_logger([&] (Trace::Logger &l) { l.log(event); });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread affinity
|
* Thread affinity
|
||||||
|
Loading…
x
Reference in New Issue
Block a user