2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Test program for raising and handling region-manager faults
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2008-09-24
|
|
|
|
*
|
|
|
|
* This program starts itself as child. When started, it first determines
|
2016-11-06 14:26:34 +01:00
|
|
|
* wheather it is parent or child by requesting a RM session. Because the
|
|
|
|
* program blocks all session-creation calls for the RM service, each program
|
|
|
|
* instance can determine its parent or child role by the checking the result
|
|
|
|
* of the session creation.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2008-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
|
|
|
*/
|
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
#include <base/component.h>
|
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/child.h>
|
2015-05-05 08:50:16 +02:00
|
|
|
#include <rm_session/connection.h>
|
2017-01-30 11:35:12 +01:00
|
|
|
#include <base/attached_ram_dataspace.h>
|
2017-07-12 13:53:11 +02:00
|
|
|
#include <base/attached_rom_dataspace.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
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
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/***********
|
|
|
|
** Child **
|
|
|
|
***********/
|
|
|
|
|
2017-07-12 13:53:11 +02:00
|
|
|
enum {
|
2017-10-12 14:33:04 +02:00
|
|
|
MANAGED_ADDR = 0x10000000,
|
|
|
|
STOP_TEST = 0xdead,
|
|
|
|
READ_TEST = 0x12345,
|
|
|
|
WRITE_TEST = READ_TEST - 1,
|
|
|
|
EXEC_TEST = WRITE_TEST - 1,
|
|
|
|
SHUTDOWN = EXEC_TEST - 1
|
2017-07-12 13:53:11 +02:00
|
|
|
};
|
2011-12-22 16:19:25 +01: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
|
|
|
static char const *state_name(Region_map::State &state)
|
2017-10-12 14:33:04 +02:00
|
|
|
{
|
|
|
|
return state.type == Region_map::State::READ_FAULT ? "READ_FAULT" :
|
|
|
|
state.type == Region_map::State::WRITE_FAULT ? "WRITE_FAULT" :
|
|
|
|
state.type == Region_map::State::EXEC_FAULT ? "EXEC_FAULT" : "READY";
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
void read_at(addr_t addr)
|
|
|
|
{
|
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
|
|
|
log("perform read operation at ", Hex(addr));
|
2011-12-22 16:19:25 +01:00
|
|
|
int value = *(int *)addr;
|
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
|
|
|
log("read value ", Hex(value));
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
bool modify_at(addr_t addr)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2017-07-12 13:53:11 +02:00
|
|
|
addr_t const value = *(addr_t volatile *)addr;
|
|
|
|
|
|
|
|
if (value == STOP_TEST)
|
|
|
|
return false;
|
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
if (value != READ_TEST + 1) {
|
|
|
|
addr_t value_mod = ++(*(addr_t volatile *)(addr));
|
|
|
|
|
|
|
|
/* if we are get told to stop, do so */
|
|
|
|
if (*(addr_t volatile *)(addr + sizeof(addr)) == STOP_TEST)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
log("modify memory at ", Hex(addr), " from ",
|
|
|
|
Hex(value), " to ", Hex(value_mod));
|
|
|
|
}
|
2017-07-12 13:53:11 +02:00
|
|
|
|
|
|
|
if (value != READ_TEST && value != READ_TEST + 1)
|
|
|
|
{
|
|
|
|
Genode::error("could modify ROM !!! ", Hex(value));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
struct Exec_faulter : Thread
|
|
|
|
{
|
|
|
|
enum { FAULT_ON_ADDR, FAULT_ON_STACK };
|
|
|
|
|
|
|
|
unsigned _fault_test;
|
|
|
|
|
|
|
|
Exec_faulter(Env &env, unsigned test)
|
|
|
|
: Thread(env, "exec_fault", 1024 * sizeof(addr_t)), _fault_test(test)
|
|
|
|
{ }
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override
|
2017-10-12 14:33:04 +02:00
|
|
|
{
|
|
|
|
if (_fault_test == FAULT_ON_ADDR) {
|
|
|
|
addr_t volatile * value = (addr_t volatile *)MANAGED_ADDR;
|
|
|
|
*value = 0x0b0f9090; /* nop, nop, ud2 */
|
|
|
|
|
|
|
|
void (*exec_fault)(void) = (void (*)(void))MANAGED_ADDR;
|
|
|
|
exec_fault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_fault_test == FAULT_ON_STACK) {
|
|
|
|
unsigned long dummy = 0x0b0f9090; /* nop, nop, ud2 */
|
|
|
|
|
|
|
|
void (*exec_fault)(void) = (void (*)(void))&dummy;
|
|
|
|
exec_fault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void execute_at(Genode::Env &env, Attached_rom_dataspace &config, addr_t cmd_addr)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2017-10-12 14:33:04 +02:00
|
|
|
addr_t volatile * cmd = (addr_t volatile *)cmd_addr;
|
|
|
|
|
|
|
|
if (config.xml().attribute_value("executable_fault_test", true)) {
|
|
|
|
/* perform illegal execute access on cmd addr */
|
|
|
|
Exec_faulter fault_on_managed_addr(env, Exec_faulter::FAULT_ON_ADDR);
|
|
|
|
fault_on_managed_addr.start();
|
|
|
|
|
|
|
|
/* wait until parent acknowledged fault */
|
|
|
|
while (*cmd != STOP_TEST) { }
|
|
|
|
|
|
|
|
/* tell parent that we start with next EXEC_TEST */
|
|
|
|
*cmd = EXEC_TEST;
|
|
|
|
|
|
|
|
Exec_faulter fault_on_stack(env, Exec_faulter::FAULT_ON_STACK);
|
|
|
|
fault_on_stack.start();
|
|
|
|
|
|
|
|
/* wait until parent acknowledged fault */
|
|
|
|
while (*cmd == EXEC_TEST) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
log("\n--- child role of region-manager fault test finished ---");
|
|
|
|
|
|
|
|
/* sync shutdown with parent */
|
|
|
|
*cmd = SHUTDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main_child(Env &env)
|
|
|
|
{
|
|
|
|
Attached_rom_dataspace config { env, "config" };
|
|
|
|
|
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
|
|
|
log("child role started");
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
/* perform illegal read access */
|
2011-12-22 16:19:25 +01:00
|
|
|
read_at(MANAGED_ADDR);
|
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
/* perform illegal write access */
|
|
|
|
while (modify_at(MANAGED_ADDR));
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
/* perform illegal execute access */
|
|
|
|
execute_at(env, config, MANAGED_ADDR);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************
|
|
|
|
** Parent **
|
|
|
|
************/
|
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
class Test_child_policy : public Child_policy
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2016-11-06 14:26:34 +01:00
|
|
|
public:
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
typedef Registered<Genode::Parent_service> Parent_service;
|
|
|
|
typedef Registry<Parent_service> Parent_services;
|
2016-04-20 21:12:57 +02:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
private:
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
Env &_env;
|
|
|
|
Parent_services &_parent_services;
|
|
|
|
Signal_context_capability const _fault_handler_sigh;
|
2017-10-12 14:33:04 +02:00
|
|
|
Signal_context_capability const _fault_handler_stack_sigh;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2019-01-30 17:53:16 +01:00
|
|
|
Service &_matching_service(Service::Name const &name)
|
|
|
|
{
|
|
|
|
Service *service = nullptr;
|
|
|
|
_parent_services.for_each([&] (Service &s) {
|
|
|
|
if (!service && name == s.name())
|
|
|
|
service = &s; });
|
|
|
|
|
|
|
|
if (!service)
|
|
|
|
throw Service_denied();
|
|
|
|
|
|
|
|
return *service;
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2016-11-06 14:26:34 +01:00
|
|
|
Test_child_policy(Env &env, Parent_services &parent_services,
|
2017-10-12 14:33:04 +02:00
|
|
|
Signal_context_capability fault_handler_sigh,
|
|
|
|
Signal_context_capability fault_handler_stack_sigh)
|
2011-12-22 16:19:25 +01:00
|
|
|
:
|
2016-11-06 14:26:34 +01:00
|
|
|
_env(env),
|
|
|
|
_parent_services(parent_services),
|
2017-10-12 14:33:04 +02:00
|
|
|
_fault_handler_sigh(fault_handler_sigh),
|
|
|
|
_fault_handler_stack_sigh(fault_handler_stack_sigh)
|
2016-11-06 14:26:34 +01:00
|
|
|
{ }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/****************************
|
|
|
|
** Child-policy interface **
|
|
|
|
****************************/
|
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
Name name() const override { return "rmchild"; }
|
|
|
|
|
|
|
|
Binary_name binary_name() const override { return "test-rm_fault"; }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
Capability quota accounting and trading
This patch mirrors the accounting and trading scheme that Genode employs
for physical memory to the accounting of capability allocations.
Capability quotas must now be explicitly assigned to subsystems by
specifying a 'caps=<amount>' attribute to init's start nodes.
Analogously to RAM quotas, cap quotas can be traded between clients and
servers as part of the session protocol. The capability budget of each
component is maintained by the component's corresponding PD session at
core.
At the current stage, the accounting is applied to RPC capabilities,
signal-context capabilities, and dataspace capabilities. Capabilities
that are dynamically allocated via core's CPU and TRACE service are not
yet covered. Also, the capabilities allocated by resource multiplexers
outside of core (like nitpicker) must be accounted by the respective
servers, which is not covered yet.
If a component runs out of capabilities, core's PD service prints a
warning to the log. To observe the consumption of capabilities per
component in detail, the PD service is equipped with a diagnostic
mode, which can be enabled via the 'diag' attribute in the target
node of init's routing rules. E.g., the following route enables the
diagnostic mode for the PD session of the "timer" component:
<default-route>
<service name="PD" unscoped_label="timer">
<parent diag="yes"/>
</service>
...
</default-route>
For subsystems based on a sub-init instance, init can be configured
to report the capability-quota information of its subsystems by
adding the attribute 'child_caps="yes"' to init's '<report>'
config node. Init's own capability quota can be reported by adding
the attribute 'init_caps="yes"'.
Fixes #2398
2017-05-08 21:35:43 +02:00
|
|
|
Pd_session &ref_pd() override { return _env.pd(); }
|
|
|
|
Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); }
|
2016-11-06 14:26:34 +01:00
|
|
|
|
|
|
|
void init(Pd_session &session, Pd_session_capability cap) override
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
Capability quota accounting and trading
This patch mirrors the accounting and trading scheme that Genode employs
for physical memory to the accounting of capability allocations.
Capability quotas must now be explicitly assigned to subsystems by
specifying a 'caps=<amount>' attribute to init's start nodes.
Analogously to RAM quotas, cap quotas can be traded between clients and
servers as part of the session protocol. The capability budget of each
component is maintained by the component's corresponding PD session at
core.
At the current stage, the accounting is applied to RPC capabilities,
signal-context capabilities, and dataspace capabilities. Capabilities
that are dynamically allocated via core's CPU and TRACE service are not
yet covered. Also, the capabilities allocated by resource multiplexers
outside of core (like nitpicker) must be accounted by the respective
servers, which is not covered yet.
If a component runs out of capabilities, core's PD service prints a
warning to the log. To observe the consumption of capabilities per
component in detail, the PD service is equipped with a diagnostic
mode, which can be enabled via the 'diag' attribute in the target
node of init's routing rules. E.g., the following route enables the
diagnostic mode for the PD session of the "timer" component:
<default-route>
<service name="PD" unscoped_label="timer">
<parent diag="yes"/>
</service>
...
</default-route>
For subsystems based on a sub-init instance, init can be configured
to report the capability-quota information of its subsystems by
adding the attribute 'child_caps="yes"' to init's '<report>'
config node. Init's own capability quota can be reported by adding
the attribute 'init_caps="yes"'.
Fixes #2398
2017-05-08 21:35:43 +02:00
|
|
|
session.ref_account(_env.pd_session_cap());
|
2017-05-11 20:03:28 +02:00
|
|
|
|
|
|
|
_env.pd().transfer_quota(cap, Ram_quota{1*1024*1024});
|
Capability quota accounting and trading
This patch mirrors the accounting and trading scheme that Genode employs
for physical memory to the accounting of capability allocations.
Capability quotas must now be explicitly assigned to subsystems by
specifying a 'caps=<amount>' attribute to init's start nodes.
Analogously to RAM quotas, cap quotas can be traded between clients and
servers as part of the session protocol. The capability budget of each
component is maintained by the component's corresponding PD session at
core.
At the current stage, the accounting is applied to RPC capabilities,
signal-context capabilities, and dataspace capabilities. Capabilities
that are dynamically allocated via core's CPU and TRACE service are not
yet covered. Also, the capabilities allocated by resource multiplexers
outside of core (like nitpicker) must be accounted by the respective
servers, which is not covered yet.
If a component runs out of capabilities, core's PD service prints a
warning to the log. To observe the consumption of capabilities per
component in detail, the PD service is equipped with a diagnostic
mode, which can be enabled via the 'diag' attribute in the target
node of init's routing rules. E.g., the following route enables the
diagnostic mode for the PD session of the "timer" component:
<default-route>
<service name="PD" unscoped_label="timer">
<parent diag="yes"/>
</service>
...
</default-route>
For subsystems based on a sub-init instance, init can be configured
to report the capability-quota information of its subsystems by
adding the attribute 'child_caps="yes"' to init's '<report>'
config node. Init's own capability quota can be reported by adding
the attribute 'init_caps="yes"'.
Fixes #2398
2017-05-08 21:35:43 +02:00
|
|
|
_env.pd().transfer_quota(cap, Cap_quota{20});
|
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
Region_map_client address_space(session.address_space());
|
|
|
|
address_space.fault_handler(_fault_handler_sigh);
|
2017-10-12 14:33:04 +02:00
|
|
|
|
|
|
|
Region_map_client stack_area(session.stack_area());
|
|
|
|
stack_area.fault_handler(_fault_handler_stack_sigh);
|
2016-11-06 14:26:34 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 17:53:16 +01:00
|
|
|
Route resolve_session_request(Service::Name const &name,
|
|
|
|
Session_label const &label) override
|
2016-11-06 14:26:34 +01:00
|
|
|
{
|
2019-01-30 17:53:16 +01:00
|
|
|
return Route { .service = _matching_service(name),
|
|
|
|
.label = label,
|
|
|
|
.diag = Session::Diag() };
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
struct Main_parent
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2016-11-06 14:26:34 +01:00
|
|
|
Env &_env;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
Signal_handler<Main_parent> _fault_handler {
|
|
|
|
_env.ep(), *this, &Main_parent::_handle_fault };
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
Signal_handler<Main_parent> _fault_handler_stack {
|
|
|
|
_env.ep(), *this, &Main_parent::_handle_fault_stack };
|
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
Heap _heap { _env.ram(), _env.rm() };
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
Attached_rom_dataspace _config { _env, "config" };
|
2018-11-28 15:42:37 +01:00
|
|
|
Rom_connection _binary { _env, "ld.lib.so" };
|
2017-07-12 13:53:11 +02:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
/* parent services */
|
|
|
|
struct Parent_services : Test_child_policy::Parent_services
|
|
|
|
{
|
|
|
|
Allocator &alloc;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2019-01-30 17:53:16 +01:00
|
|
|
Parent_services(Env &env, Allocator &alloc) : alloc(alloc)
|
2016-11-06 14:26:34 +01:00
|
|
|
{
|
|
|
|
static const char *names[] = {
|
2017-05-29 16:13:16 +02:00
|
|
|
"PD", "CPU", "ROM", "LOG", 0 };
|
2016-11-06 14:26:34 +01:00
|
|
|
for (unsigned i = 0; names[i]; i++)
|
2019-01-30 17:53:16 +01:00
|
|
|
new (alloc) Test_child_policy::Parent_service(*this, env, names[i]);
|
2016-11-06 14:26:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~Parent_services()
|
|
|
|
{
|
|
|
|
for_each([&] (Test_child_policy::Parent_service &s) { destroy(alloc, &s); });
|
|
|
|
}
|
2019-01-30 17:53:16 +01:00
|
|
|
} _parent_services { _env, _heap };
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* create child */
|
2017-10-12 14:33:04 +02:00
|
|
|
Test_child_policy _child_policy { _env, _parent_services, _fault_handler,
|
|
|
|
_fault_handler_stack };
|
2016-11-06 14:26:34 +01:00
|
|
|
|
|
|
|
Child _child { _env.rm(), _env.ep().rpc_ep(), _child_policy };
|
|
|
|
|
|
|
|
Region_map_client _address_space { _child.pd().address_space() };
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
/* dataspace used for creating shared memory between parent and child */
|
|
|
|
Attached_ram_dataspace _ds { _env.ram(), _env.rm(), 4096 };
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
unsigned _fault_cnt = 0;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
long volatile &_child_value() { return *_ds.local_addr<long volatile>(); }
|
2017-10-12 14:33:04 +02:00
|
|
|
long volatile &_child_stop() { return *(_ds.local_addr<long volatile>() + 1); }
|
|
|
|
|
|
|
|
void _test_read_fault(addr_t const child_virt_addr)
|
|
|
|
{
|
|
|
|
/* allocate dataspace to resolve the fault */
|
|
|
|
log("attach dataspace to the child at ", Hex(child_virt_addr));
|
|
|
|
|
|
|
|
_child_value() = READ_TEST;
|
|
|
|
|
|
|
|
_address_space.attach_at(_ds.cap(), child_virt_addr);
|
|
|
|
|
|
|
|
/* poll until our child modifies the dataspace content */
|
|
|
|
while (_child_value() == READ_TEST);
|
|
|
|
|
|
|
|
log("child modified dataspace content, new value is ",
|
|
|
|
Hex(_child_value()));
|
2016-11-06 14:26:34 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
log("revoke dataspace from child");
|
|
|
|
_address_space.detach((void *)child_virt_addr);
|
|
|
|
}
|
|
|
|
|
2018-05-08 11:21:10 +02:00
|
|
|
void _test_write_fault(addr_t const child_virt_addr, unsigned round)
|
2016-11-06 14:26:34 +01:00
|
|
|
{
|
2018-05-08 11:21:10 +02:00
|
|
|
if (_child_value() != WRITE_TEST) {
|
|
|
|
Genode::log("test WRITE faults on read-only binary and "
|
|
|
|
"read-only attached RAM");
|
2017-10-12 14:33:04 +02:00
|
|
|
|
2018-05-08 11:21:10 +02:00
|
|
|
_child_value() = WRITE_TEST;
|
2017-10-12 14:33:04 +02:00
|
|
|
|
2018-05-08 11:21:10 +02:00
|
|
|
_address_space.attach_at(_binary.dataspace(), child_virt_addr);
|
2017-07-12 13:53:11 +02:00
|
|
|
return;
|
2016-11-06 14:26:34 +01:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2018-05-08 11:21:10 +02:00
|
|
|
enum { ROUND_FAULT_ON_ROM_BINARY = 1, ROUND_FAULT_ON_RO_RAM = 2 };
|
|
|
|
|
|
|
|
if (round == ROUND_FAULT_ON_RO_RAM)
|
|
|
|
_child_stop() = STOP_TEST;
|
|
|
|
|
|
|
|
Genode::log("got write fault on ", Hex(child_virt_addr),
|
|
|
|
(round == ROUND_FAULT_ON_ROM_BINARY) ? " ROM (binary)" :
|
|
|
|
(round == ROUND_FAULT_ON_RO_RAM) ? " read-only attached RAM"
|
|
|
|
: " unknown");
|
2017-07-12 13:53:11 +02:00
|
|
|
|
2018-05-08 11:21:10 +02:00
|
|
|
/* detach region where fault happened */
|
|
|
|
_address_space.detach((void *)child_virt_addr);
|
2017-07-12 13:53:11 +02:00
|
|
|
|
2018-05-08 11:21:10 +02:00
|
|
|
if (round == ROUND_FAULT_ON_ROM_BINARY) {
|
|
|
|
/* attach a RAM dataspace read-only */
|
|
|
|
enum {
|
|
|
|
SIZE = 4096, OFFSET = 0, ATTACH_AT = true, NON_EXEC = false,
|
|
|
|
READONLY = false
|
|
|
|
};
|
|
|
|
|
|
|
|
_address_space.attach(_ds.cap(), SIZE, OFFSET, ATTACH_AT,
|
|
|
|
child_virt_addr, NON_EXEC, READONLY);
|
|
|
|
} else
|
|
|
|
if (round == ROUND_FAULT_ON_RO_RAM) {
|
|
|
|
/* let client continue by attaching RAM dataspace writeable */
|
|
|
|
_address_space.attach_at(_ds.cap(), child_virt_addr);
|
|
|
|
}
|
2017-10-12 14:33:04 +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
|
|
|
void _test_exec_fault(Region_map::State &state)
|
2017-10-12 14:33:04 +02:00
|
|
|
{
|
|
|
|
if (_child_value() == WRITE_TEST) {
|
|
|
|
_child_value() = EXEC_TEST;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.type != Region_map::State::EXEC_FAULT ||
|
|
|
|
state.addr != MANAGED_ADDR)
|
|
|
|
{
|
|
|
|
error("exec test failed ", (int)state.type,
|
|
|
|
" addr=", Hex(state.addr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log("got exec fault on dataspace");
|
|
|
|
/* signal client to continue with next test, current test is done */
|
|
|
|
_child_value() = STOP_TEST;
|
2017-07-12 13:53:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void _handle_fault()
|
|
|
|
{
|
2018-05-08 11:21:10 +02:00
|
|
|
enum { FAULT_CNT_READ = 4, FAULT_CNT_WRITE = 6 };
|
2017-07-12 13:53:11 +02:00
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
log("received region-map fault signal, request fault state");
|
|
|
|
|
|
|
|
Region_map::State state = _address_space.state();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
log("rm session state is ", state_name(state), ", pf_addr=", Hex(state.addr));
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-07-12 13:53:11 +02:00
|
|
|
/* ignore spurious fault signal */
|
2016-04-15 15:19:22 +02:00
|
|
|
if (state.type == Region_map::State::READY) {
|
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
|
|
|
log("ignoring spurious fault signal");
|
2016-11-06 14:26:34 +01:00
|
|
|
return;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addr_t child_virt_addr = state.addr & ~(4096 - 1);
|
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
if (_fault_cnt < FAULT_CNT_READ)
|
|
|
|
_test_read_fault(child_virt_addr);
|
2017-07-12 13:53:11 +02:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
if (_fault_cnt <= FAULT_CNT_WRITE && _fault_cnt >= FAULT_CNT_READ)
|
2018-05-08 11:21:10 +02:00
|
|
|
_test_write_fault(child_virt_addr, _fault_cnt - FAULT_CNT_READ);
|
2017-07-12 13:53:11 +02:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
if (!_config.xml().attribute_value("executable_fault_test", true) &&
|
|
|
|
_fault_cnt >=FAULT_CNT_WRITE)
|
|
|
|
_handle_fault_stack();
|
2017-07-12 13:53:11 +02:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
if (_fault_cnt > FAULT_CNT_WRITE)
|
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
|
|
|
_test_exec_fault(state);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
_fault_cnt++;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
void _handle_fault_stack()
|
|
|
|
{
|
|
|
|
/* sanity check that we got exec fault */
|
|
|
|
if (_config.xml().attribute_value("executable_fault_test", true)) {
|
|
|
|
Region_map::State state = _address_space.state();
|
|
|
|
if (state.type != Region_map::State::EXEC_FAULT) {
|
|
|
|
error("unexpected state ", state_name(state));
|
|
|
|
return;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
_child_value() = STOP_TEST;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2017-10-12 14:33:04 +02:00
|
|
|
/* sync shutdown with client */
|
|
|
|
while (_child_value() != SHUTDOWN) { }
|
|
|
|
|
|
|
|
log("--- parent role of region-manager fault test finished --- ");
|
|
|
|
|
|
|
|
/* done, finally */
|
|
|
|
_env.parent().exit(0);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
Main_parent(Env &env) : _env(env) { }
|
|
|
|
};
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2016-11-06 14:26:34 +01:00
|
|
|
void Component::construct(Env &env)
|
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
|
|
|
log("--- region-manager fault test ---");
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
try {
|
2016-11-06 14:26:34 +01:00
|
|
|
/*
|
|
|
|
* Distinguish parent from child by requesting an service that is only
|
|
|
|
* available to the parent.
|
|
|
|
*/
|
2017-01-05 16:19:16 +01:00
|
|
|
Rm_connection rm(env);
|
2016-11-06 14:26:34 +01:00
|
|
|
static Main_parent parent(env);
|
|
|
|
log("-- parent role started --");
|
|
|
|
}
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
catch (Service_denied) {
|
2017-10-12 14:33:04 +02:00
|
|
|
main_child(env);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
}
|