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.
What was added?
Added support for rbpf to run on
no_std
environments.Why is it needed?
Using rbpf on targets without
std
support increases compatibility of the crate.A more high-level motivation is that running eBPF VMs on microcontrollers is an interesting way of performing over-the-air
updates of business logic deployed on IOT devices. It also allows for compartmentalization of multiple programs deployed on a single device. I'm currently working on my Master's project which aims to implement a system for running eBPF programs on low-end microcontrollers in RIOT OS (can be found here).
Testing
Currently the code compiles on with both configuration options enabled.
Compilation for native can be tested using the default
cargo build
. Theno_std
port can be tested usingRemaining items for the PR
no_std
specific tests and some testsuite environment using an emulator.Notes
For my project I'm currently using a more heavily-modified version of rbpf which has already diverged from the upstream repo.
I decided to bring over the
no_std
support changes back to this branch. This was because they are fairly easy to isolate and the additional changes that I have made might not be applicable to the general intended use-cases of rbpf.When implementing the
no_std
port, I used this guide It seems to work well, however I realise that it introduces a somewhat bespoke way of handling imports (with the new concept ofstdlib
module) which might not match the expectations of the maintainers of rbpf. I'm open to discussion as to how the conditional imports of different versions based on std/no_std setting should be handled. Currently they are isolated inside of three modules:with_std
,without_std
,with_alloc
which reexport the required imports. A correct combination of those import files is then included inlib.rs
depending on the configuration.For instance, an alternative approach which doesn't require the bespoke modules is to always handle all imports conditionally like so:
This approach has an advantage of not requiring additional files to correctly reexport required modules. However the cost is that all imports of things that require an allocator e.g. Vec, String, would need to be duplicated and gated with the corresponding cfg annotations.
The biggest advantage in this case would be that the overall file structure of rbpf would remain unchanged so
no_std
could be supported with minimal intervention in the existing codebase.