2015-04-21 17:21:11 +02:00
|
|
|
/*
|
|
|
|
* \brief Muen subject information API impl
|
|
|
|
* \author Reto Buerki
|
|
|
|
* \date 2015-04-21
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2015-2017 Genode Labs GmbH
|
2015-04-21 17:21:11 +02: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.
|
2015-04-21 17:21:11 +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
|
|
|
#include <base/log.h>
|
2016-10-04 11:56:16 +02:00
|
|
|
#include <base/snprintf.h>
|
2015-04-21 17:21:11 +02:00
|
|
|
#include <util/string.h>
|
|
|
|
|
2015-07-02 16:25:51 +02:00
|
|
|
#include <muen/sinfo.h>
|
2015-04-21 17:21:11 +02:00
|
|
|
|
2016-12-06 11:50:46 +01:00
|
|
|
#include "muschedinfo.h"
|
|
|
|
|
|
|
|
#define roundup(x, y) ( \
|
|
|
|
{ \
|
|
|
|
const typeof(y) __y = y; \
|
|
|
|
(((x) + (__y - 1)) / __y) * __y; \
|
|
|
|
})
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
using namespace Genode;
|
2015-04-21 17:21:11 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
static_assert(sizeof(Sinfo::Subject_info_type) <= Sinfo::SIZE,
|
|
|
|
"Size of subject info type larger than Sinfo::SIZE.");
|
2015-04-21 17:21:11 +02:00
|
|
|
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2016-10-04 11:56:16 +02:00
|
|
|
static const char * const content_names[] = {
|
|
|
|
"uninitialized", "fill", "file",
|
|
|
|
};
|
|
|
|
|
|
|
|
uint8_t no_hash[Sinfo::HASH_LENGTH] = {0};
|
|
|
|
|
|
|
|
/* Return true if given buffer contains a hash */
|
|
|
|
static bool hash_available(const uint8_t * const first)
|
|
|
|
{
|
|
|
|
return memcmp(first, no_hash, Sinfo::HASH_LENGTH) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
static bool names_equal(const struct Sinfo::Name_type *const n1,
|
|
|
|
const char *const n2)
|
|
|
|
{
|
|
|
|
return n1->length == strlen(n2) && strcmp(n1->data, n2) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-04 11:56:16 +02:00
|
|
|
/* Convert given hash to hex string */
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
static char *hash_to_hex(char *buffer, const unsigned char *first)
|
2016-10-04 11:56:16 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < Sinfo::HASH_LENGTH; i++)
|
|
|
|
snprintf(&buffer[i * 2], 3, "%02x", (unsigned int)*first++);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
static bool log_resource(const struct Sinfo::Resource_type *const res, void *)
|
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
|
|
|
{
|
2016-10-04 11:56:16 +02:00
|
|
|
char hash_str[65];
|
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
switch (res->kind) {
|
|
|
|
case Sinfo::RES_MEMORY:
|
|
|
|
Genode::log("muen-sinfo: memory [",
|
|
|
|
content_names[res->data.mem.content],
|
|
|
|
", addr ", Genode::Hex(res->data.mem.address),
|
|
|
|
" size ", Genode::Hex(res->data.mem.size), " ",
|
|
|
|
res->data.mem.flags & Sinfo::MEM_WRITABLE_FLAG ? "rw" : "ro",
|
|
|
|
res->data.mem.flags & Sinfo::MEM_EXECUTABLE_FLAG ? "x" : "-",
|
|
|
|
res->data.mem.flags & Sinfo::MEM_CHANNEL_FLAG ? "c" : "-",
|
|
|
|
"] ", res->name.data);
|
|
|
|
|
|
|
|
if (res->data.mem.content == Sinfo::CONTENT_FILL)
|
|
|
|
Genode::log("muen-sinfo: [pattern ", res->data.mem.pattern, "]");
|
|
|
|
|
|
|
|
if (hash_available(res->data.mem.hash))
|
|
|
|
Genode::log("muen-sinfo: [hash 0x",
|
|
|
|
Genode::Cstring(hash_to_hex(hash_str, res->data.mem.hash)),
|
|
|
|
"]");
|
|
|
|
break;
|
|
|
|
case Sinfo::RES_DEVICE:
|
|
|
|
Genode::log("muen-sinfo: device [sid ", Genode::Hex(res->data.dev.sid),
|
|
|
|
" IRTE/IRQ start ", res->data.dev.irte_start,
|
|
|
|
"/", res->data.dev.irq_start,
|
|
|
|
" IR count ", res->data.dev.ir_count,
|
|
|
|
" flags ", res->data.dev.flags, "] ", res->name.data);
|
|
|
|
break;
|
|
|
|
case Sinfo::RES_EVENT:
|
|
|
|
Genode::log("muen-sinfo: event [number ", res->data.number, "] ", res->name.data);
|
|
|
|
break;
|
|
|
|
case Sinfo::RES_VECTOR:
|
|
|
|
Genode::log("muen-sinfo: vector [number ", res->data.number, "] ", res->name.data);
|
|
|
|
break;
|
|
|
|
case Sinfo::RES_NONE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Genode::log("muen-sinfo: UNKNOWN resource at address %p\n",
|
|
|
|
res);
|
|
|
|
break;
|
|
|
|
}
|
2016-10-04 11:56:16 +02:00
|
|
|
|
2015-04-21 17:21:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2015-07-02 16:25:51 +02:00
|
|
|
Sinfo::Sinfo(const addr_t base_addr)
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
:
|
2018-03-27 14:46:26 +02:00
|
|
|
sinfo((Subject_info_type *)base_addr)
|
2016-02-16 17:08:14 +01:00
|
|
|
{
|
2018-03-27 14:46:26 +02:00
|
|
|
const uint64_t sinfo_page_size = roundup(sizeof(Subject_info_type), 0x1000);
|
|
|
|
sched_info = ((Scheduling_info_type *)(base_addr + sinfo_page_size));
|
2016-02-16 17:08:14 +01:00
|
|
|
|
2015-04-21 17:21:11 +02:00
|
|
|
if (!check_magic()) {
|
2019-04-05 13:50:34 +02:00
|
|
|
Genode::warning("muen-sinfo: Subject information MAGIC mismatch");
|
2015-04-21 17:21:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
bool Sinfo::check_magic(void) const
|
2015-04-21 17:21:11 +02:00
|
|
|
{
|
|
|
|
return sinfo != 0 && sinfo->magic == MUEN_SUBJECT_INFO_MAGIC;
|
|
|
|
}
|
|
|
|
|
2015-06-02 12:11:50 +02:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
const char * Sinfo::get_subject_name(void)
|
2016-10-25 19:18:24 +02:00
|
|
|
{
|
|
|
|
if (!check_magic())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (!subject_name_set)
|
|
|
|
{
|
|
|
|
memset(subject_name, 0, MAX_NAME_LENGTH + 1);
|
|
|
|
memcpy(subject_name, &sinfo->name.data, sinfo->name.length);
|
|
|
|
subject_name_set = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return subject_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
bool Sinfo::iterate_resources(struct iterator *const iter) const
|
2015-04-21 17:21:11 +02:00
|
|
|
{
|
2018-03-27 14:46:26 +02:00
|
|
|
if (!iter->res) {
|
|
|
|
iter->res = &sinfo->resources[0];
|
|
|
|
iter->idx = 0;
|
|
|
|
} else {
|
|
|
|
iter->res++;
|
|
|
|
iter->idx++;
|
2015-04-21 17:21:11 +02:00
|
|
|
}
|
2018-03-27 14:46:26 +02:00
|
|
|
return iter->idx < sinfo->resource_count
|
|
|
|
&& iter->res->kind != RES_NONE;
|
2015-04-21 17:21:11 +02:00
|
|
|
}
|
|
|
|
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
const struct Sinfo::Resource_type *
|
|
|
|
Sinfo::get_resource(const char *const name, enum Resource_kind kind) const
|
2015-04-21 17:21:11 +02:00
|
|
|
{
|
2018-03-27 14:46:26 +02:00
|
|
|
struct iterator i = { nullptr, 0 };
|
2015-04-21 17:21:11 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
while (iterate_resources(&i))
|
|
|
|
if (i.res->kind == kind && names_equal(&i.res->name, name))
|
|
|
|
return i.res;
|
|
|
|
|
|
|
|
return nullptr;
|
2015-04-21 17:21:11 +02:00
|
|
|
}
|
|
|
|
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
const struct Sinfo::Device_type * Sinfo::get_device(const uint16_t sid) const
|
2016-02-16 17:08:14 +01:00
|
|
|
{
|
2018-03-27 14:46:26 +02:00
|
|
|
struct iterator i = { nullptr, 0 };
|
2016-02-16 17:08:14 +01:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
while (iterate_resources(&i))
|
|
|
|
if (i.res->kind == RES_DEVICE && i.res->data.dev.sid == sid)
|
|
|
|
return &i.res->data.dev;
|
2016-02-16 17:08:14 +01:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
return nullptr;
|
2016-02-16 17:08:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
bool Sinfo::for_each_resource(resource_cb func, void *data) const
|
2015-04-21 17:21:11 +02:00
|
|
|
{
|
2018-03-27 14:46:26 +02:00
|
|
|
struct iterator i = { nullptr, 0 };
|
2015-04-21 17:21:11 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
while (iterate_resources(&i))
|
|
|
|
if (!func(i.res, data))
|
|
|
|
return 0;
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
return 1;
|
2015-04-21 17:21:11 +02:00
|
|
|
}
|
|
|
|
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
uint64_t Sinfo::get_tsc_khz(void) const
|
2015-04-21 17:21:11 +02:00
|
|
|
{
|
|
|
|
if (!check_magic())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return sinfo->tsc_khz;
|
|
|
|
}
|
|
|
|
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
uint64_t Sinfo::get_sched_start(void) const
|
2015-04-21 17:21:11 +02:00
|
|
|
{
|
|
|
|
if (!check_magic())
|
|
|
|
return 0;
|
|
|
|
|
2016-12-06 11:50:46 +01:00
|
|
|
return sched_info->tsc_schedule_start;
|
2015-04-21 17:21:11 +02:00
|
|
|
}
|
|
|
|
|
2015-06-02 12:11:50 +02:00
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
uint64_t Sinfo::get_sched_end(void) const
|
2015-04-21 17:21:11 +02:00
|
|
|
{
|
|
|
|
if (!check_magic())
|
|
|
|
return 0;
|
|
|
|
|
2016-12-06 11:50:46 +01:00
|
|
|
return sched_info->tsc_schedule_end;
|
2015-04-21 17:21:11 +02:00
|
|
|
}
|
2015-07-02 16:25:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
void Sinfo::log_status()
|
|
|
|
{
|
|
|
|
if (!sinfo) {
|
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::log("Sinfo API not initialized");
|
2015-07-02 16:25:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!check_magic()) {
|
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::log("Sinfo MAGIC not found");
|
2015-07-02 16:25:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-27 14:46:26 +02:00
|
|
|
const uint16_t count = sinfo->resource_count;
|
|
|
|
|
2016-10-25 19:18:24 +02:00
|
|
|
Genode::log("muen-sinfo: Subject name is '",
|
|
|
|
Sinfo::get_subject_name(), "'");
|
2018-03-27 14:46:26 +02:00
|
|
|
Genode::log("muen-sinfo: Subject exports ", count, " resources");
|
|
|
|
for_each_resource(log_resource, nullptr);
|
2015-07-02 16:25:51 +02:00
|
|
|
}
|