2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Implementation of the core-internal Thread API via Linux threads
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-06-13
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2006-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 <base/thread.h>
|
|
|
|
#include <base/sleep.h>
|
|
|
|
|
2016-03-11 17:32:43 +01:00
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/native_thread.h>
|
2016-06-22 16:14:18 +02:00
|
|
|
#include <base/internal/stack.h>
|
2016-03-11 17:32:43 +01:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/* Linux syscall bindings */
|
|
|
|
#include <linux_syscalls.h>
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
|
|
|
static void empty_signal_handler(int) { }
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_thread_start()
|
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
|
|
|
Thread * const thread_ptr = Thread::myself();
|
2016-06-22 16:14:18 +02:00
|
|
|
|
|
|
|
/* use primary stack as alternate stack for fatal signals (exceptions) */
|
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 *stack_base = (void *)thread_ptr->_stack->base();
|
|
|
|
size_t stack_size = thread_ptr->_stack->top() - thread_ptr->_stack->base();
|
2016-06-22 16:14:18 +02:00
|
|
|
|
|
|
|
lx_sigaltstack(stack_base, stack_size);
|
2016-04-08 18:24:15 +02:00
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/*
|
2013-01-03 13:20:24 +01:00
|
|
|
* Set signal handler such that canceled system calls get not transparently
|
|
|
|
* retried after a signal gets received.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
2016-06-22 16:14:18 +02:00
|
|
|
lx_sigaction(LX_SIGUSR1, empty_signal_handler, false);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2012-07-09 17:51:39 +02:00
|
|
|
/*
|
2013-01-03 13:20:24 +01:00
|
|
|
* Deliver SIGCHLD signals to no thread other than the main thread. Core's
|
|
|
|
* main thread will handle the signals while executing the 'wait_for_exit'
|
|
|
|
* function, which is known to not hold any locks that would interfere with
|
|
|
|
* the handling of the signal.
|
2012-07-09 17:51:39 +02:00
|
|
|
*/
|
2013-01-03 13:20:24 +01:00
|
|
|
lx_sigsetmask(LX_SIGCHLD, false);
|
2012-07-09 17:51:39 +02:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
Thread::myself()->entry();
|
|
|
|
Thread::myself()->_join_lock.unlock();
|
2011-12-22 16:19:25 +01:00
|
|
|
sleep_forever();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_init_platform_thread(size_t, Type) { }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::_deinit_platform_thread() { }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::start()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2016-05-04 12:27:17 +02:00
|
|
|
native_thread().tid = lx_create_thread(Thread::_thread_start, stack_top(), this);
|
2016-03-11 17:32:43 +01:00
|
|
|
native_thread().pid = lx_getpid();
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
void Thread::cancel_blocking() { }
|