From efe4523132169a4f28b84b1820a1a71d35118965 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 30 Aug 2018 20:27:45 +0800 Subject: [Kernel] move module tolibc/libdl. --- src/object.c | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'src/object.c') diff --git a/src/object.c b/src/object.c index b09af9ddee..e9a2b99246 100644 --- a/src/object.c +++ b/src/object.c @@ -32,6 +32,10 @@ #include #include +#ifdef RT_USING_MODULE +#include +#endif + /* * define object_info for the number of rt_object_container items. */ @@ -111,7 +115,7 @@ static struct rt_object_information rt_object_container[RT_Object_Info_Unknown] {RT_Object_Class_Timer, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Timer), sizeof(struct rt_timer)}, #ifdef RT_USING_MODULE /* initialize object container - module */ - {RT_Object_Class_Module, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Module), sizeof(struct rt_module)}, + {RT_Object_Class_Module, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Module), sizeof(struct rt_dlmodule)}, #endif }; @@ -251,6 +255,9 @@ void rt_object_init(struct rt_object *object, { register rt_base_t temp; struct rt_object_information *information; +#ifdef RT_USING_MODULE + struct rt_dlmodule *module = dlmodule_self(); +#endif /* get object information */ information = rt_object_get_information(type); @@ -269,8 +276,18 @@ void rt_object_init(struct rt_object *object, /* lock interrupt */ temp = rt_hw_interrupt_disable(); - /* insert object into information object list */ - rt_list_insert_after(&(information->object_list), &(object->list)); +#ifdef RT_USING_MODULE + if (module) + { + rt_list_insert_after(&(module->object_list), &(object->list)); + object->module_id = (void *)module; + } + else +#endif + { + /* insert object into information object list */ + rt_list_insert_after(&(information->object_list), &(object->list)); + } /* unlock interrupt */ rt_hw_interrupt_enable(temp); @@ -318,6 +335,9 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name) struct rt_object *object; register rt_base_t temp; struct rt_object_information *information; +#ifdef RT_USING_MODULE + struct rt_dlmodule *module = dlmodule_self(); +#endif RT_DEBUG_NOT_IN_INTERRUPT; @@ -332,6 +352,9 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name) return RT_NULL; } + /* clean memory data of object */ + rt_memset(object, 0x0, information->object_size); + /* initialize object's parameters */ /* set object type */ @@ -340,14 +363,6 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name) /* set object flag */ object->flag = 0; -#ifdef RT_USING_MODULE - if (rt_module_self() != RT_NULL) - { - object->flag |= RT_OBJECT_FLAG_MODULE; - } - object->module_id = (void *)rt_module_self(); -#endif - /* copy name */ rt_strncpy(object->name, name, RT_NAME_MAX); @@ -356,8 +371,18 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name) /* lock interrupt */ temp = rt_hw_interrupt_disable(); - /* insert object into information object list */ - rt_list_insert_after(&(information->object_list), &(object->list)); +#ifdef RT_USING_MODULE + if (module) + { + rt_list_insert_after(&(module->object_list), &(object->list)); + object->module_id = (void *)module; + } + else +#endif + { + /* insert object into information object list */ + rt_list_insert_after(&(information->object_list), &(object->list)); + } /* unlock interrupt */ rt_hw_interrupt_enable(temp); -- cgit v1.3.1