diff options
-rwxr-xr-x | src/kernel/proc.c | 7 | ||||
-rw-r--r-- | src/kernel/proc.h | 2 | ||||
-rw-r--r-- | src/kernel/vfs/procfs.c | 2 |
3 files changed, 6 insertions, 5 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 408e3d0..acefeb9 100755 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -295,7 +295,7 @@ _Noreturn void process_switch_any(void) { if (process_current && process_current->state == PS_RUNNING) process_switch(process_current); - for (struct process *p = process_first; p; p = process_next(p)) { + for (struct process *p = process_first; p; p = process_next(p, NULL)) { if (p->state == PS_RUNNING) process_switch(p); } @@ -304,7 +304,7 @@ _Noreturn void process_switch_any(void) { } } -struct process *process_next(struct process *p) { +struct process *process_next(struct process *p, struct process *root) { /* depth-first search, the order is: * 1 * / \ @@ -319,7 +319,8 @@ struct process *process_next(struct process *p) { /* looking at the diagram above - we're at 4, want to find 5 */ while (!p->sibling) { p = p->parent; - if (!p) return NULL; + if (root) assert(p); + if (!p || p == root) return NULL; } return p->sibling; } diff --git a/src/kernel/proc.h b/src/kernel/proc.h index fa50520..c51151b 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -96,7 +96,7 @@ void process_tryreap(struct process *dead); _Noreturn void process_switch_any(void); /** Used for iterating over all processes */ -struct process *process_next(struct process *); +struct process *process_next(struct process *p, struct process *root); handle_t process_find_free_handle(struct process *proc, handle_t start_at); struct handle *process_handle_get(struct process *, handle_t); diff --git a/src/kernel/vfs/procfs.c b/src/kernel/vfs/procfs.c index 0f65f93..5837012 100644 --- a/src/kernel/vfs/procfs.c +++ b/src/kernel/vfs/procfs.c @@ -45,7 +45,7 @@ openpath(const char *path, size_t len, struct process *p) static struct process * findgid(uint32_t gid, struct process *root) { - for (struct process *p = root; p; p = process_next(p)) { + for (struct process *p = root; p; p = process_next(p, root)) { if (p->globalid == gid) return p; } return NULL; |