xref: /nrf52832-nimble/rt-thread/components/libc/libdl/dlmodule.h (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2018/08/11     Bernard      the first version
9  */
10 
11 #ifndef RT_DL_MODULE_H__
12 #define RT_DL_MODULE_H__
13 
14 #include <rtthread.h>
15 
16 #define RT_DLMODULE_STAT_INIT       0x00
17 #define RT_DLMODULE_STAT_RUNNING    0x01
18 #define RT_DLMODULE_STAT_CLOSING    0x02
19 #define RT_DLMODULE_STAT_CLOSED     0x03
20 
21 struct rt_dlmodule;
22 typedef void* rt_addr_t;
23 
24 typedef void (*rt_dlmodule_init_func_t)(struct rt_dlmodule *module);
25 typedef void (*rt_dlmodule_cleanup_func_t)(struct rt_dlmodule *module);
26 typedef int  (*rt_dlmodule_entry_func_t)(int argc, char** argv);
27 
28 struct rt_dlmodule
29 {
30     struct rt_object parent;
31     rt_list_t object_list;  /* objects inside this module */
32 
33     rt_uint8_t stat;        /* status of module */
34 
35     /* main thread of this module */
36     rt_uint16_t priority;
37     rt_uint32_t stack_size;
38     struct rt_thread *main_thread;
39     /* the return code */
40     int ret_code;
41 
42     /* VMA base address for the first LOAD segment */
43     rt_uint32_t vstart_addr;
44 
45     /* module entry, RT_NULL for dynamic library */
46     rt_dlmodule_entry_func_t  entry_addr;
47     char *cmd_line;         /* command line */
48 
49     rt_addr_t   mem_space;  /* memory space */
50     rt_uint32_t mem_size;   /* sizeof memory space */
51 
52     /* init and clean function */
53     rt_dlmodule_init_func_t     init_func;
54     rt_dlmodule_cleanup_func_t  cleanup_func;
55 
56     rt_uint16_t nref;       /* reference count */
57 
58     rt_uint16_t nsym;       /* number of symbols in the module */
59     struct rt_module_symtab *symtab;    /* module symbol table */
60 };
61 
62 struct rt_dlmodule *dlmodule_create(void);
63 rt_err_t dlmodule_destroy(struct rt_dlmodule* module);
64 
65 struct rt_dlmodule *dlmodule_self(void);
66 
67 struct rt_dlmodule *dlmodule_load(const char* pgname);
68 struct rt_dlmodule *dlmodule_exec(const char* pgname, const char* cmd, int cmd_size);
69 void dlmodule_exit(int ret_code);
70 
71 struct rt_dlmodule *dlmodule_find(const char *name);
72 
73 rt_uint32_t dlmodule_symbol_find(const char *sym_str);
74 
75 #endif
76