提交 5a8d5a56 编写于 作者: qiuyiuestc's avatar qiuyiuestc

update module

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1097 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 c5c956a8
...@@ -377,7 +377,7 @@ struct rt_thread ...@@ -377,7 +377,7 @@ struct rt_thread
*/ */
#define RT_MODULE_FLAG_WITHENTRY 0x00 /* with entry point */ #define RT_MODULE_FLAG_WITHENTRY 0x00 /* with entry point */
#define RT_MODULE_FLAG_WITHOUTENTRY 0x01 /* no entry point */ #define RT_MODULE_FLAG_WITHOUTENTRY 0x01 /* without entry point */
struct rt_module struct rt_module
{ {
......
...@@ -316,7 +316,7 @@ void *rt_module_realloc(void *ptr, rt_size_t size); ...@@ -316,7 +316,7 @@ void *rt_module_realloc(void *ptr, rt_size_t size);
void rt_module_free(rt_module_t module, void *addr); void rt_module_free(rt_module_t module, void *addr);
rt_module_t rt_module_self (void); rt_module_t rt_module_self (void);
rt_err_t rt_module_set (rt_module_t module); rt_err_t rt_module_set (rt_module_t module);
rt_module_t rt_module_find(char* name); rt_module_t rt_module_find(const char* name);
#endif #endif
/* /*
......
...@@ -253,9 +253,8 @@ rt_module_t rt_module_load(const rt_uint8_t* name, void* module_ptr) ...@@ -253,9 +253,8 @@ rt_module_t rt_module_load(const rt_uint8_t* name, void* module_ptr)
rt_uint8_t *ptr, *strtab; rt_uint8_t *ptr, *strtab;
rt_bool_t linked = RT_FALSE; rt_bool_t linked = RT_FALSE;
#ifdef RT_MODULE_DEBUG
rt_kprintf("rt_module_load: %s\n", name); rt_kprintf("rt_module_load: %s\n", name);
#endif
/* check ELF header */ /* check ELF header */
if (rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) == 0) if (rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) == 0)
{ {
...@@ -393,11 +392,10 @@ rt_module_t rt_module_load(const rt_uint8_t* name, void* module_ptr) ...@@ -393,11 +392,10 @@ rt_module_t rt_module_load(const rt_uint8_t* name, void* module_ptr)
/* init module memory allocator */ /* init module memory allocator */
module->module_mem_list = RT_NULL; module->module_mem_list = RT_NULL;
module->page_node_pool = rt_malloc(sizeof(struct rt_mempool)); module->page_node_pool = RT_NULL;
rt_memset(module->page_node_pool, 0, sizeof(struct rt_mempool));
/* create module thread */ /* create module thread */
module->stack_size = 512; module->stack_size = 2048;
module->thread_priority = 90; module->thread_priority = 90;
module->module_thread = rt_thread_create(name, module->module_thread = rt_thread_create(name,
module->module_entry, RT_NULL, module->module_entry, RT_NULL,
...@@ -447,7 +445,9 @@ rt_module_t rt_module_open(const char* filename) ...@@ -447,7 +445,9 @@ rt_module_t rt_module_open(const char* filename)
rt_free(buffer); rt_free(buffer);
return RT_NULL; return RT_NULL;
} }
rt_kprintf("read %d bytes from file\n", length);
/* rt_kprintf("read %d bytes from file\n", length); */
module = rt_module_load(filename, (void *)buffer); module = rt_module_load(filename, (void *)buffer);
rt_free(buffer); rt_free(buffer);
close(fd); close(fd);
...@@ -474,13 +474,12 @@ rt_err_t rt_module_unload(rt_module_t module) ...@@ -474,13 +474,12 @@ rt_err_t rt_module_unload(rt_module_t module)
struct rt_object* object; struct rt_object* object;
struct rt_list_node *list; struct rt_list_node *list;
#ifdef RT_MODULE_DEBUG rt_kprintf("rt_module_unload: %s\n", module->parent.name);
rt_kprintf("rt_module_unload %s\n", module->parent.name);
#endif
/* check parameter */ /* check parameter */
RT_ASSERT(module != RT_NULL); RT_ASSERT(module != RT_NULL);
/* module has entry point */
if(!(module->parent.flag & RT_MODULE_FLAG_WITHOUTENTRY)) if(!(module->parent.flag & RT_MODULE_FLAG_WITHOUTENTRY))
{ {
/* suspend module main thread */ /* suspend module main thread */
...@@ -660,16 +659,18 @@ rt_err_t rt_module_unload(rt_module_t module) ...@@ -660,16 +659,18 @@ rt_err_t rt_module_unload(rt_module_t module)
rt_list_remove(list->next); rt_list_remove(list->next);
} }
/* free page node mempool */ if(module->page_node_pool)
if(((struct rt_mempool*)module->page_node_pool)->start_address != 0) {
rt_page_free(((struct rt_mempool*)module->page_node_pool)->start_address, 1); /* free page node mempool */
if(((struct rt_mempool*)module->page_node_pool)->start_address != 0)
rt_page_free(((struct rt_mempool*)module->page_node_pool)->start_address, 1);
/* detach page node mempool */ /* detach page node mempool */
if(module->page_node_pool != RT_NULL)
rt_mp_detach(module->page_node_pool); rt_mp_detach(module->page_node_pool);
/* free page node mempool structure */ /* free page node mempool structure */
rt_free(module->page_node_pool); rt_free(module->page_node_pool);
}
} }
/* release module space memory */ /* release module space memory */
...@@ -688,7 +689,7 @@ rt_err_t rt_module_unload(rt_module_t module) ...@@ -688,7 +689,7 @@ rt_err_t rt_module_unload(rt_module_t module)
* *
* @return the module * @return the module
*/ */
rt_module_t rt_module_find(char* name) rt_module_t rt_module_find(const char* name)
{ {
struct rt_object_information *information; struct rt_object_information *information;
struct rt_object* object; struct rt_object* object;
...@@ -733,8 +734,11 @@ static struct rt_mem_head *morepage(rt_size_t nu) ...@@ -733,8 +734,11 @@ static struct rt_mem_head *morepage(rt_size_t nu)
cp = rt_page_alloc(npage); cp = rt_page_alloc(npage);
if(cp == RT_NULL) return RT_NULL; if(cp == RT_NULL) return RT_NULL;
if(((struct rt_mempool*)rt_current_module->page_node_pool)->start_address == 0) if(!rt_current_module->page_node_pool)
{ {
rt_current_module->page_node_pool = rt_malloc(sizeof(struct rt_mempool));
rt_memset(rt_current_module->page_node_pool, 0, sizeof(struct rt_mempool));
/* allocate a page for page node */ /* allocate a page for page node */
void *start = rt_page_alloc(1); void *start = rt_page_alloc(1);
rt_mp_init( rt_mp_init(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册