kernel: add initial object manager definitions
This commit is contained in:
69
include/socks/object.h
Normal file
69
include/socks/object.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef SOCKS_OBJECT_H_
|
||||
#define SOCKS_OBJECT_H_
|
||||
|
||||
#include <socks/locks.h>
|
||||
#include <socks/status.h>
|
||||
#include <socks/vm.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define OBJECT_MAGIC 0xBADDCAFE
|
||||
|
||||
struct object;
|
||||
|
||||
typedef enum object_type_flags {
|
||||
OBJTYPE_INIT = 0x01u,
|
||||
} object_type_flags_t;
|
||||
|
||||
typedef struct object_ops {
|
||||
kern_status_t(*open)(struct object *obj);
|
||||
kern_status_t(*close)(struct object *obj);
|
||||
kern_status_t(*delete)(struct object *obj);
|
||||
kern_status_t(*query_name)(struct object *obj, char *out, size_t max);
|
||||
kern_status_t(*parse)(struct object *obj, const char *path, struct object **out);
|
||||
kern_status_t(*get_name)(struct object *obj, const char *name, struct object **out);
|
||||
kern_status_t(*get_at)(struct object *obj, size_t at, struct object **out);
|
||||
} object_ops_t;
|
||||
|
||||
typedef struct object_type {
|
||||
object_type_flags_t ob_flags;
|
||||
char ob_name[32];
|
||||
unsigned int ob_size;
|
||||
vm_cache_t ob_cache;
|
||||
queue_entry_t ob_list;
|
||||
const object_ops_t *ob_ops;
|
||||
} object_type_t;
|
||||
|
||||
typedef struct object {
|
||||
uint32_t ob_magic;
|
||||
object_type_t *ob_type;
|
||||
spin_lock_t ob_lock;
|
||||
unsigned int ob_refcount;
|
||||
unsigned int ob_handles;
|
||||
} __aligned(sizeof(long)) object_t;
|
||||
|
||||
typedef struct object_namespace object_namespace_t;
|
||||
|
||||
extern kern_status_t object_bootstrap(void);
|
||||
extern kern_status_t object_type_register(object_type_t *p);
|
||||
extern kern_status_t object_type_unregister(object_type_t *p);
|
||||
|
||||
extern object_namespace_t *global_namespace(void);
|
||||
extern object_namespace_t *object_namespace_create(void);
|
||||
extern kern_status_t object_namespace_get_object(object_namespace_t *ns, const char *path, object_t **out);
|
||||
extern kern_status_t object_publish(object_namespace_t *ns, const char *path, object_t *obj);
|
||||
extern kern_status_t object_unpublish(object_namespace_t *ns, object_t *obj);
|
||||
|
||||
extern object_t *object_create(object_type_t *type);
|
||||
extern object_t *object_ref(object_t *obj);
|
||||
extern void object_deref(object_t *obj);
|
||||
extern void *object_data(object_t *obj);
|
||||
extern object_t *object_header(void *p);
|
||||
static inline kern_status_t object_get(const char *path, object_t **out)
|
||||
{
|
||||
return object_namespace_get_object(global_namespace(), path, out);
|
||||
}
|
||||
|
||||
extern void init_set_objects(void);
|
||||
extern void init_global_namespace(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user