2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Thread facility
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Sebastian Sumpf
|
2012-08-01 16:16:51 +02:00
|
|
|
* \author Alexander Boettcher
|
2011-12-22 16:19:25 +01:00
|
|
|
* \date 2009-10-02
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2009-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
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
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
|
|
|
|
|
|
|
/* core includes */
|
2015-06-19 14:58:18 +02:00
|
|
|
#include <ipc_pager.h>
|
2016-11-04 13:01:09 +01:00
|
|
|
#include <platform.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <platform_thread.h>
|
|
|
|
#include <platform_pd.h>
|
|
|
|
#include <util.h>
|
|
|
|
#include <nova_util.h>
|
|
|
|
|
2016-03-03 17:57:29 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/stack_area.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/* NOVA includes */
|
|
|
|
#include <nova/syscalls.h>
|
2012-08-24 10:25:24 +02:00
|
|
|
#include <nova/util.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
2016-11-30 19:36:32 +01:00
|
|
|
|
|
|
|
static uint8_t map_thread_portals(Pager_object &pager,
|
|
|
|
addr_t const target_exc_base,
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Nova::Utcb &utcb)
|
2016-11-30 19:36:32 +01:00
|
|
|
{
|
|
|
|
using Nova::Obj_crd;
|
|
|
|
using Nova::NUM_INITIAL_PT_LOG2;
|
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
addr_t const source_pd = platform_specific().core_pd_sel();
|
2016-11-30 19:36:32 +01:00
|
|
|
addr_t const source_exc_base = pager.exc_pt_sel_client();
|
|
|
|
addr_t const target_pd = pager.pd_sel();
|
|
|
|
|
|
|
|
/* xxx better map portals with solely pt_call and sm separately ? xxx */
|
|
|
|
addr_t const rights = Obj_crd::RIGHT_EC_RECALL |
|
2018-05-13 12:08:32 +02:00
|
|
|
Obj_crd::RIGHT_PT_CTRL | Obj_crd::RIGHT_PT_CALL | Obj_crd::RIGHT_PT_XCPU |
|
2016-11-30 19:36:32 +01:00
|
|
|
Obj_crd::RIGHT_SM_UP | Obj_crd::RIGHT_SM_DOWN;
|
|
|
|
|
|
|
|
Obj_crd const source_initial_caps(source_exc_base, NUM_INITIAL_PT_LOG2,
|
|
|
|
rights);
|
|
|
|
Obj_crd const target_initial_caps(target_exc_base, NUM_INITIAL_PT_LOG2,
|
|
|
|
rights);
|
|
|
|
|
|
|
|
return async_map(pager, source_pd, target_pd,
|
|
|
|
source_initial_caps, target_initial_caps, utcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/*********************
|
|
|
|
** Platform thread **
|
|
|
|
*********************/
|
|
|
|
|
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 Platform_thread::affinity(Affinity::Location)
|
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
|
|
|
error("dynamic affinity change not supported on NOVA");
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-11 23:05:02 +02:00
|
|
|
Affinity::Location Platform_thread::affinity() const { return _location; }
|
2013-07-09 15:58:06 +02:00
|
|
|
|
|
|
|
|
2012-08-22 12:10:04 +02:00
|
|
|
int Platform_thread::start(void *ip, void *sp)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
using namespace Nova;
|
|
|
|
|
|
|
|
if (!_pager) {
|
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
|
|
|
error("pager undefined");
|
2011-12-22 16:19:25 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
if (!_pd || (main_thread() && !vcpu() &&
|
2015-10-16 20:26:13 +02:00
|
|
|
_pd->parent_pt_sel() == Native_thread::INVALID_INDEX)) {
|
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
|
|
|
error("protection domain undefined");
|
2012-08-08 17:12:10 +02:00
|
|
|
return -2;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Utcb &utcb = *reinterpret_cast<Utcb *>(Thread::myself()->utcb());
|
|
|
|
unsigned const kernel_cpu_id = platform_specific().kernel_cpu_id(_location.xpos());
|
|
|
|
addr_t const source_pd = platform_specific().core_pd_sel();
|
2016-11-24 21:57:33 +01:00
|
|
|
|
2015-06-09 19:33:53 +02:00
|
|
|
addr_t const pt_oom = _pager->get_oom_portal();
|
2018-06-29 14:04:32 +02:00
|
|
|
if (!pt_oom || map_local(source_pd, utcb,
|
2015-06-09 19:33:53 +02:00
|
|
|
Obj_crd(pt_oom, 0), Obj_crd(_sel_pt_oom(), 0))) {
|
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
|
|
|
error("setup of out-of-memory notification portal - failed");
|
2015-06-09 19:33:53 +02:00
|
|
|
return -8;
|
|
|
|
}
|
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
if (!main_thread()) {
|
2015-06-09 19:33:53 +02:00
|
|
|
addr_t const initial_sp = reinterpret_cast<addr_t>(sp);
|
2016-11-24 21:57:33 +01:00
|
|
|
addr_t const utcb_addr = vcpu() ? 0 : round_page(initial_sp);
|
2012-08-08 17:12:10 +02:00
|
|
|
|
2012-08-23 11:02:31 +02:00
|
|
|
if (_sel_exc_base == Native_thread::INVALID_INDEX) {
|
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
|
|
|
error("exception base not specified");
|
2012-08-08 17:12:10 +02:00
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
2016-11-30 19:36:32 +01:00
|
|
|
uint8_t res = syscall_retry(*_pager,
|
|
|
|
[&]() {
|
|
|
|
return create_ec(_sel_ec(), _pd->pd_sel(), kernel_cpu_id,
|
|
|
|
utcb_addr, initial_sp, _sel_exc_base,
|
|
|
|
!worker());
|
|
|
|
});
|
2015-06-09 19:33:53 +02:00
|
|
|
|
2016-11-30 19:36:32 +01:00
|
|
|
if (res != Nova::NOVA_OK) {
|
|
|
|
error("creation of new thread failed ", res);
|
|
|
|
return -4;
|
|
|
|
}
|
2016-11-24 21:57:33 +01:00
|
|
|
|
2016-11-30 19:36:32 +01:00
|
|
|
if (vcpu()) {
|
|
|
|
if (!remote_pd())
|
|
|
|
res = map_pagefault_portal(*_pager, _pager->exc_pt_sel_client(),
|
|
|
|
_sel_exc_base, _pd->pd_sel(), utcb);
|
|
|
|
} else
|
|
|
|
res = map_thread_portals(*_pager, _sel_exc_base, utcb);
|
2016-11-24 21:57:33 +01:00
|
|
|
|
2016-11-30 19:36:32 +01:00
|
|
|
if (res != NOVA_OK) {
|
|
|
|
revoke(Obj_crd(_sel_ec(), 0));
|
|
|
|
error("creation of new thread/vcpu failed ", res);
|
|
|
|
return -3;
|
2016-11-24 21:57:33 +01:00
|
|
|
}
|
|
|
|
|
2016-05-17 16:13:56 +02:00
|
|
|
if (worker()) {
|
2013-09-27 14:47:11 +02:00
|
|
|
/* local/worker threads do not require a startup portal */
|
|
|
|
revoke(Obj_crd(_pager->exc_pt_sel_client() + PT_SEL_STARTUP, 0));
|
|
|
|
}
|
|
|
|
|
2012-09-28 12:24:14 +02:00
|
|
|
_pager->initial_eip((addr_t)ip);
|
|
|
|
_pager->initial_esp(initial_sp);
|
2012-08-22 12:10:04 +02:00
|
|
|
_pager->client_set_ec(_sel_ec());
|
|
|
|
|
2012-09-28 12:24:14 +02:00
|
|
|
return 0;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2016-11-24 21:57:33 +01:00
|
|
|
if (!vcpu() && _sel_exc_base != Native_thread::INVALID_INDEX) {
|
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
|
|
|
error("thread already started");
|
2013-09-23 09:07:33 +02:00
|
|
|
return -5;
|
2012-08-02 12:20:00 +02:00
|
|
|
}
|
|
|
|
|
2016-11-10 11:46:30 +01:00
|
|
|
addr_t pd_utcb = 0;
|
2013-11-14 10:35:44 +01:00
|
|
|
|
2016-05-11 18:21:47 +02:00
|
|
|
if (!vcpu()) {
|
2016-11-24 21:57:33 +01:00
|
|
|
_sel_exc_base = _pager->exc_pt_sel_client();
|
|
|
|
|
2016-03-03 17:57:29 +01:00
|
|
|
pd_utcb = stack_area_virtual_base() + stack_virtual_size() - get_page_size();
|
2013-11-14 10:35:44 +01:00
|
|
|
|
2016-11-30 19:36:32 +01:00
|
|
|
addr_t remap_src[] = { _pd->parent_pt_sel() };
|
|
|
|
addr_t remap_dst[] = { PT_SEL_PARENT };
|
2013-11-14 10:35:44 +01:00
|
|
|
|
|
|
|
/* remap exception portals for first thread */
|
|
|
|
for (unsigned i = 0; i < sizeof(remap_dst)/sizeof(remap_dst[0]); i++) {
|
2018-06-29 14:04:32 +02:00
|
|
|
if (map_local(source_pd, utcb,
|
2014-09-05 17:00:31 +02:00
|
|
|
Obj_crd(remap_src[i], 0),
|
|
|
|
Obj_crd(_sel_exc_base + remap_dst[i], 0)))
|
2013-11-14 10:35:44 +01:00
|
|
|
return -6;
|
|
|
|
}
|
2012-08-08 17:12:10 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-01-11 23:10:21 +01:00
|
|
|
/* create first thread in task */
|
2011-12-22 16:19:25 +01:00
|
|
|
enum { THREAD_GLOBAL = true };
|
2016-11-30 19:36:32 +01:00
|
|
|
uint8_t res = create_ec(_sel_ec(), _pd->pd_sel(), kernel_cpu_id,
|
|
|
|
pd_utcb, 0, vcpu() ? _sel_exc_base : 0,
|
|
|
|
THREAD_GLOBAL);
|
2012-09-28 12:24:14 +02:00
|
|
|
if (res != NOVA_OK) {
|
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
|
|
|
error("create_ec returned ", res);
|
2016-11-30 19:36:32 +01:00
|
|
|
return -7;
|
2012-08-08 17:12:10 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2012-08-22 12:10:04 +02:00
|
|
|
_pager->client_set_ec(_sel_ec());
|
2012-09-28 12:24:14 +02:00
|
|
|
_pager->initial_eip((addr_t)ip);
|
|
|
|
_pager->initial_esp((addr_t)sp);
|
2016-11-30 19:36:32 +01:00
|
|
|
|
|
|
|
if (vcpu())
|
|
|
|
_features |= REMOTE_PD;
|
|
|
|
else
|
|
|
|
res = map_thread_portals(*_pager, 0, utcb);
|
2016-11-24 21:57:33 +01:00
|
|
|
|
|
|
|
if (res == NOVA_OK) {
|
2016-11-30 19:36:32 +01:00
|
|
|
res = syscall_retry(*_pager,
|
|
|
|
[&]() {
|
|
|
|
/* let the thread run */
|
|
|
|
return create_sc(_sel_sc(), _pd->pd_sel(), _sel_ec(),
|
|
|
|
Qpd(Qpd::DEFAULT_QUANTUM, _priority));
|
|
|
|
});
|
2016-11-24 21:57:33 +01:00
|
|
|
}
|
2012-08-02 12:20:00 +02:00
|
|
|
|
2012-09-28 12:24:14 +02:00
|
|
|
if (res != NOVA_OK) {
|
2012-08-23 11:02:31 +02:00
|
|
|
_pager->client_set_ec(Native_thread::INVALID_INDEX);
|
2012-09-28 12:24:14 +02:00
|
|
|
_pager->initial_eip(0);
|
|
|
|
_pager->initial_esp(0);
|
2012-08-02 12:20:00 +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
|
|
|
error("create_sc returned ", res);
|
2016-11-30 19:36:32 +01:00
|
|
|
|
|
|
|
/* cap_selector free for _sel_ec is done in de-constructor */
|
|
|
|
revoke(Obj_crd(_sel_ec(), 0));
|
|
|
|
return -8;
|
2016-11-24 21:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_features |= SC_CREATED;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 16:13:56 +02:00
|
|
|
void Platform_thread::pause()
|
2012-08-24 09:29:54 +02:00
|
|
|
{
|
2016-05-17 16:13:56 +02:00
|
|
|
if (!_pager)
|
|
|
|
return;
|
2013-09-27 14:47:11 +02:00
|
|
|
|
2016-05-17 16:13:56 +02:00
|
|
|
_pager->client_recall(true);
|
2012-08-24 09:29:54 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
void Platform_thread::resume()
|
|
|
|
{
|
2012-08-24 10:25:24 +02:00
|
|
|
using namespace Nova;
|
|
|
|
|
2016-08-24 15:18:49 +02:00
|
|
|
if (worker() || sc_created()) {
|
|
|
|
if (_pager)
|
|
|
|
_pager->wake_up();
|
|
|
|
return;
|
2013-09-27 14:47:11 +02:00
|
|
|
}
|
2012-08-24 10:25:24 +02:00
|
|
|
|
2016-11-30 19:36:32 +01:00
|
|
|
if (!_pd || !_pager) {
|
|
|
|
error("protection domain undefined - resuming thread failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t res = syscall_retry(*_pager,
|
|
|
|
[&]() {
|
|
|
|
return create_sc(_sel_sc(), _pd->pd_sel(), _sel_ec(),
|
|
|
|
Qpd(Qpd::DEFAULT_QUANTUM, _priority));
|
|
|
|
});
|
2012-08-22 12:10:04 +02:00
|
|
|
|
2016-08-24 15:18:49 +02:00
|
|
|
if (res == NOVA_OK)
|
|
|
|
_features |= SC_CREATED;
|
|
|
|
else
|
|
|
|
error("create_sc failed ", res);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2013-01-11 23:10:21 +01:00
|
|
|
|
2012-11-12 17:48:18 +01:00
|
|
|
Thread_state Platform_thread::state()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2016-05-10 18:05:38 +02:00
|
|
|
if (!_pager) throw Cpu_thread::State_access_failed();
|
2013-09-27 14:47:11 +02:00
|
|
|
|
|
|
|
Thread_state s;
|
2014-07-15 19:05:26 +02:00
|
|
|
|
2013-09-27 14:47:11 +02:00
|
|
|
if (_pager->copy_thread_state(&s))
|
|
|
|
return s;
|
|
|
|
|
2016-05-10 18:05:38 +02:00
|
|
|
throw Cpu_thread::State_access_failed();
|
2013-01-11 23:10:21 +01:00
|
|
|
}
|
|
|
|
|
2012-08-22 12:10:04 +02:00
|
|
|
|
2012-11-12 17:48:18 +01:00
|
|
|
void Platform_thread::state(Thread_state s)
|
|
|
|
{
|
2017-02-27 19:54:03 +01:00
|
|
|
if (!_pager) throw Cpu_thread::State_access_failed();
|
2016-05-17 16:13:56 +02:00
|
|
|
|
2017-02-27 19:54:03 +01:00
|
|
|
if (!_pager->copy_thread_state(s))
|
|
|
|
throw Cpu_thread::State_access_failed();
|
2016-05-17 16:13:56 +02:00
|
|
|
|
2017-02-27 19:54:03 +01:00
|
|
|
/* the new state is transferred to the kernel by the recall handler */
|
|
|
|
_pager->client_recall(false);
|
2013-01-11 23:10:21 +01:00
|
|
|
}
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2012-08-24 10:25:24 +02:00
|
|
|
void Platform_thread::cancel_blocking()
|
|
|
|
{
|
|
|
|
if (!_pager) return;
|
|
|
|
|
2012-08-22 12:10:04 +02:00
|
|
|
_pager->client_cancel_blocking();
|
2012-08-24 10:25:24 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-01-11 23:10:21 +01:00
|
|
|
|
2016-05-17 16:13:56 +02:00
|
|
|
void Platform_thread::single_step(bool on)
|
2012-08-23 12:43:19 +02:00
|
|
|
{
|
2016-05-17 16:13:56 +02:00
|
|
|
if (!_pager) return;
|
2014-09-05 17:00:31 +02:00
|
|
|
|
2016-05-17 16:13:56 +02:00
|
|
|
_pager->single_step(on);
|
2012-08-23 12:43:19 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-05-19 20:33:36 +02:00
|
|
|
const char * Platform_thread::pd_name() const {
|
|
|
|
return _pd ? _pd->name() : "unknown"; }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2013-03-08 11:54:12 +01:00
|
|
|
|
2017-09-11 13:03:28 +02:00
|
|
|
Trace::Execution_time Platform_thread::execution_time() const
|
2015-06-11 23:05:02 +02:00
|
|
|
{
|
|
|
|
unsigned long long time = 0;
|
|
|
|
|
2016-08-24 15:18:49 +02:00
|
|
|
/* for ECs without a SC we simply return 0 */
|
|
|
|
if (!sc_created())
|
2017-09-11 13:03:28 +02:00
|
|
|
return { time, time, Nova::Qpd::DEFAULT_QUANTUM, _priority };
|
2015-09-04 17:01:23 +02:00
|
|
|
|
|
|
|
uint8_t res = Nova::sc_ctrl(_sel_sc(), time);
|
|
|
|
if (res != Nova::NOVA_OK)
|
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
|
|
|
warning("sc_ctrl failed res=", res);
|
2015-06-11 23:05:02 +02:00
|
|
|
|
2017-09-11 13:03:28 +02:00
|
|
|
return { time, time, Nova::Qpd::DEFAULT_QUANTUM, _priority };
|
2015-06-11 23:05:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
void Platform_thread::pager(Pager_object &pager)
|
2016-11-30 19:36:32 +01:00
|
|
|
{
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
_pager = &pager;
|
2016-11-30 19:36:32 +01:00
|
|
|
_pager->assign_pd(_pd->pd_sel());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-27 19:54:03 +01:00
|
|
|
void Platform_thread::thread_type(Nova_native_cpu::Thread_type thread_type,
|
|
|
|
Nova_native_cpu::Exception_base exception_base)
|
|
|
|
{
|
|
|
|
/* you can do it only once */
|
|
|
|
if (_sel_exc_base != Native_thread::INVALID_INDEX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!main_thread() || (thread_type == Nova_native_cpu::Thread_type::VCPU))
|
|
|
|
_sel_exc_base = exception_base.exception_base;
|
|
|
|
|
|
|
|
if (thread_type == Nova_native_cpu::Thread_type::LOCAL)
|
|
|
|
_features |= WORKER;
|
|
|
|
else if (thread_type == Nova_native_cpu::Thread_type::VCPU)
|
|
|
|
_features |= VCPU;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-10 18:05:38 +02:00
|
|
|
Platform_thread::Platform_thread(size_t, const char *name, unsigned prio,
|
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
|
|
|
Affinity::Location affinity, int)
|
2013-01-11 23:10:21 +01:00
|
|
|
:
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
_pd(0), _pager(0), _id_base(cap_map().insert(2)),
|
2016-04-20 21:12:57 +02:00
|
|
|
_sel_exc_base(Native_thread::INVALID_INDEX), _location(affinity),
|
2014-02-10 15:28:12 +01:00
|
|
|
_features(0),
|
2019-01-14 08:35:10 +01:00
|
|
|
_priority(scale_priority(prio, name)),
|
2016-01-23 14:42:55 +01:00
|
|
|
_name(name)
|
2019-01-14 08:35:10 +01:00
|
|
|
{ }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
Platform_thread::~Platform_thread()
|
|
|
|
{
|
2014-09-05 17:00:31 +02:00
|
|
|
if (_pager) {
|
|
|
|
/* reset pager and badge used for debug output */
|
|
|
|
_pager->reset_badge();
|
|
|
|
_pager = 0;
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
using namespace Nova;
|
|
|
|
|
2012-08-02 12:20:00 +02:00
|
|
|
/* free ec and sc caps */
|
2015-06-09 19:33:53 +02:00
|
|
|
revoke(Obj_crd(_id_base, 2));
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
cap_map().remove(_id_base, 2, false);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|