diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/proc.c | 25 | ||||
-rw-r--r-- | src/kernel/proc.h | 2 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c index d20b0d3..2af352b 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -74,25 +74,30 @@ _Noreturn void process_switch_any(void) { } // TODO there's no check for going past the stack - VULN -static struct process *_process_find_recursive( - enum process_state target, struct process *iter) { - struct process *in; - while (iter) { +static size_t _process_find_recursive( + enum process_state target, struct process *iter, + struct process **buf, size_t pos, size_t max) +{ + while (pos < max && iter) { if (iter->state == target) - return iter; + buf[pos++] = iter; // DFS - in = _process_find_recursive(target, iter->child); - if (in) - return in; + pos = _process_find_recursive(target, iter->child, buf, pos, max); iter = iter->sibling; } - return NULL; + return pos; } struct process *process_find(enum process_state target) { - return _process_find_recursive(target, process_first); + struct process *result = NULL; + process_find_multiple(target, &result, 1); + return result; +} + +size_t process_find_multiple(enum process_state target, struct process **buf, size_t max) { + return _process_find_recursive(target, process_first, buf, 0, max); } handle_t process_find_handle(struct process *proc) { diff --git a/src/kernel/proc.h b/src/kernel/proc.h index 5e328aa..2066b40 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -57,6 +57,8 @@ _Noreturn void process_switch(struct process *proc); _Noreturn void process_switch_any(void); // switches to any running process struct process *process_find(enum process_state); +size_t process_find_multiple(enum process_state, struct process **buf, size_t max); + handle_t process_find_handle(struct process *proc); // finds the first free handle void process_kill(struct process *proc, int ret); |