2014-04-28 21:31:57 +02:00
|
|
|
/*
|
|
|
|
* \brief Implementation of Thread API interface for core
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \author Martin Stein
|
|
|
|
* \date 2014-02-27
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2014-04-28 21:31:57 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2014-04-28 21:31:57 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/thread.h>
|
|
|
|
#include <base/sleep.h>
|
|
|
|
#include <base/env.h>
|
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/* base-internal stack */
|
|
|
|
#include <base/internal/stack.h>
|
2016-03-08 16:59:43 +01:00
|
|
|
#include <base/internal/native_utcb.h>
|
2016-01-23 14:42:55 +01:00
|
|
|
|
2014-04-28 21:31:57 +02:00
|
|
|
/* core includes */
|
2019-09-26 14:24:28 +02:00
|
|
|
#include "map_local.h"
|
|
|
|
#include "kernel/kernel.h"
|
2014-04-28 21:31:57 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include <platform_thread.h>
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
namespace Hw { extern Untyped_capability _main_thread_cap; }
|
2014-04-28 21:31:57 +02:00
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::start()
|
2014-04-28 21:31:57 +02:00
|
|
|
{
|
|
|
|
/* start thread with stack pointer at the top of stack */
|
2016-03-11 17:32:43 +01:00
|
|
|
if (native_thread().platform_thread->start((void *)&_thread_start, stack_top()))
|
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("failed to start thread");
|
2014-04-28 21:31:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::cancel_blocking()
|
2014-04-28 21:31:57 +02:00
|
|
|
{
|
2016-03-11 17:32:43 +01:00
|
|
|
native_thread().platform_thread->cancel_blocking();
|
2014-04-28 21:31:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_deinit_platform_thread()
|
2014-04-28 21:31:57 +02:00
|
|
|
{
|
|
|
|
/* destruct 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
|
|
|
destroy(platform().core_mem_alloc(), native_thread().platform_thread);
|
2014-04-28 21:31:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_init_platform_thread(size_t, Type type)
|
2014-04-28 21:31:57 +02:00
|
|
|
{
|
2015-03-09 15:00:58 +01:00
|
|
|
if (type == NORMAL) {
|
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
|
|
|
native_thread().platform_thread = new (platform().core_mem_alloc())
|
|
|
|
Platform_thread(_stack->name(), _stack->utcb());
|
2015-03-09 15:00:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/* remap initial main-thread UTCB according to stack-area spec */
|
2016-11-07 18:00:24 +01:00
|
|
|
Genode::map_local(Platform::core_phys_addr((addr_t)Kernel::Core_thread::singleton().utcb()),
|
2016-01-23 14:42:55 +01:00
|
|
|
(addr_t)&_stack->utcb(),
|
2015-03-17 11:47:25 +01:00
|
|
|
max(sizeof(Native_utcb) / get_page_size(), (size_t)1));
|
|
|
|
|
2015-03-09 15:00:58 +01:00
|
|
|
/* adjust initial object state in case of a main thread */
|
2016-06-15 15:04:54 +02:00
|
|
|
native_thread().cap = Hw::_main_thread_cap;
|
2014-04-28 21:31:57 +02:00
|
|
|
}
|