From 02c16e710668736a0e49a0cb5cd5a49bacaaa70c Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Tue, 25 Mar 2014 16:34:20 +0100 Subject: [PATCH] hw: split resume_local_thread from resume_thread Kernel::resume_thread was restricted to core when the targeted thread was in another domain. Now there are two kernel calls, resume_local_thread and resume_thread, where the former is never restricted and is provided via public kernel/interface.h and the latter is always restricted to core and is provided via core-local kernel/core_interface.h. ref #1101 --- base-hw/include/kernel/interface.h | 8 ++--- base-hw/src/base/lock/lock_helper.h | 2 +- base-hw/src/core/kernel/core_interface.h | 42 ++++++++++++++++-------- base-hw/src/core/kernel/thread.cc | 23 ++++++++++--- base-hw/src/core/kernel/thread.h | 1 + 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/base-hw/include/kernel/interface.h b/base-hw/include/kernel/interface.h index c36923ae0..82b5be63e 100644 --- a/base-hw/include/kernel/interface.h +++ b/base-hw/include/kernel/interface.h @@ -36,7 +36,7 @@ namespace Kernel * Kernel names of the kernel calls */ constexpr Call_arg call_id_pause_current_thread() { return 0; } - constexpr Call_arg call_id_resume_thread() { return 1; } + constexpr Call_arg call_id_resume_local_thread() { return 1; } constexpr Call_arg call_id_yield_thread() { return 2; } constexpr Call_arg call_id_send_request_msg() { return 3; } constexpr Call_arg call_id_send_reply_msg() { return 4; } @@ -95,15 +95,15 @@ namespace Kernel /** - * Cancel blocking of a thread if possible + * Cancel blocking of a thread of the current domain if possible * * \param thread_id kernel name of the targeted thread * * \return wether thread was in a cancelable blocking beforehand */ - inline bool resume_thread(unsigned const thread_id) + inline bool resume_local_thread(unsigned const thread_id) { - return call(call_id_resume_thread(), thread_id); + return call(call_id_resume_local_thread(), thread_id); } diff --git a/base-hw/src/base/lock/lock_helper.h b/base-hw/src/base/lock/lock_helper.h index db4b02bbd..39c13068f 100644 --- a/base-hw/src/base/lock/lock_helper.h +++ b/base-hw/src/base/lock/lock_helper.h @@ -52,7 +52,7 @@ static inline void thread_switch_to(Genode::Thread_base * const t) static inline bool thread_check_stopped_and_restart(Genode::Thread_base * const t) { - return Kernel::resume_thread(native_thread_id(t)); + return Kernel::resume_local_thread(native_thread_id(t)); } diff --git a/base-hw/src/core/kernel/core_interface.h b/base-hw/src/core/kernel/core_interface.h index 398db2144..3a71e3492 100644 --- a/base-hw/src/core/kernel/core_interface.h +++ b/base-hw/src/core/kernel/core_interface.h @@ -34,20 +34,21 @@ namespace Kernel constexpr Call_arg call_id_new_thread() { return 12; } constexpr Call_arg call_id_bin_thread() { return 13; } constexpr Call_arg call_id_start_thread() { return 14; } - constexpr Call_arg call_id_access_thread_regs() { return 15; } - constexpr Call_arg call_id_route_thread_event() { return 16; } - constexpr Call_arg call_id_update_pd() { return 17; } - constexpr Call_arg call_id_update_region() { return 18; } - constexpr Call_arg call_id_new_pd() { return 19; } - constexpr Call_arg call_id_bin_pd() { return 20; } - constexpr Call_arg call_id_new_signal_receiver() { return 21; } - constexpr Call_arg call_id_new_signal_context() { return 22; } - constexpr Call_arg call_id_bin_signal_context() { return 23; } - constexpr Call_arg call_id_bin_signal_receiver() { return 24; } - constexpr Call_arg call_id_new_vm() { return 25; } - constexpr Call_arg call_id_run_vm() { return 26; } - constexpr Call_arg call_id_pause_vm() { return 27; } - constexpr Call_arg call_id_pause_thread() { return 28; } + constexpr Call_arg call_id_resume_thread() { return 15; } + constexpr Call_arg call_id_access_thread_regs() { return 16; } + constexpr Call_arg call_id_route_thread_event() { return 17; } + constexpr Call_arg call_id_update_pd() { return 18; } + constexpr Call_arg call_id_update_region() { return 19; } + constexpr Call_arg call_id_new_pd() { return 20; } + constexpr Call_arg call_id_bin_pd() { return 21; } + constexpr Call_arg call_id_new_signal_receiver() { return 22; } + constexpr Call_arg call_id_new_signal_context() { return 23; } + constexpr Call_arg call_id_bin_signal_context() { return 24; } + constexpr Call_arg call_id_bin_signal_receiver() { return 25; } + constexpr Call_arg call_id_new_vm() { return 26; } + constexpr Call_arg call_id_run_vm() { return 27; } + constexpr Call_arg call_id_pause_vm() { return 28; } + constexpr Call_arg call_id_pause_thread() { return 29; } /** * Create a domain @@ -163,6 +164,19 @@ namespace Kernel } + /** + * Cancel blocking of a thread if possible + * + * \param thread_id kernel name of the targeted thread + * + * \return wether thread was in a cancelable blocking beforehand + */ + inline bool resume_thread(unsigned const thread_id) + { + return call(call_id_resume_thread(), thread_id); + } + + /** * Set or unset the handler of an event that can be triggered by a thread * diff --git a/base-hw/src/core/kernel/thread.cc b/base-hw/src/core/kernel/thread.cc index c6bd56705..0eff1a0ab 100644 --- a/base-hw/src/core/kernel/thread.cc +++ b/base-hw/src/core/kernel/thread.cc @@ -407,6 +407,12 @@ void Thread::_call_pause_thread() void Thread::_call_resume_thread() { + /* check permissions */ + if (!_core()) { + PWRN("not entitled to resume thread"); + _stop(); + return; + } /* lookup thread */ Thread * const thread = Thread::pool()->object(user_arg_1()); if (!thread) { @@ -414,10 +420,18 @@ void Thread::_call_resume_thread() user_arg_0(false); return; } - /* check permissions */ - if (!_core() && pd_id() != thread->pd_id()) { - PWRN("not entitled to resume thread"); - _stop(); + /* resume thread */ + user_arg_0(thread->_resume()); +} + + +void Thread::_call_resume_local_thread() +{ + /* lookup thread */ + Thread * const thread = Thread::pool()->object(user_arg_1()); + if (!thread || pd_id() != thread->pd_id()) { + PWRN("failed to lookup thread"); + user_arg_0(0); return; } /* resume thread */ @@ -972,6 +986,7 @@ void Thread::_call(unsigned const processor_id) case call_id_pause_current_thread(): _call_pause_current_thread(); return; case call_id_pause_thread(): _call_pause_thread(); return; case call_id_resume_thread(): _call_resume_thread(); return; + case call_id_resume_local_thread(): _call_resume_local_thread(); return; case call_id_yield_thread(): _call_yield_thread(); return; case call_id_send_request_msg(): _call_send_request_msg(); return; case call_id_send_reply_msg(): _call_send_reply_msg(); return; diff --git a/base-hw/src/core/kernel/thread.h b/base-hw/src/core/kernel/thread.h index e11371bfc..40ee23f97 100644 --- a/base-hw/src/core/kernel/thread.h +++ b/base-hw/src/core/kernel/thread.h @@ -237,6 +237,7 @@ class Kernel::Thread void _call_pause_current_thread(); void _call_pause_thread(); void _call_resume_thread(); + void _call_resume_local_thread(); void _call_yield_thread(); void _call_await_request_msg(); void _call_send_request_msg();