diff options
-rw-r--r-- | sys/kern/subr_kobj.c | 34 | ||||
-rw-r--r-- | sys/sys/kobj.h | 6 |
2 files changed, 33 insertions, 7 deletions
diff --git a/sys/kern/subr_kobj.c b/sys/kern/subr_kobj.c index 6b95eb9..2f3e60f 100644 --- a/sys/kern/subr_kobj.c +++ b/sys/kern/subr_kobj.c @@ -77,10 +77,9 @@ kobj_unregister_method(struct kobjop_desc *desc) { } -void -kobj_class_compile(kobj_class_t cls) +static void +kobj_class_compile_common(kobj_class_t cls, kobj_ops_t ops) { - kobj_ops_t ops; kobj_method_t *m; int i; @@ -97,17 +96,38 @@ kobj_class_compile(kobj_class_t cls) kobj_register_method(m->desc); /* - * Then allocate the compiled op table. + * Then initialise the ops table. */ - ops = malloc(sizeof(struct kobj_ops), M_KOBJ, M_NOWAIT); - if (!ops) - panic("kobj_compile_methods: out of memory"); bzero(ops, sizeof(struct kobj_ops)); ops->cls = cls; cls->ops = ops; } void +kobj_class_compile(kobj_class_t cls) +{ + kobj_ops_t ops; + + /* + * Allocate space for the compiled ops table. + */ + ops = malloc(sizeof(struct kobj_ops), M_KOBJ, M_NOWAIT); + if (!ops) + panic("kobj_compile_methods: out of memory"); + kobj_class_compile_common(cls, ops); +} + +void +kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops) +{ + /* + * Increment refs to make sure that the ops table is not freed. + */ + cls->refs++; + kobj_class_compile_common(cls, ops); +} + +void kobj_lookup_method(kobj_method_t *methods, kobj_method_t *ce, kobjop_desc_t desc) diff --git a/sys/sys/kobj.h b/sys/sys/kobj.h index bf10325..c291963 100644 --- a/sys/sys/kobj.h +++ b/sys/sys/kobj.h @@ -105,6 +105,12 @@ struct kobj_class name ## _class = { \ void kobj_class_compile(kobj_class_t cls); /* + * Compile the method table, with the caller providing the space for + * the ops table.(for use before malloc is initialised). + */ +void kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops); + +/* * Free the compiled method table in a class. */ void kobj_class_free(kobj_class_t cls); |