Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2053: Add utilities for allocating dynamic grants. r=bradjc a=daboross ### Pull Request Overview This pull request is intended to expand the basic functionality for dynamically allocating values. It: - changes the existing `alloc` method to accept non-`Default` values - adds a new method, `alloc_n_with`, for allocating a runtime-determined number of contiguous values - splits the internal `alloc_unowned` into `alloc_raw` and `alloc_default_unowned` to allow for allocating non-`Default` values I believe all of these changes will be useful, but the one which motivated this PR was `alloc_n_with`. To support connections in the Rubble BLE capsule, we'll need to support attributes, and the capsule won't know ahead of time how many attributes any given app will want to have in a connection. Attributes are most naturally stored in an array, and since the kernel won't know at compile time how many attributes an app has, we need dynamic allocation. Hence, `alloc_n_with`. Note that this PR leaves the usage of `Owned`, which I believe is unsound. Once we re-export `Owned` so that applications can store them, those applications could potentially store them outside of app-specific grant memory, and then access them after the app has been restarted (thus accessing deallocated memory). I have a fix for this, but since the changes are fairly separate, I've submitted it as a separate PR - #2052. If one PR is merged first, the other will need a rebase, but it shouldn't matter which one that is. CC @alevy ### Testing Strategy I created a temporary test capsule and app which calls `alloc` and `alloc_n_with` every other tick until we hit `OutOfMemory`, keeps each allocation one tick, and prints the data out after retrieving it. ### TODO or Help Wanted While this was manually tested, automated testing would be better. Do we have a place for unit tests for kernel functionality exposed to capsules? ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: David Ross <David.Ross@wdc.com>
- Loading branch information