Skip to content

Allow arbitrary closures in start_core#31

Merged
qwandor merged 7 commits intogoogle:mainfrom
m4tx:start_core_arg
Dec 4, 2025
Merged

Allow arbitrary closures in start_core#31
qwandor merged 7 commits intogoogle:mainfrom
m4tx:start_core_arg

Conversation

@m4tx
Copy link
Contributor

@m4tx m4tx commented Nov 14, 2025

This changes start_core so that it receives an arbitrary FnOnce object, rather than a fn(u64) pointer. This makes the API more ergonomic, and most importantly, allows passing more than just one u64 argument to the secondary core.

src/lib.rs Outdated
where
// TODO: change to FnOnce() -> ! when the never type is stabilized:
// https://github.com/rust-lang/rust/issues/35121
F: FnOnce() + Send + 'static,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: This constraint on F can go directly on the generic parameter declaration a few lines up, like the other parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured it makes sense to put this here given the constraint is a bit longer than others + there is quite a long comment, but I'm fine with both.

@m4tx m4tx requested a review from qwandor December 1, 2025 11:17
Copy link
Collaborator

@qwandor qwandor left a comment

Choose a reason for hiding this comment

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

I like this approach, very clever. Some minor comments below.

src/lib.rs Outdated
let rust_entry = ManuallyDrop::new(rust_entry);

let stack_bottom = stack.cast::<u8>();
let align_offfset = stack.align_offset(core::mem::align_of::<F>());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be stack_bottom.align_offset(...)? Otherwise it will give you an offset in units of Stack<N>, not bytes. Though given that the stack already has a 4 KiB alignment it is unlikely that this would ever be nonzero.

Copy link
Contributor Author

@m4tx m4tx Dec 4, 2025

Choose a reason for hiding this comment

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

Ah, fair! Sad that align_offset/align_of don't return some sort of generic newtype (Alignment<T>(usize)) to avoid such issues.

I'm wondering how this slipped through my testing, but I guess I was lucky enough to always get valid and mapped memory addresses accidentally.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably it was always returning 0 either way.

@m4tx m4tx requested a review from qwandor December 4, 2025 13:37
src/entry.rs Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is now the other way around. Either update this comment, or change the order of fields in StartCoreStack. I'd prefer the latter, because there's a small chance someone could be relying on the order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I've updated the struct then (and the comment a little bit to match the latest semantics).

@m4tx m4tx requested a review from qwandor December 4, 2025 17:12
@qwandor qwandor merged commit 30b06d7 into google:main Dec 4, 2025
3 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