elf_file.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @file elf_file.h
  3. * ELF file loader
  4. */
  5. #pragma once
  6. #include <storage/storage.h>
  7. #include "../application_manifest.h"
  8. #include "elf_api_interface.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef struct ELFFile ELFFile;
  13. typedef struct {
  14. const char* name;
  15. uint32_t address;
  16. } ELFMemoryMapEntry;
  17. typedef struct {
  18. uint32_t debug_link_size;
  19. uint8_t* debug_link;
  20. } ELFDebugLinkInfo;
  21. typedef struct {
  22. uint32_t mmap_entry_count;
  23. ELFMemoryMapEntry* mmap_entries;
  24. ELFDebugLinkInfo debug_link_info;
  25. off_t entry;
  26. } ELFDebugInfo;
  27. typedef enum {
  28. ELFFileLoadStatusSuccess = 0,
  29. ELFFileLoadStatusUnspecifiedError,
  30. ELFFileLoadStatusNoFreeMemory,
  31. ELFFileLoadStatusMissingImports,
  32. } ELFFileLoadStatus;
  33. /**
  34. * @brief Allocate ELFFile instance
  35. * @param storage
  36. * @param api_interface
  37. * @return ELFFile*
  38. */
  39. ELFFile* elf_file_alloc(Storage* storage, const ElfApiInterface* api_interface);
  40. /**
  41. * @brief Free ELFFile instance
  42. * @param elf_file
  43. */
  44. void elf_file_free(ELFFile* elf_file);
  45. /**
  46. * @brief Open ELF file
  47. * @param elf_file
  48. * @param path
  49. * @return bool
  50. */
  51. bool elf_file_open(ELFFile* elf_file, const char* path);
  52. /**
  53. * @brief Load ELF file manifest
  54. * @param elf
  55. * @param manifest
  56. * @return bool
  57. */
  58. bool elf_file_load_manifest(ELFFile* elf, FlipperApplicationManifest* manifest);
  59. /**
  60. * @brief Load ELF file section table (load stage #1)
  61. * @param elf_file
  62. * @param manifest
  63. * @return bool
  64. */
  65. bool elf_file_load_section_table(ELFFile* elf_file, FlipperApplicationManifest* manifest);
  66. /**
  67. * @brief Load and relocate ELF file sections (load stage #2)
  68. * @param elf_file
  69. * @return ELFFileLoadStatus
  70. */
  71. ELFFileLoadStatus elf_file_load_sections(ELFFile* elf_file);
  72. /**
  73. * @brief Execute ELF file pre-run stage, call static constructors for example (load stage #3)
  74. * @param elf
  75. */
  76. void elf_file_pre_run(ELFFile* elf);
  77. /**
  78. * @brief Run ELF file (load stage #4)
  79. * @param elf_file
  80. * @param args
  81. * @return int32_t
  82. */
  83. int32_t elf_file_run(ELFFile* elf_file, void* args);
  84. /**
  85. * @brief Execute ELF file post-run stage, call static destructors for example (load stage #5)
  86. * @param elf
  87. */
  88. void elf_file_post_run(ELFFile* elf);
  89. /**
  90. * @brief Get ELF file API interface
  91. * @param elf_file
  92. * @return const ElfApiInterface*
  93. */
  94. const ElfApiInterface* elf_file_get_api_interface(ELFFile* elf_file);
  95. /**
  96. * @brief Get ELF file debug info
  97. * @param elf_file
  98. * @param debug_info
  99. */
  100. void elf_file_init_debug_info(ELFFile* elf_file, ELFDebugInfo* debug_info);
  101. /**
  102. * @brief Clear ELF file debug info generated by elf_file_init_debug_info
  103. * @param debug_info
  104. */
  105. void elf_file_clear_debug_info(ELFDebugInfo* debug_info);
  106. #ifdef __cplusplus
  107. }
  108. #endif