2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Linux-specific platform thread implementation
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2007-10-15
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2007-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 */
|
|
|
|
#include <util/token.h>
|
|
|
|
#include <util/misc_math.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
|
|
|
|
|
|
|
/* local includes */
|
|
|
|
#include "platform_thread.h"
|
2012-08-10 16:35:57 +02:00
|
|
|
#include "server_socket_pair.h"
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
|
|
|
typedef Token<Scanner_policy_identifier_with_underline> Tid_token;
|
|
|
|
|
|
|
|
|
2013-01-03 16:23:11 +01:00
|
|
|
/*******************************
|
|
|
|
** Platform_thread::Registry **
|
|
|
|
*******************************/
|
|
|
|
|
|
|
|
void Platform_thread::Registry::insert(Platform_thread *thread)
|
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
_list.insert(thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Platform_thread::Registry::remove(Platform_thread *thread)
|
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
_list.remove(thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Platform_thread::Registry::submit_exception(unsigned long pid)
|
|
|
|
{
|
|
|
|
Lock::Guard guard(_lock);
|
|
|
|
|
|
|
|
/* traverse list to find 'Platform_thread' with matching PID */
|
|
|
|
for (Platform_thread *curr = _list.first(); curr; curr = curr->next()) {
|
|
|
|
|
|
|
|
if (curr->_tid == pid) {
|
|
|
|
Signal_context_capability sigh = curr->_pager._sigh;
|
|
|
|
|
|
|
|
if (sigh.valid())
|
|
|
|
Signal_transmitter(sigh).submit();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
Platform_thread::Registry &Platform_thread::_registry()
|
2013-01-03 16:23:11 +01:00
|
|
|
{
|
|
|
|
static Platform_thread::Registry registry;
|
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
|
|
|
return registry;
|
2013-01-03 16:23:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
** Platform_thread **
|
|
|
|
*********************/
|
|
|
|
|
2016-04-20 21:12:57 +02:00
|
|
|
Platform_thread::Platform_thread(size_t, const char *name, unsigned,
|
|
|
|
Affinity::Location, addr_t)
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2013-05-21 11:34:35 +02:00
|
|
|
strncpy(_name, name, min(sizeof(_name), strlen(name) + 1));
|
2013-01-03 16:23:11 +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
|
|
|
_registry().insert(this);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-05 17:23:50 +01:00
|
|
|
Platform_thread::~Platform_thread()
|
|
|
|
{
|
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
|
|
|
ep_sd_registry().disassociate(_socket_pair.client_sd);
|
2012-11-05 17:23:50 +01:00
|
|
|
|
2016-03-18 22:53:25 +01:00
|
|
|
if (_socket_pair.client_sd)
|
|
|
|
lx_close(_socket_pair.client_sd);
|
2012-11-05 17:23:50 +01:00
|
|
|
|
2016-03-18 22:53:25 +01:00
|
|
|
if (_socket_pair.server_sd)
|
|
|
|
lx_close(_socket_pair.server_sd);
|
2013-01-03 16:23:11 +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
|
|
|
_registry().remove(this);
|
2012-11-05 17:23:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
void Platform_thread::cancel_blocking()
|
|
|
|
{
|
|
|
|
lx_tgkill(_pid, _tid, LX_SIGUSR1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Platform_thread::pause()
|
|
|
|
{
|
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(__func__, "not implemented");
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Platform_thread::resume()
|
|
|
|
{
|
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(__func__, "not implemented");
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
2012-08-09 16:52:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
int Platform_thread::client_sd()
|
|
|
|
{
|
|
|
|
/* construct socket pair on first call */
|
2016-03-18 22:53:25 +01:00
|
|
|
if (_socket_pair.client_sd == -1)
|
|
|
|
_socket_pair = create_server_socket_pair(_tid);
|
2012-08-09 16:52:47 +02:00
|
|
|
|
2016-03-18 22:53:25 +01:00
|
|
|
return _socket_pair.client_sd;
|
2012-08-09 16:52:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Platform_thread::server_sd()
|
|
|
|
{
|
|
|
|
client_sd();
|
2016-03-18 22:53:25 +01:00
|
|
|
return _socket_pair.server_sd;
|
2012-08-09 16:52:47 +02:00
|
|
|
}
|