2012-05-30 20:13:09 +02:00
|
|
|
/**
|
2014-07-09 12:03:17 +02:00
|
|
|
* \brief Implementations for the start of a thread
|
2012-05-30 20:13:09 +02:00
|
|
|
* \author Martin Stein
|
2014-04-28 21:31:57 +02:00
|
|
|
* \author Stefan Kalkowski
|
2012-05-30 20:13:09 +02:00
|
|
|
* \date 2012-02-12
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2012-2013 Genode Labs GmbH
|
2012-05-30 20:13:09 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/thread.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>
|
2012-05-30 20:13:09 +02:00
|
|
|
#include <base/sleep.h>
|
|
|
|
#include <base/env.h>
|
2016-05-10 18:05:38 +02:00
|
|
|
#include <cpu_thread/client.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/stack_allocator.h>
|
2016-03-08 16:59:43 +01:00
|
|
|
#include <base/internal/native_utcb.h>
|
2016-04-29 22:58:59 +02:00
|
|
|
#include <base/internal/globals.h>
|
2016-01-23 14:42:55 +01:00
|
|
|
|
2012-05-30 20:13:09 +02:00
|
|
|
using namespace Genode;
|
|
|
|
|
2015-05-19 14:18:40 +02:00
|
|
|
namespace Hw {
|
|
|
|
extern Ram_dataspace_capability _main_thread_utcb_ds;
|
|
|
|
extern Untyped_capability _main_thread_cap;
|
|
|
|
}
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
/************
|
|
|
|
** Thread **
|
|
|
|
************/
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_init_platform_thread(size_t weight, Type type)
|
2012-05-30 20:13:09 +02:00
|
|
|
{
|
2017-01-09 15:18:49 +01:00
|
|
|
if (!_cpu_session) { _cpu_session = env_deprecated()->cpu_session(); }
|
2014-05-21 17:59:12 +02:00
|
|
|
if (type == NORMAL) {
|
|
|
|
|
|
|
|
/* create server object */
|
2016-01-23 14:42:55 +01:00
|
|
|
addr_t const utcb = (addr_t)&_stack->utcb();
|
2017-01-09 15:18:49 +01:00
|
|
|
_thread_cap = _cpu_session->create_thread(env_deprecated()->pd_session_cap(),
|
2016-05-04 12:27:17 +02:00
|
|
|
name(), _affinity,
|
|
|
|
Weight(weight), utcb);
|
2014-05-21 17:59:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-04-28 21:31:57 +02:00
|
|
|
/* if we got reinitialized we have to get rid of the old UTCB */
|
2016-01-23 14:42:55 +01:00
|
|
|
size_t const utcb_size = sizeof(Native_utcb);
|
2016-03-03 17:57:29 +01:00
|
|
|
addr_t const stack_area = stack_area_virtual_base();
|
2016-01-23 14:42:55 +01:00
|
|
|
addr_t const utcb_new = (addr_t)&_stack->utcb() - stack_area;
|
2016-04-15 15:19:22 +02:00
|
|
|
Region_map * const rm = env_stack_area_region_map;
|
2016-01-23 14:42:55 +01:00
|
|
|
|
2014-04-28 21:31:57 +02:00
|
|
|
if (type == REINITIALIZED_MAIN) { rm->detach(utcb_new); }
|
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/* remap initial main-thread UTCB according to stack-area spec */
|
2015-05-19 14:18:40 +02:00
|
|
|
try { rm->attach_at(Hw::_main_thread_utcb_ds, utcb_new, utcb_size); }
|
2014-04-28 21:31:57 +02:00
|
|
|
catch(...) {
|
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 re-map UTCB");
|
2014-04-28 21:31:57 +02:00
|
|
|
while (1) ;
|
|
|
|
}
|
|
|
|
/* adjust initial object state in case of a main thread */
|
2016-03-11 17:32:43 +01:00
|
|
|
native_thread().cap = Hw::_main_thread_cap;
|
2017-01-09 15:18:49 +01:00
|
|
|
_thread_cap = env_deprecated()->parent()->main_thread_cap();
|
2012-05-30 20:13:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_deinit_platform_thread()
|
2012-05-30 20:13:09 +02:00
|
|
|
{
|
2014-04-28 21:31:57 +02:00
|
|
|
if (!_cpu_session)
|
2017-01-09 15:18:49 +01:00
|
|
|
_cpu_session = env_deprecated()->cpu_session();
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2014-04-28 21:31:57 +02:00
|
|
|
_cpu_session->kill_thread(_thread_cap);
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
/* detach userland stack */
|
|
|
|
size_t const size = sizeof(_stack->utcb());
|
|
|
|
addr_t utcb = Stack_allocator::addr_to_base(_stack) +
|
2016-03-03 17:57:29 +01:00
|
|
|
stack_virtual_size() - size - stack_area_virtual_base();
|
2016-04-15 15:19:22 +02:00
|
|
|
env_stack_area_region_map->detach(utcb);
|
2012-10-09 15:41:40 +02:00
|
|
|
}
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::start()
|
2012-05-30 20:13:09 +02:00
|
|
|
{
|
2016-01-23 14:42:55 +01:00
|
|
|
/* attach userland stack */
|
2012-05-30 20:13:09 +02:00
|
|
|
try {
|
2016-05-10 18:05:38 +02:00
|
|
|
Dataspace_capability ds = Cpu_thread_client(_thread_cap).utcb();
|
2016-01-23 14:42:55 +01:00
|
|
|
size_t const size = sizeof(_stack->utcb());
|
|
|
|
addr_t dst = Stack_allocator::addr_to_base(_stack) +
|
2016-03-03 17:57:29 +01:00
|
|
|
stack_virtual_size() - size - stack_area_virtual_base();
|
2016-04-15 15:19:22 +02:00
|
|
|
env_stack_area_region_map->attach_at(ds, dst, size);
|
2012-05-30 20:13:09 +02:00
|
|
|
} catch (...) {
|
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 attach userland stack");
|
2012-05-30 20:13:09 +02:00
|
|
|
sleep_forever();
|
|
|
|
}
|
|
|
|
/* start thread with its initial IP and aligned SP */
|
2016-05-10 18:05:38 +02:00
|
|
|
Cpu_thread_client(_thread_cap).start((addr_t)_thread_start, _stack->top());
|
2012-05-30 20:13:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::cancel_blocking()
|
2013-09-18 23:40:38 +02:00
|
|
|
{
|
2016-05-10 18:05:38 +02:00
|
|
|
Cpu_thread_client(_thread_cap).cancel_blocking();
|
2013-09-18 23:40:38 +02:00
|
|
|
}
|