1
0

dlmodule.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2006-2021, 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. #ifndef RT_DL_MODULE_H__
  11. #define RT_DL_MODULE_H__
  12. #include <rtthread.h>
  13. #define RT_DLMODULE_STAT_INIT 0x00
  14. #define RT_DLMODULE_STAT_RUNNING 0x01
  15. #define RT_DLMODULE_STAT_CLOSING 0x02
  16. #define RT_DLMODULE_STAT_CLOSED 0x03
  17. struct rt_dlmodule;
  18. typedef void* rt_addr_t;
  19. typedef void (*rt_dlmodule_init_func_t)(struct rt_dlmodule *module);
  20. typedef void (*rt_dlmodule_cleanup_func_t)(struct rt_dlmodule *module);
  21. typedef int (*rt_dlmodule_entry_func_t)(int argc, char** argv);
  22. struct rt_dlmodule
  23. {
  24. struct rt_object parent;
  25. rt_list_t object_list; /* objects inside this module */
  26. rt_uint8_t stat; /* status of module */
  27. /* main thread of this module */
  28. rt_uint16_t priority;
  29. rt_uint32_t stack_size;
  30. struct rt_thread *main_thread;
  31. /* the return code */
  32. int ret_code;
  33. /* VMA base address for the first LOAD segment */
  34. rt_uint32_t vstart_addr;
  35. /* module entry, RT_NULL for dynamic library */
  36. rt_dlmodule_entry_func_t entry_addr;
  37. char *cmd_line; /* command line */
  38. rt_addr_t mem_space; /* memory space */
  39. rt_uint32_t mem_size; /* sizeof memory space */
  40. /* init and clean function */
  41. rt_dlmodule_init_func_t init_func;
  42. rt_dlmodule_cleanup_func_t cleanup_func;
  43. rt_uint16_t nref; /* reference count */
  44. rt_uint16_t nsym; /* number of symbols in the module */
  45. struct rt_module_symtab *symtab; /* module symbol table */
  46. };
  47. struct rt_dlmodule_ops
  48. {
  49. rt_uint8_t *(*load)(const char* filename); /* load dlmodule file data */
  50. rt_err_t (*unload)(rt_uint8_t *param); /* unload dlmodule file data */
  51. };
  52. struct rt_dlmodule *dlmodule_create(void);
  53. rt_err_t dlmodule_destroy(struct rt_dlmodule* module);
  54. struct rt_dlmodule *dlmodule_self(void);
  55. struct rt_dlmodule *dlmodule_load(const char* pgname);
  56. struct rt_dlmodule *dlmodule_exec(const char* pgname, const char* cmd, int cmd_size);
  57. #if defined(RT_USING_CUSTOM_DLMODULE)
  58. struct rt_dlmodule* dlmodule_load_custom(const char* filename, struct rt_dlmodule_ops* ops);
  59. struct rt_dlmodule* dlmodule_exec_custom(const char* pgname, const char* cmd, int cmd_size, struct rt_dlmodule_ops* ops);
  60. #endif
  61. void dlmodule_exit(int ret_code);
  62. struct rt_dlmodule *dlmodule_find(const char *name);
  63. rt_uint32_t dlmodule_symbol_find(const char *sym_str);
  64. #endif