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,11 +48,15 @@ struct object *object_create(struct object_type *type)
|
||||
}
|
||||
|
||||
struct vm_cache *cache = &type->ob_cache;
|
||||
struct object *obj = vm_cache_alloc(cache, 0);
|
||||
if (!obj) {
|
||||
void *obj_buf = vm_cache_alloc(cache, 0);
|
||||
if (!obj_buf) {
|
||||
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_lock = SPIN_LOCK_INIT;
|
||||
obj->ob_magic = OBJECT_MAGIC;
|
||||
|
||||
Reference in New Issue
Block a user