-
-
Notifications
You must be signed in to change notification settings - Fork 770
static_buf!()
: Remove StaticUninitializedBuffer
and UninitializedBuffer
in favor of MaybeUninit
, update component conventions to match
#3239
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a major step forward for components. The singleton-without-enforcement property of components has long been a pain point for Tock, and this is a step towards eliminating that rough edge.
static_buf!()
: Remove StaticUninitializedBuffer
and UninitializedBuffer
in favor of MaybeUninit
static_buf!()
: Remove StaticUninitializedBuffer
and UninitializedBuffer
in favor of MaybeUninit
, update component conventions to match
4a70cf7
to
ab89f67
Compare
let hmac = &perf.hmac; | ||
|
||
let callback = unsafe { static_init_test_cb() }; | ||
let callback = unsafe { static_init_test_cb!() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised you don't get warnings that this unsafe is not needed
That is, `static_buf!()` will now panic if the same static buffer is used multiple times. This happens if the same `static_buf!()` expansion is run multiple times, such is if `static_buf!()` is in a function which is called multiple times. Since doing this causes memory to be aliased which is bad, we panic to let the board author know this needs to be fixed. Also: doc: update soundness with new static_init impl
ab89f67
to
8f80902
Compare
8f80902
to
8fad119
Compare
8fad119
to
def33a3
Compare
The most recent version of this PR (which @bradjc just updated) requires |
There was some discussion outside GitHub about the desire for a zero-cost variant that doesn't dynamically check if a value has already been initialized, though the uses of this would likely be only out-of-tree (at least for now). I think this is pretty simple to implement, but would vote for leaving this either out-of-tree for now or doing it in a separate pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a chance to actually read this over now, sorry I wasn't so engaged earlier today. I agree this is better than what we have, and we should make the stepwise improvement here.
bors r+ |
3245: boards/opentitan/tests: fixup macro syntax r=ppannuto a=twilfredo ### Pull Request Overview The following changes address the compiler warning generated [1] when building tests: Since: #3239 [1]: `warning: trailing semicolon in macro used in expression position` The exact warning: ``` warning: trailing semicolon in macro used in expression position --> boards/opentitan/earlgrey-cw310/src/tests/flash_ctrl.rs:92:6 | 92 | };}; | ^ ... 104 | let cb = unsafe { static_init_test!() }; | ------------------- in this macro invocation | = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #79813 <rust-lang/rust#79813> = note: macro invocations at the end of a block are treated as expressions = note: to ignore the value produced by the macro, add a semicolon after the invocation of `static_init_test` = note: this warning originates in the macro `static_init_test` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ### Testing Strategy Compiling and testing on Verilator ### TODO or Help Wanted N/A ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make prepush`. Co-authored-by: Wilfred Mallawa <[email protected]>
Pull Request Overview
This pull request builds on top of #3219 , with some additional optimizations for size to reduce the overhead introduced in #3219. This PR removes
StaticUninitializedBuffer
andUninitializedBuffer
, since I believe they now offer very little overMaybeUninit
today (other than a slightly nicer name forinitialize()
vswrite()
.This combination of changes makes it no longer
unsafe
to callstatic_init!()
orstatic_buf!()
. A logical followup change is to removeunsafe
fromstatic_buf!()
and makeComponent::finalize()
safe. This change should allow us to remove >90% of the unsafe code inmain.rs
, a big jump forward for validating memory safety in Tock.On Imix, this brings the overhead of #3219 down to 1104 bytes. Notably, once Brad finishes porting uses of
static_init_half!()
tostatic_buf!()
, this overhead will increase.Apologies for the weird commit ordering, where #3219 comes after my changes -- I implemented my changes first and then pulled in the #3219 changes in a squashed commit. Ultimately I think that #3219 should just be closed in favor of this PR.
This PR also defines the expected process for a component: all statically declared memory is created in a macro and passed in to
finalize()
. That macro has a naming convention of[name]_component_static!()
. No memory is statically allocated infinalize()
(i.e. no static_init! or static_buf! in the finalize function). That macro only statically declares memory.Testing Strategy
This pull request was tested by compiling.
TODO or Help Wanted
After this PR is merged, Brad's various component PRs will need to be rebased to useMaybeUninit
as theStaticInput
to components.Documentation Updated
Formatting
make prepush
.