Skip to content
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

Convenient no-panic API for just waiting on notifications #1715

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

cbiffle
Copy link
Collaborator

@cbiffle cbiffle commented Apr 3, 2024

This is an alternate API for accessing the common "receive only kernel
notifications" pattern. That specific use of the sys_recv syscall is
defined as not being able to fail. Different users have handled that in
different ways -- some panic, some ignore the result. The latter embeds
the assumption of that behavior in many different places in the
codebase, a pattern I'm trying to keep an eye on.

This change adds a new sys_recv_notification userlib function that
bundles up this common pattern. Because of its central placement in
userlib, it seems like a more appropriate place to encode the assumption
about the syscall not failing, and so I've done that, using
unreachable_unchecked to explain it to the compiler.

This removes a panic site from every notification-wait in programs that
were previously using unwrap or unwrap_lite.

@cbiffle cbiffle force-pushed the cbiffle/no-panic-notif-recv branch from f81ffbb to a96d644 Compare April 3, 2024 18:23
@cbiffle cbiffle requested a review from hawkw April 3, 2024 18:23
@cbiffle cbiffle force-pushed the cbiffle/no-panic-notif-recv branch from a96d644 to eca0f2a Compare April 3, 2024 18:35
These comments by 2020-me didn't super make sense to 2024-me, so I have
rewritten them to hopefully be a little more clear and reveal some
context that was previously implicit.
@cbiffle cbiffle force-pushed the cbiffle/no-panic-notif-recv branch from eca0f2a to 88b9f93 Compare April 3, 2024 18:38
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

This is lovely, I'm looking forward to using it!

Comment on lines +273 to +278
// We're not using the extract_new_generation function here because
// that has a failure code path for cases where the code is not a
// dead code. In this case, sys_recv is defined as being _only_
// capable of returning a dead code -- otherwise we have a serious
// kernel bug. So to avoid the introduction of a panic that can't
// trigger, we will do this manually:
Copy link
Member

Choose a reason for hiding this comment

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

This comment is great, thanks for adding it!

sys/userlib/src/lib.rs Outdated Show resolved Hide resolved
This is an alternate API for accessing the common "receive only kernel
notifications" pattern. That specific use of the sys_recv syscall is
defined as not being able to fail. Different users have handled that in
different ways -- some panic, some ignore the result. The latter embeds
the assumption of that behavior in many different places in the
codebase, a pattern I'm trying to keep an eye on.

This change adds a new sys_recv_notification userlib function that
bundles up this common pattern. Because of its central placement in
userlib, it seems like a more appropriate place to encode the assumption
about the syscall not failing, and so I've done that, using
unreachable_unchecked to explain it to the compiler.

This removes a panic site from every notification-wait in programs that
were previously using unwrap or unwrap_lite.
@cbiffle cbiffle force-pushed the cbiffle/no-panic-notif-recv branch from 88b9f93 to f734275 Compare April 3, 2024 18:47
@cbiffle cbiffle enabled auto-merge (rebase) April 3, 2024 18:49
@cbiffle cbiffle merged commit 588c7d5 into master Apr 3, 2024
103 checks passed
@cbiffle cbiffle deleted the cbiffle/no-panic-notif-recv branch April 3, 2024 19:55
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.

None yet

2 participants