From 36111587beecbec0ed5b14cd52c4d4a371738191 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 18 Sep 2013 22:33:56 +0200 Subject: [PATCH] hw: don't use assertions in Kernel::get_thread ref #589 --- base-hw/include/kernel/syscalls.h | 13 +++++++++---- base-hw/src/core/kernel.cc | 28 ++++++++++++++-------------- base-hw/src/core/thread.cc | 9 +++------ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/base-hw/include/kernel/syscalls.h b/base-hw/include/kernel/syscalls.h index 827f6ca04..f33491cf3 100644 --- a/base-hw/include/kernel/syscalls.h +++ b/base-hw/include/kernel/syscalls.h @@ -317,14 +317,19 @@ namespace Kernel /** - * Get platform thread by ID or 0 if target is "core main" or "idle" + * Get platform thread by the kernel name of a thread * - * \param id ID of the targeted thread or 0 if caller targets itself + * \param id kernel name of the thread or 0 if the caller targets itself + * + * \retval 0 thread doesn't exist or has no platform thread + * \retval >0 core local address of platform thread * * Restricted to core threads. */ - inline Platform_thread * get_thread(unsigned const id = 0) { - return (Platform_thread *)syscall(GET_THREAD, id); } + inline Platform_thread * get_thread(unsigned const id) + { + return (Platform_thread *)syscall(GET_THREAD, id); + } /** diff --git a/base-hw/src/core/kernel.cc b/base-hw/src/core/kernel.cc index 2c36fdd5c..2ed33549e 100644 --- a/base-hw/src/core/kernel.cc +++ b/base-hw/src/core/kernel.cc @@ -444,21 +444,21 @@ namespace Kernel void do_get_thread(Thread * const user) { /* check permissions */ - assert(user->pd_id() == core_id()); - - /* get target */ - unsigned const tid = (unsigned)user->user_arg_1(); + if (user->pd_id() != core_id()) { + PERR("not entitled to read address of platform thread"); + user->user_arg_0(0); + return; + } + /* lookup thread */ + unsigned const id = user->user_arg_1(); Thread * t; - - /* user targets a thread by ID */ - if (tid) { - t = Thread::pool()->object(tid); - assert(t); - - /* user targets itself */ - } else t = user; - - /* return target platform thread */ + if (id) { + t = Thread::pool()->object(id); + if (!t) { + PERR("unknown thread"); + user->user_arg_0(0); + } + } else { t = user; } user->user_arg_0((Syscall_ret)t->platform_thread()); } diff --git a/base-hw/src/core/thread.cc b/base-hw/src/core/thread.cc index 11dd96bb4..46808ffea 100644 --- a/base-hw/src/core/thread.cc +++ b/base-hw/src/core/thread.cc @@ -42,12 +42,9 @@ Native_utcb * Thread_base::utcb() */ Thread_base * Thread_base::myself() { - /* get our platform thread wich holds our thread base or 0 */ - Platform_thread * const pt = Kernel::get_thread(); - if (pt) return pt->thread_base(); - - /* we are core main, the only thread beside idle with no platform thread */ - else return 0; + Platform_thread * const t = Kernel::get_thread(0); + if (t) { return t->thread_base(); } + return 0; }