2023-02-17 19:36:14 +00:00
|
|
|
#ifndef SOCKS_OBJECT_H_
|
|
|
|
|
#define SOCKS_OBJECT_H_
|
|
|
|
|
|
|
|
|
|
#include <socks/locks.h>
|
|
|
|
|
#include <socks/status.h>
|
2023-05-14 21:11:32 +01:00
|
|
|
#include <socks/flags.h>
|
2023-02-17 19:36:14 +00:00
|
|
|
#include <socks/vm.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2023-03-20 20:41:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-17 19:36:14 +00:00
|
|
|
#define OBJECT_MAGIC 0xBADDCAFE
|
2023-02-25 17:57:53 +00:00
|
|
|
#define OBJECT_NAME_MAX 64
|
2023-06-02 19:34:33 +01:00
|
|
|
#define OBJECT_PATH_MAX 256
|
2023-02-17 19:36:14 +00:00
|
|
|
|
2023-05-06 19:48:14 +01:00
|
|
|
#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))
|
|
|
|
|
|
2023-02-17 19:36:14 +00:00
|
|
|
struct object;
|
2023-02-25 17:57:53 +00:00
|
|
|
struct object_attrib;
|
2023-02-17 19:36:14 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
enum object_type_flags {
|
2023-02-17 19:36:14 +00:00
|
|
|
OBJTYPE_INIT = 0x01u,
|
2023-04-12 20:17:11 +01:00
|
|
|
};
|
2023-02-17 19:36:14 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct object_ops {
|
2023-02-17 19:36:14 +00:00
|
|
|
kern_status_t(*open)(struct object *obj);
|
|
|
|
|
kern_status_t(*close)(struct object *obj);
|
2023-05-14 21:11:32 +01:00
|
|
|
kern_status_t(*read)(struct object *obj, void *p, size_t *r, socks_flags_t flags);
|
|
|
|
|
kern_status_t(*write)(struct object *obj, const void *p, size_t *w, socks_flags_t flags);
|
2023-03-20 20:41:39 +00:00
|
|
|
kern_status_t(*destroy)(struct object *obj);
|
2023-02-25 17:57:53 +00:00
|
|
|
kern_status_t(*query_name)(struct object *obj, char out[OBJECT_NAME_MAX]);
|
2023-02-17 19:36:14 +00:00
|
|
|
kern_status_t(*parse)(struct object *obj, const char *path, struct object **out);
|
2023-02-25 17:57:53 +00:00
|
|
|
kern_status_t(*get_named)(struct object *obj, const char *name, struct object **out);
|
2023-02-17 19:36:14 +00:00
|
|
|
kern_status_t(*get_at)(struct object *obj, size_t at, struct object **out);
|
2023-02-25 17:57:53 +00:00
|
|
|
kern_status_t(*read_attrib)(struct object *obj, struct object_attrib *attrib, char *out, size_t max, size_t *r);
|
|
|
|
|
kern_status_t(*write_attrib)(struct object *obj, struct object_attrib *attrib, const char *s, size_t len, size_t *r);
|
2023-04-12 20:17:11 +01:00
|
|
|
};
|
2023-02-17 19:36:14 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct object_attrib {
|
2023-02-25 17:57:53 +00:00
|
|
|
char *a_name;
|
2023-04-12 20:17:11 +01:00
|
|
|
struct queue_entry a_list;
|
|
|
|
|
};
|
2023-02-25 17:57:53 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct object_type {
|
|
|
|
|
enum object_type_flags ob_flags;
|
2023-02-17 19:36:14 +00:00
|
|
|
char ob_name[32];
|
|
|
|
|
unsigned int ob_size;
|
2023-05-06 22:22:05 +01:00
|
|
|
unsigned int ob_header_offset;
|
2023-04-12 20:17:11 +01:00
|
|
|
struct vm_cache ob_cache;
|
|
|
|
|
struct queue_entry ob_list;
|
|
|
|
|
struct queue ob_attrib;
|
|
|
|
|
struct object_ops ob_ops;
|
|
|
|
|
};
|
2023-02-17 19:36:14 +00:00
|
|
|
|
2023-04-12 20:17:11 +01:00
|
|
|
struct object {
|
2023-02-17 19:36:14 +00:00
|
|
|
uint32_t ob_magic;
|
2023-04-12 20:17:11 +01:00
|
|
|
struct object_type *ob_type;
|
2023-02-17 19:36:14 +00:00
|
|
|
spin_lock_t ob_lock;
|
|
|
|
|
unsigned int ob_refcount;
|
|
|
|
|
unsigned int ob_handles;
|
2023-04-12 20:17:11 +01:00
|
|
|
struct queue ob_attrib;
|
|
|
|
|
struct queue_entry ob_list;
|
|
|
|
|
} __aligned(sizeof(long));
|
2023-02-17 19:36:14 +00:00
|
|
|
|
|
|
|
|
extern kern_status_t object_bootstrap(void);
|
2023-04-12 20:17:11 +01:00
|
|
|
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_namespace *global_namespace(void);
|
|
|
|
|
extern struct object_namespace *object_namespace_create(void);
|
2023-05-06 19:48:14 +01:00
|
|
|
extern struct object *ns_header(struct object_namespace *ns);
|
2023-04-12 20:17:11 +01:00
|
|
|
extern kern_status_t object_namespace_get_object(struct object_namespace *ns, const char *path, struct object **out);
|
2023-06-02 19:34:33 +01:00
|
|
|
extern kern_status_t object_namespace_create_link(struct object_namespace *ns, const char *linkpath, struct object *dest);
|
2023-04-12 20:17:11 +01:00
|
|
|
extern kern_status_t object_publish(struct object_namespace *ns, const char *path, struct object *obj);
|
|
|
|
|
extern kern_status_t object_unpublish(struct object_namespace *ns, struct object *obj);
|
|
|
|
|
|
|
|
|
|
extern struct object *object_create(struct object_type *type);
|
|
|
|
|
extern struct object *object_ref(struct object *obj);
|
|
|
|
|
extern void object_deref(struct object *obj);
|
2023-06-02 19:34:33 +01:00
|
|
|
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);
|
2023-04-12 20:17:11 +01:00
|
|
|
static inline kern_status_t object_get(const char *path, struct object **out)
|
2023-02-17 19:36:14 +00:00
|
|
|
{
|
|
|
|
|
return object_namespace_get_object(global_namespace(), path, out);
|
|
|
|
|
}
|
2023-05-14 21:11:32 +01:00
|
|
|
extern kern_status_t object_read(struct object *obj, void *p, size_t max, size_t *nr_read, socks_flags_t flags);
|
|
|
|
|
extern kern_status_t object_write(struct object *obj, const void *p, size_t max, size_t *nr_written, socks_flags_t flags);
|
2023-04-12 20:17:11 +01:00
|
|
|
extern kern_status_t object_get_child_named(struct object *obj, const char *name, struct object **out);
|
|
|
|
|
extern kern_status_t object_get_child_at(struct object *obj, size_t at, struct object **out);
|
|
|
|
|
extern kern_status_t object_query_name(struct object *obj, char name[OBJECT_NAME_MAX]);
|
|
|
|
|
|
|
|
|
|
extern struct object *set_create(const char *name);
|
|
|
|
|
extern kern_status_t set_add_object(struct object *set, struct object *obj);
|
|
|
|
|
extern kern_status_t set_remove_object(struct object *set, struct object *obj);
|
|
|
|
|
extern bool object_is_set(struct object *obj);
|
2023-02-17 19:36:14 +00:00
|
|
|
|
2023-06-02 19:34:33 +01:00
|
|
|
extern struct object *link_create(const char *name, struct object *dest);
|
|
|
|
|
extern struct object *link_read_ptr(struct object *link);
|
|
|
|
|
extern bool object_is_link(struct object *obj);
|
|
|
|
|
|
2023-02-17 19:36:14 +00:00
|
|
|
extern void init_set_objects(void);
|
2023-06-02 19:34:33 +01:00
|
|
|
extern void init_link_objects(void);
|
2023-02-17 19:36:14 +00:00
|
|
|
extern void init_global_namespace(void);
|
|
|
|
|
|
2023-03-20 20:41:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-02-17 19:36:14 +00:00
|
|
|
#endif
|