flipper_application.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #pragma once
  2. #include "application_manifest.h"
  3. #include "elf/elf_api_interface.h"
  4. #include <furi.h>
  5. #include <storage/storage.h>
  6. #include <stdbool.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. typedef enum {
  11. FlipperApplicationPreloadStatusSuccess = 0,
  12. FlipperApplicationPreloadStatusUnspecifiedError,
  13. FlipperApplicationPreloadStatusInvalidFile,
  14. FlipperApplicationPreloadStatusInvalidManifest,
  15. FlipperApplicationPreloadStatusApiMismatch,
  16. FlipperApplicationPreloadStatusTargetMismatch,
  17. } FlipperApplicationPreloadStatus;
  18. typedef enum {
  19. FlipperApplicationLoadStatusSuccess = 0,
  20. FlipperApplicationLoadStatusUnspecifiedError,
  21. FlipperApplicationLoadStatusNoFreeMemory,
  22. FlipperApplicationLoadStatusMissingImports,
  23. } FlipperApplicationLoadStatus;
  24. /**
  25. * @brief Get text description of preload status
  26. * @param status Status code
  27. * @return String pointer to description
  28. */
  29. const char* flipper_application_preload_status_to_string(FlipperApplicationPreloadStatus status);
  30. /**
  31. * @brief Get text description of load status
  32. * @param status Status code
  33. * @return String pointer to description
  34. */
  35. const char* flipper_application_load_status_to_string(FlipperApplicationLoadStatus status);
  36. typedef struct FlipperApplication FlipperApplication;
  37. typedef struct {
  38. const char* name;
  39. uint32_t address;
  40. } FlipperApplicationMemoryMapEntry;
  41. typedef struct {
  42. uint32_t mmap_entry_count;
  43. FlipperApplicationMemoryMapEntry* mmap_entries;
  44. uint32_t debug_link_size;
  45. uint8_t* debug_link;
  46. } FlipperApplicationState;
  47. /**
  48. * @brief Initialize FlipperApplication object
  49. * @param storage Storage instance
  50. * @param api_interface ELF API interface to use for pre-loading and symbol resolving
  51. * @return Application instance
  52. */
  53. FlipperApplication*
  54. flipper_application_alloc(Storage* storage, const ElfApiInterface* api_interface);
  55. /**
  56. * @brief Destroy FlipperApplication object
  57. * @param app Application pointer
  58. */
  59. void flipper_application_free(FlipperApplication* app);
  60. /**
  61. * @brief Validate elf file and load application metadata
  62. * @param app Application pointer
  63. * @return Preload result code
  64. */
  65. FlipperApplicationPreloadStatus
  66. flipper_application_preload(FlipperApplication* app, const char* path);
  67. /**
  68. * @brief Get pointer to application manifest for preloaded application
  69. * @param app Application pointer
  70. * @return Pointer to application manifest
  71. */
  72. const FlipperApplicationManifest* flipper_application_get_manifest(FlipperApplication* app);
  73. /**
  74. * @brief Load sections and process relocations for already pre-loaded application
  75. * @param app Application pointer
  76. * @return Load result code
  77. */
  78. FlipperApplicationLoadStatus flipper_application_map_to_memory(FlipperApplication* app);
  79. /**
  80. * @brief Get state object for loaded application
  81. * @param app Application pointer
  82. * @return Pointer to state object
  83. */
  84. const FlipperApplicationState* flipper_application_get_state(FlipperApplication* app);
  85. /**
  86. * @brief Create application thread at entry point address, using app name and
  87. * stack size from metadata. Returned thread isn't started yet.
  88. * Can be only called once for application instance.
  89. * @param app Applicaiton pointer
  90. * @param args Object to pass to app's entry point
  91. * @return Created thread
  92. */
  93. FuriThread* flipper_application_spawn(FlipperApplication* app, void* args);
  94. /**
  95. * @brief Get previously spawned thread
  96. * @param app Application pointer
  97. * @return Created thread
  98. */
  99. FuriThread* flipper_application_get_thread(FlipperApplication* app);
  100. /**
  101. * @brief Return relocated and valid address of app's entry point
  102. * @param app Application pointer
  103. * @return Address of app's entry point
  104. */
  105. void const* flipper_application_get_entry_address(FlipperApplication* app);
  106. #ifdef __cplusplus
  107. }
  108. #endif