obj: object header is no longer allocated automatically

This commit is contained in:
2023-05-06 19:48:14 +01:00
parent 79c30e5393
commit f52ca2f1e2
13 changed files with 97 additions and 66 deletions

View File

@@ -3,13 +3,18 @@
#include <socks/init.h>
#include <socks/libc/stdio.h>
#define TEST_CAST(p) OBJECT_C_CAST(struct test_object, base, &test_type, p)
struct test_object {
struct object base;
char name[OBJECT_NAME_MAX];
};
static struct object_type test_type;
static kern_status_t test_query_name(struct object *obj, char out[OBJECT_NAME_MAX])
{
struct test_object *test = object_data(obj);
struct test_object *test = TEST_CAST(obj);
strncpy(out, test->name, OBJECT_NAME_MAX);
out[OBJECT_NAME_MAX - 1] = 0;
return KERN_OK;
@@ -37,10 +42,10 @@ static void print_object_tree(struct object *obj, int depth)
len += snprintf(msg + len, sizeof msg - len, "%s", name);
printk(msg);
struct object *child = NULL;
size_t i = 0;
while (1) {
kern_status_t status = object_get_child_at(obj, i, &child);
if (status != KERN_OK) {
@@ -58,7 +63,7 @@ static int run_obj_tests(void)
object_type_register(&test_type);
struct object *test_obj = object_create(&test_type);
struct test_object *test = object_data(test_obj);
struct test_object *test = TEST_CAST(test_obj);
snprintf(test->name, sizeof test->name, "object1");
kern_status_t status = object_publish(global_namespace(), "/misc/objects", test_obj);
if (status == KERN_OK) {
@@ -73,7 +78,7 @@ static int run_obj_tests(void)
return -1;
}
print_object_tree(object_header(global_namespace()), 0);
print_object_tree(ns_header(global_namespace()), 0);
return 0;
}