kernel: add header files
This commit is contained in:
95
include/kernel/object.h
Normal file
95
include/kernel/object.h
Normal file
@@ -0,0 +1,95 @@
|
||||
#ifndef KERNEL_OBJECT_H_
|
||||
#define KERNEL_OBJECT_H_
|
||||
|
||||
#include <kernel/flags.h>
|
||||
#include <kernel/locks.h>
|
||||
#include <mango/status.h>
|
||||
#include <kernel/vm.h>
|
||||
#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); \
|
||||
}
|
||||
|
||||
#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 {
|
||||
kern_status_t (*destroy)(struct object *obj);
|
||||
};
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user