2026-02-19 19:13:44 +00:00
|
|
|
#ifndef KERNEL_OBJECT_H_
|
|
|
|
|
#define KERNEL_OBJECT_H_
|
|
|
|
|
|
|
|
|
|
#include <kernel/flags.h>
|
|
|
|
|
#include <kernel/locks.h>
|
|
|
|
|
#include <kernel/vm.h>
|
2026-02-23 18:31:28 +00:00
|
|
|
#include <mango/status.h>
|
2026-02-19 19:13:44 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define DEFINE_OBJECT_LOCK_FUNCTION(object_name, base) \
|
|
|
|
|
static inline void object_name##_lock(struct object_name *p) \
|
|
|
|
|
{ \
|
|
|
|
|
object_lock(&p->base); \
|
|
|
|
|
} \
|
|
|
|
|
static inline void object_name##_unlock(struct object_name *p) \
|
|
|
|
|
{ \
|
|
|
|
|
object_unlock(&p->base); \
|
|
|
|
|
} \
|
|
|
|
|
static inline void object_name##_lock_irqsave( \
|
|
|
|
|
struct object_name *p, \
|
|
|
|
|
unsigned long *flags) \
|
|
|
|
|
{ \
|
|
|
|
|
object_lock_irqsave(&p->base, flags); \
|
|
|
|
|
} \
|
|
|
|
|
static inline void object_name##_unlock_irqrestore( \
|
|
|
|
|
struct object_name *p, \
|
|
|
|
|
unsigned long flags) \
|
|
|
|
|
{ \
|
|
|
|
|
object_unlock_irqrestore(&p->base, flags); \
|
2026-02-26 19:38:49 +00:00
|
|
|
} \
|
|
|
|
|
static inline void object_name##_lock_pair_irqsave( \
|
|
|
|
|
struct object_name *a, \
|
|
|
|
|
struct object_name *b, \
|
|
|
|
|
unsigned long *flags) \
|
|
|
|
|
{ \
|
|
|
|
|
object_lock_pair_irqsave(&a->base, &b->base, flags); \
|
|
|
|
|
} \
|
|
|
|
|
static inline void object_name##_unlock_pair_irqrestore( \
|
|
|
|
|
struct object_name *a, \
|
|
|
|
|
struct object_name *b, \
|
|
|
|
|
unsigned long flags) \
|
|
|
|
|
{ \
|
|
|
|
|
object_unlock_pair_irqrestore(&a->base, &b->base, flags); \
|
2026-02-19 19:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define OBJECT_MAGIC 0xBADDCAFE
|
|
|
|
|
#define OBJECT_NAME_MAX 64
|
|
|
|
|
#define OBJECT_PATH_MAX 256
|
|
|
|
|
|
|
|
|
|
#define OBJECT_CAST(to_type, to_type_member, p) \
|
|
|
|
|
((to_type *)((uintptr_t)p) - offsetof(to_type, to_type_member))
|
|
|
|
|
#define OBJECT_C_CAST(c_type, c_type_member, obj_type, objp) \
|
|
|
|
|
OBJECT_IS_TYPE(objp, obj_type) \
|
|
|
|
|
? OBJECT_CAST(c_type, c_type_member, (objp)) : NULL
|
|
|
|
|
#define OBJECT_IS_TYPE(obj, type_ptr) ((obj)->ob_type == (type_ptr))
|
|
|
|
|
|
|
|
|
|
struct object;
|
|
|
|
|
struct object_attrib;
|
|
|
|
|
|
|
|
|
|
enum object_type_flags {
|
|
|
|
|
OBJTYPE_INIT = 0x01u,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct object_ops {
|
2026-02-23 18:34:12 +00:00
|
|
|
kern_status_t (*destroy)(struct object *obj, struct queue *q);
|
|
|
|
|
kern_status_t (*destroy_recurse)(
|
|
|
|
|
struct queue_entry *entry,
|
|
|
|
|
struct object **out);
|
2026-02-19 19:13:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct object_type {
|
|
|
|
|
enum object_type_flags ob_flags;
|
|
|
|
|
char ob_name[32];
|
|
|
|
|
unsigned int ob_size;
|
|
|
|
|
unsigned int ob_header_offset;
|
|
|
|
|
struct vm_cache ob_cache;
|
|
|
|
|
struct queue_entry ob_list;
|
|
|
|
|
struct object_ops ob_ops;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct object {
|
|
|
|
|
uint32_t ob_magic;
|
2026-02-23 18:31:28 +00:00
|
|
|
koid_t ob_id;
|
2026-02-19 19:13:44 +00:00
|
|
|
struct object_type *ob_type;
|
|
|
|
|
spin_lock_t ob_lock;
|
|
|
|
|
unsigned int ob_refcount;
|
|
|
|
|
unsigned int ob_handles;
|
|
|
|
|
struct queue_entry ob_list;
|
|
|
|
|
} __aligned(sizeof(long));
|
|
|
|
|
|
|
|
|
|
extern kern_status_t object_bootstrap(void);
|
|
|
|
|
extern kern_status_t object_type_register(struct object_type *p);
|
|
|
|
|
extern kern_status_t object_type_unregister(struct object_type *p);
|
|
|
|
|
|
|
|
|
|
extern struct object *object_create(struct object_type *type);
|
|
|
|
|
extern struct object *object_ref(struct object *obj);
|
|
|
|
|
extern void object_unref(struct object *obj);
|
|
|
|
|
extern void object_add_handle(struct object *obj);
|
|
|
|
|
extern void object_remove_handle(struct object *obj);
|
|
|
|
|
extern void object_lock(struct object *obj);
|
|
|
|
|
extern void object_unlock(struct object *obj);
|
|
|
|
|
extern void object_lock_irqsave(struct object *obj, unsigned long *flags);
|
|
|
|
|
extern void object_unlock_irqrestore(struct object *obj, unsigned long flags);
|
|
|
|
|
|
2026-02-26 19:38:49 +00:00
|
|
|
extern void object_lock_pair_irqsave(
|
|
|
|
|
struct object *a,
|
|
|
|
|
struct object *b,
|
|
|
|
|
unsigned long *flags);
|
|
|
|
|
extern void object_unlock_pair_irqrestore(
|
|
|
|
|
struct object *a,
|
|
|
|
|
struct object *b,
|
|
|
|
|
unsigned long flags);
|
|
|
|
|
|
2026-02-19 19:13:44 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|