diff --git a/sys/kern/subr_kobj.c b/sys/kern/subr_kobj.c index 6b95eb9d593..2f3e60ff0a5 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,14 +96,35 @@ kobj_class_compile(kobj_class_t cls) kobj_register_method(m->desc); /* - * Then allocate the compiled op table. + * Then initialise the ops table. + */ + 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"); - bzero(ops, sizeof(struct kobj_ops)); - ops->cls = cls; - cls->ops = ops; + 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 diff --git a/sys/sys/kobj.h b/sys/sys/kobj.h index bf10325399d..c2919636419 100644 --- a/sys/sys/kobj.h +++ b/sys/sys/kobj.h @@ -104,6 +104,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. */