diff --git a/include/kernel/object.h b/include/kernel/object.h index 4f053de..6271e4b 100644 --- a/include/kernel/object.h +++ b/include/kernel/object.h @@ -3,8 +3,8 @@ #include #include -#include #include +#include #include #ifdef __cplusplus @@ -67,6 +67,7 @@ struct object_type { struct object { uint32_t ob_magic; + koid_t ob_id; struct object_type *ob_type; spin_lock_t ob_lock; unsigned int ob_refcount; diff --git a/kernel/object.c b/kernel/object.c index 115d0b6..cf9df21 100644 --- a/kernel/object.c +++ b/kernel/object.c @@ -7,6 +7,20 @@ static struct queue object_types; static spin_lock_t object_types_lock = SPIN_LOCK_INIT; +static koid_t koid_alloc(void) +{ + static koid_t counter = 0; + static spin_lock_t lock = SPIN_LOCK_INIT; + + unsigned long flags; + spin_lock_irqsave(&lock, &flags); + koid_t result = counter; + counter++; + spin_unlock_irqrestore(&lock, flags); + + return result; +} + kern_status_t object_bootstrap(void) { return KERN_OK; @@ -53,6 +67,7 @@ struct object *object_create(struct object_type *type) struct object *obj = (struct object *)((unsigned char *)obj_buf + type->ob_header_offset); + obj->ob_id = koid_alloc(); obj->ob_type = type; obj->ob_lock = SPIN_LOCK_INIT; obj->ob_magic = OBJECT_MAGIC; diff --git a/libmango/include/mango/types.h b/libmango/include/mango/types.h index c766801..ee8f0b2 100644 --- a/libmango/include/mango/types.h +++ b/libmango/include/mango/types.h @@ -45,6 +45,7 @@ typedef uintptr_t phys_addr_t; typedef uintptr_t virt_addr_t; typedef uint64_t msgid_t; typedef uint64_t off_t; +typedef uint64_t koid_t; typedef unsigned int tid_t; typedef uint32_t kern_handle_t; typedef uint32_t kern_config_key_t;