diff options
author | dzwdz | 2022-05-01 20:09:52 +0200 |
---|---|---|
committer | dzwdz | 2022-05-01 20:09:52 +0200 |
commit | d996f88bfda890df5d2b76e7c06cae329e04ab00 (patch) | |
tree | eebe7b88bc48960a78648001adf38b5c66ffcfe3 /src/kernel/handle.c | |
parent | 7c62817193517f298bc566f3803c00d53a9a2b94 (diff) |
kernel/proc: make handles separate refcounted objects
Diffstat (limited to 'src/kernel/handle.c')
-rw-r--r-- | src/kernel/handle.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/kernel/handle.c b/src/kernel/handle.c new file mode 100644 index 0000000..d7f19b3 --- /dev/null +++ b/src/kernel/handle.c @@ -0,0 +1,27 @@ +#include <kernel/handle.h> +#include <kernel/mem/alloc.h> +#include <kernel/panic.h> +#include <kernel/proc.h> + +struct handle *handle_init(enum handle_type type) { + struct handle *h = kmalloc(sizeof *h); + h->type = type; + h->refcount = 1; + return h; +} + +void handle_close(struct handle *h) { + if (!h) return; + assert(h->refcount > 0); + if (--(h->refcount) == 0) { + // TODO call close() in handler + // TODO count allocations and frees + + // TODO sanity check to check if refcount is true. handle_sanity? + + // TODO tests which would catch premature frees + // by that i mean duplicating a handle and killing the original process + h->type = HANDLE_INVALID; + kfree(h); + } +} |