diff --git a/hermit/include/hermit/tasks.h b/hermit/include/hermit/tasks.h index d45f18141..6fe4612b4 100644 --- a/hermit/include/hermit/tasks.h +++ b/hermit/include/hermit/tasks.h @@ -190,6 +190,18 @@ int wakeup_task(tid_t); */ int block_current_task(void); +/** @brief Get a process control block + * + * @param id ID of the task to retrieve + * @param task Location to store pointer to task + * @return + * - 0 on success + * - -ENOMEM (-12) if @p task is NULL + * - -ENOENT ( -2) if @p id not in task table + * - -EINVAL (-22) if there's no valid task with @p id + */ +int get_task(tid_t id, task_t** task); + /** @brief Block current task until timer expires * * @param deadline Clock tick, when the timer expires diff --git a/hermit/kernel/tasks.c b/hermit/kernel/tasks.c index 3853930b2..44c04ece7 100644 --- a/hermit/kernel/tasks.c +++ b/hermit/kernel/tasks.c @@ -877,6 +877,26 @@ get_task_out: return NULL; } + +int get_task(tid_t id, task_t** task) +{ + if (BUILTIN_EXPECT(task == NULL, 0)) { + return -ENOMEM; + } + + if (BUILTIN_EXPECT(id >= MAX_TASKS, 0)) { + return -ENOENT; + } + + if (BUILTIN_EXPECT(task_table[id].status == TASK_INVALID, 0)) { + return -EINVAL; + } + + *task = &task_table[id]; + + return 0; +} + void reschedule(void) { size_t** stack;