lx_kit: sanitize that solely ep calls schedule()

with expected primary stack.

Issue #4540
This commit is contained in:
Alexander Boettcher
2022-06-24 11:43:38 +02:00
committed by Christian Helmuth
parent c81b3d4757
commit ce67be5a86
3 changed files with 18 additions and 1 deletions

View File

@ -47,7 +47,7 @@ struct Lx_kit::Env
Timer::Connection timer { env }; Timer::Connection timer { env };
Mem_allocator memory { env, heap, platform, CACHED }; Mem_allocator memory { env, heap, platform, CACHED };
Mem_allocator uncached_memory { env, heap, platform, UNCACHED }; Mem_allocator uncached_memory { env, heap, platform, UNCACHED };
Scheduler scheduler { }; Scheduler scheduler { env.ep() };
Device_list devices { env.ep(), heap, platform }; Device_list devices { env.ep(), heap, platform };
Lx_kit::Timeout timeout { timer, scheduler }; Lx_kit::Timeout timeout { timer, scheduler };
unsigned int last_irq { 0 }; unsigned int last_irq { 0 };

View File

@ -32,6 +32,8 @@ class Lx_kit::Scheduler
List<Task> _present_list { }; List<Task> _present_list { };
Task * _current { nullptr }; Task * _current { nullptr };
Genode::Entrypoint &ep;
public: public:
Task & current(); Task & current();
@ -51,6 +53,8 @@ class Lx_kit::Scheduler
template <typename FN> template <typename FN>
void for_each_task(FN const & fn); void for_each_task(FN const & fn);
Scheduler(Genode::Entrypoint &ep) : ep(ep) { }
}; };

View File

@ -15,8 +15,10 @@
*/ */
/* Genode includes */ /* Genode includes */
#include <base/entrypoint.h>
#include <base/log.h> #include <base/log.h>
#include <base/sleep.h> #include <base/sleep.h>
#include <base/thread.h>
#include <os/backtrace.h> #include <os/backtrace.h>
#include <lx_kit/scheduler.h> #include <lx_kit/scheduler.h>
@ -91,6 +93,17 @@ Task & Scheduler::task(void * lx_task)
void Scheduler::schedule() void Scheduler::schedule()
{ {
/* sanity check that right thread & stack is in use */
auto const thread = Genode::Thread::myself();
if (!ep.rpc_ep().myself(addr_t(&thread))) {
Genode::error("Lx_kit::Scheduler called by invalid thread/stack ",
thread->name(), " ",
Genode::Hex(thread->mystack().base), "-",
Genode::Hex(thread->mystack().top));
Genode::backtrace();
Genode::sleep_forever();
}
/* /*
* Iterate over all tasks and run first runnable. * Iterate over all tasks and run first runnable.
* *