-
-
Notifications
You must be signed in to change notification settings - Fork 95
Run executables directly #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
92e5c9b
Make it possible to run elf/so files directly
KenVanHoeylandt e0f3c42
Update build scripts
KenVanHoeylandt a58638c
Refactor execution logic
KenVanHoeylandt 43ccaf0
Remove exec path check and simplify API
KenVanHoeylandt e08300d
Remove unused header
KenVanHoeylandt dd40580
Cleanup
KenVanHoeylandt 3f11b76
Harden arguments.h and add tests
KenVanHoeylandt d42c68c
Comments updated
KenVanHoeylandt 4db0d94
Fix for inputdialog
KenVanHoeylandt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
|
|
||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| // <elf.h> is not guaranteed to exist under the ESP32 newlib toolchain | ||
| #define ELF_CLASS_32 1 | ||
| #define ELF_CLASS_64 2 | ||
| #define ELF_DATA_2LSB 1 | ||
| #define ELF_TYPE_DYN 3 | ||
| #define ELF_MACHINE_XTENSA 94 | ||
| #define ELF_MACHINE_RISCV 243 | ||
| #define ELF_MACHINE_X86_64 62 | ||
| #define ELF_MACHINE_AARCH64 183 | ||
|
|
||
| /** What a loader needs an ELF file's header to say before it will try to load it. */ | ||
| struct ElfRequirements { | ||
| uint8_t elf_class; /**< ELF_CLASS_32 / ELF_CLASS_64 */ | ||
| uint8_t data; /**< ELF_DATA_2LSB */ | ||
| uint16_t type; /**< ELF_TYPE_DYN */ | ||
| uint16_t machine; /**< ELF_MACHINE_XTENSA / _RISCV / _X86_64 / _AARCH64 */ | ||
| }; | ||
|
|
||
| /** | ||
| * Reads the first 20 bytes of @a path (e_ident, e_type, e_machine; identical offsets for | ||
| * ELF32 and ELF64) and checks the magic number and every field in @a requirements match. | ||
| * @return false if @a path can't be opened, is too short, or doesn't match | ||
| */ | ||
| bool elf_check_file(const char* path, const struct ElfRequirements* requirements); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
|
|
||
| /** | ||
| * This file contains functions to start and run apps. | ||
| * It differs from start.h by running apps directly from the specified location, | ||
| * instead of having to register them first via an AppManifest and the app manager. | ||
| */ | ||
|
|
||
| #include <app/manager.h> | ||
|
|
||
| #include <stdbool.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * Starts an app directly from @a location, without it having to be pre-registered via | ||
| * app_manager_add() first. | ||
| * Performs no checks of its own beyond what AppLoaderApi::load() itself rejects. | ||
| * @warning It's advised to validate @a location with app_is_executable() first | ||
| * @param[in] stack stack allocation config for the app's task; all-zero uses the scheduler's | ||
| * default depth/capability, same as an AppManifest that leaves AppManifest::stack zeroed | ||
| * @retval ERROR_NOT_FOUND no AppLoaderApi is registered for @a location.type | ||
| * @retval ERROR_NONE on success | ||
| */ | ||
| error_t app_execute( | ||
| struct AppLocation location, | ||
| struct AppStackConfig stack, | ||
| int argc, | ||
| const char* const argv[], | ||
| AppInstanceId* out_app_instance_id | ||
| ); | ||
|
|
||
| /** | ||
| * Same as app_execute(), but as a modal child of @a parent_instance_id. | ||
| * See app_start_for_result()'s own doc for the result-delivery contract. | ||
| * @retval ERROR_NOT_FOUND no AppLoaderApi is registered for @a location.type | ||
| * @retval ERROR_NONE on success | ||
| */ | ||
| error_t app_execute_for_result( | ||
| struct AppLocation location, | ||
| struct AppStackConfig stack, | ||
| int argc, | ||
| const char* const argv[], | ||
| AppInstanceId parent_instance_id, | ||
| AppInstanceId* out_app_instance_id | ||
| ); | ||
|
|
||
| /** | ||
| * Same as app_execute(), but installs @a bindings into the new instance's fd table before its | ||
| * task begins executing. See app_start_with_streams()'s own doc for stream ownership. | ||
| * @param[in] bindings see app_start_with_streams() | ||
| * @retval ERROR_NOT_FOUND no AppLoaderApi is registered for @a location.type | ||
| * @retval ERROR_OUT_OF_RANGE a binding's producer_fd is out of range | ||
| * @retval ERROR_RESOURCE a binding's event_group has no free bits left to claim | ||
| * @retval ERROR_NONE on success | ||
| */ | ||
| error_t app_execute_with_streams( | ||
| struct AppLocation location, | ||
| struct AppStackConfig stack, | ||
| int argc, | ||
| const char* const argv[], | ||
| const struct AppStreamBinding* bindings, | ||
| size_t binding_count, | ||
| AppInstanceId* out_app_instance_id | ||
| ); | ||
|
|
||
| /** | ||
| * Combines app_execute_for_result() and app_execute_with_streams(). | ||
| * @param[in] bindings see app_start_with_streams() | ||
| * @retval ERROR_NOT_FOUND no AppLoaderApi is registered for @a location.type | ||
| * @retval ERROR_OUT_OF_RANGE a binding's producer_fd is out of range | ||
| * @retval ERROR_RESOURCE a binding's event_group has no free bits left to claim | ||
| * @retval ERROR_NONE on success | ||
| */ | ||
| error_t app_execute_for_result_with_streams( | ||
| struct AppLocation location, | ||
| struct AppStackConfig stack, | ||
| int argc, | ||
| const char* const argv[], | ||
| const struct AppStreamBinding* bindings, | ||
| size_t binding_count, | ||
| AppInstanceId parent_instance_id, | ||
| AppInstanceId* out_app_instance_id | ||
| ); | ||
|
|
||
| /** | ||
| * Reports whether @a location is runnable on this target: the extension and header a loader | ||
| * requires (e.g. an ELF's class/data/type/machine), not whether it lives anywhere in particular. | ||
| * Any executable app is runnable from any path. Cheap enough to call while listing a directory. | ||
| * @return false if @a location can't be run, or if no AppLoaderApi is registered for its type | ||
| */ | ||
| bool app_is_executable(struct AppLocation location); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.