Skip to content

Simplify via zerocopy::FromZeros::new_box_zeroed - #919

Merged
Jay Bosamiya (Microsoft) (jaybosamiya-ms) merged 1 commit into
microsoft:mainfrom
lschuermann:dev/box-new-zeroed-opt
Aug 14, 2026
Merged

Simplify via zerocopy::FromZeros::new_box_zeroed#919
Jay Bosamiya (Microsoft) (jaybosamiya-ms) merged 1 commit into
microsoft:mainfrom
lschuermann:dev/box-new-zeroed-opt

Conversation

@lschuermann

@lschuermann Leon Schuermann (lschuermann) commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

The existing implementation of box_new_zeroed was unnecessarily complex. This PR simplifies it.

@lschuermann

Copy link
Copy Markdown
Contributor Author

I see that the ratchet::ratchet_maybe_uninit test fails, which I assume is just a guard to ensure one is not inadvertently adding a new unsafe transmute? Either way, I think this is cleaner and more idiomatic; should I go ahead and add a path prefix to the ratchet test accordingly?

@jaybosamiya-ms Jay Bosamiya (Microsoft) (jaybosamiya-ms) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall seems good to me, thanks Leon! Minor stylistic thing: prefer SAFETY: ... comment rather than # Safety\n\n... comment when discharging a safety obligation.

Also, fwiw, maybe we should use FromZeros::new_box_zeroed instead of the current body? Might need to tweak Cargo.toml to pull in the alloc feature, but since we're depending on alloc anyways, that's not an issue. Thoughts?

If we do not use the new_box_zeroed, then yes, we'd need to update the ratchet for this, thanks for confirming.

@lschuermann

Leon Schuermann (lschuermann) commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Agreed, new_box_zeroed seems strictly better. Enabling alloc on zerocopy sounds like the right call and could enable a bunch more cleanups. In that case, it's probably best to get #817 over the finish line first and do the cleanup inline on top of that merged result.

@lschuermann

Copy link
Copy Markdown
Contributor Author

Jay Bosamiya (Microsoft) (@jaybosamiya-ms) Finally got around to this after #817 merged, sorry for the delay. Switched to zerocopy's function (which does force us to handle an alloc error that appears to be distinct from the other errors in that function's return type, so I added one).

@lschuermann

This comment was marked as off-topic.

@lschuermann Leon Schuermann (lschuermann) changed the title litebox_{platform_lvbs,shim_optee}: simplify box_new_zeroed litebox_common_linux: switch to zerocopy's FromZeros::new_box_zeroed Aug 11, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the cleanup Leon! I'll clean up the PR description before merging, since the merge queue uses it as the commit message

@jaybosamiya-ms Jay Bosamiya (Microsoft) (jaybosamiya-ms) changed the title litebox_common_linux: switch to zerocopy's FromZeros::new_box_zeroed Simplify via zerocopy::FromZeros::new_box_zeroed Aug 14, 2026
Merged via the queue into microsoft:main with commit 9e197f0 Aug 14, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants