summaryrefslogtreecommitdiff
path: root/src/kernel/proc.c
diff options
context:
space:
mode:
authordzwdz2022-05-01 20:21:55 +0200
committerdzwdz2022-05-01 20:21:55 +0200
commit5f6767972f1550c54dd6f28267dc3d882f67d7ed (patch)
tree0e16411f440e191084a6e61c81fd5416425ba12e /src/kernel/proc.c
parentd996f88bfda890df5d2b76e7c06cae329e04ab00 (diff)
kernel/proc: `process_handle_get` for safely accepting handle ids
Diffstat (limited to 'src/kernel/proc.c')
-rw-r--r--src/kernel/proc.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 79c4ed7..39f9e1f 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -208,6 +208,15 @@ handle_t process_find_handle(struct process *proc, handle_t start_at) {
return handle;
}
+struct handle*
+process_handle_get(struct process *p, handle_t id, enum handle_type type) {
+ struct handle *h;
+ if (id < 0 || id >= HANDLE_MAX) return NULL;
+ h = p->handles[id];
+ if (h == NULL || h->type != type) return NULL;
+ return h;
+}
+
void process_transition(struct process *p, enum process_state state) {
enum process_state last = p->state;
p->state = state;