obj: add header-offset field to object_type
this allows the object header to be placed anywhere within the larger object structure. the object system now also ensures that the object is zero-initialised during allocation.
This commit is contained in:
@@ -48,6 +48,7 @@ struct object_type {
|
|||||||
enum object_type_flags ob_flags;
|
enum object_type_flags ob_flags;
|
||||||
char ob_name[32];
|
char ob_name[32];
|
||||||
unsigned int ob_size;
|
unsigned int ob_size;
|
||||||
|
unsigned int ob_header_offset;
|
||||||
struct vm_cache ob_cache;
|
struct vm_cache ob_cache;
|
||||||
struct queue_entry ob_list;
|
struct queue_entry ob_list;
|
||||||
struct queue ob_attrib;
|
struct queue ob_attrib;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ static kern_status_t kext_destroy(struct object *obj)
|
|||||||
static struct object_type kext_type = {
|
static struct object_type kext_type = {
|
||||||
.ob_name = "kext",
|
.ob_name = "kext",
|
||||||
.ob_size = sizeof(struct kext),
|
.ob_size = sizeof(struct kext),
|
||||||
|
.ob_header_offset = offsetof(struct kext, k_base),
|
||||||
.ob_ops = {
|
.ob_ops = {
|
||||||
.query_name = kext_query_name,
|
.query_name = kext_query_name,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ static kern_status_t ns_get_child_named(struct object *obj, const char *name, st
|
|||||||
static struct object_type ns_type = {
|
static struct object_type ns_type = {
|
||||||
.ob_name = "namespace",
|
.ob_name = "namespace",
|
||||||
.ob_size = sizeof(struct object_namespace),
|
.ob_size = sizeof(struct object_namespace),
|
||||||
|
.ob_header_offset = offsetof(struct object_namespace, ns_base),
|
||||||
.ob_ops = {
|
.ob_ops = {
|
||||||
.query_name = ns_query_name,
|
.query_name = ns_query_name,
|
||||||
.get_named = ns_get_child_named,
|
.get_named = ns_get_child_named,
|
||||||
|
|||||||
@@ -48,11 +48,15 @@ struct object *object_create(struct object_type *type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct vm_cache *cache = &type->ob_cache;
|
struct vm_cache *cache = &type->ob_cache;
|
||||||
struct object *obj = vm_cache_alloc(cache, 0);
|
void *obj_buf = vm_cache_alloc(cache, 0);
|
||||||
if (!obj) {
|
if (!obj_buf) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(obj_buf, 0x00, type->ob_size);
|
||||||
|
|
||||||
|
struct object *obj = (struct object *)((unsigned char *)obj_buf + type->ob_header_offset);
|
||||||
|
|
||||||
obj->ob_type = type;
|
obj->ob_type = type;
|
||||||
obj->ob_lock = SPIN_LOCK_INIT;
|
obj->ob_lock = SPIN_LOCK_INIT;
|
||||||
obj->ob_magic = OBJECT_MAGIC;
|
obj->ob_magic = OBJECT_MAGIC;
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ static kern_status_t set_get_child_named(struct object *obj, const char *name, s
|
|||||||
static struct object_type set_type = {
|
static struct object_type set_type = {
|
||||||
.ob_name = "set",
|
.ob_name = "set",
|
||||||
.ob_size = sizeof(struct set),
|
.ob_size = sizeof(struct set),
|
||||||
|
.ob_header_offset = offsetof(struct set, s_base),
|
||||||
.ob_ops = {
|
.ob_ops = {
|
||||||
.query_name = set_query_name,
|
.query_name = set_query_name,
|
||||||
.get_named = set_get_child_named,
|
.get_named = set_get_child_named,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
static struct object_type task_type = {
|
static struct object_type task_type = {
|
||||||
.ob_name = "task",
|
.ob_name = "task",
|
||||||
.ob_size = sizeof(struct task),
|
.ob_size = sizeof(struct task),
|
||||||
|
.ob_header_offset = offsetof(struct task, t_base),
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct task *__kernel_task;
|
static struct task *__kernel_task;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
static struct object_type thread_type = {
|
static struct object_type thread_type = {
|
||||||
.ob_name = "thread",
|
.ob_name = "thread",
|
||||||
.ob_size = sizeof(struct thread),
|
.ob_size = sizeof(struct thread),
|
||||||
|
.ob_header_offset = offsetof(struct thread, thr_base),
|
||||||
};
|
};
|
||||||
|
|
||||||
kern_status_t thread_object_type_init(void)
|
kern_status_t thread_object_type_init(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user