-
Notifications
You must be signed in to change notification settings - Fork 430
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
Pinned module #997
base: rust-next
Are you sure you want to change the base?
Pinned module #997
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o | ||
obj-$(CONFIG_SAMPLE_RUST_INPLACE) += rust_inplace.o | ||
obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o | ||
|
||
subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
//! Rust minimal in-place sample. | ||
|
||
use kernel::prelude::*; | ||
|
||
module! { | ||
type: RustInPlace, | ||
name: "rust_inplace", | ||
author: "Rust for Linux Contributors", | ||
description: "Rust minimal in-place sample", | ||
license: "GPL", | ||
} | ||
|
||
#[pin_data(PinnedDrop)] | ||
struct RustInPlace { | ||
numbers: Vec<i32>, | ||
} | ||
|
||
impl kernel::InPlaceModule for RustInPlace { | ||
type Init = impl PinInit<Self, Error>; | ||
fn init(_module: &'static ThisModule) -> Result<Self::Init> { | ||
pr_info!("Rust minimal sample (init)\n"); | ||
pr_info!("Am I built-in? {}\n", !cfg!(MODULE)); | ||
|
||
let mut numbers = Vec::new(); | ||
numbers.try_push(72)?; | ||
numbers.try_push(108)?; | ||
numbers.try_push(200)?; | ||
|
||
Ok(try_pin_init!(Self { numbers })) | ||
} | ||
} | ||
|
||
#[pinned_drop] | ||
impl PinnedDrop for RustInPlace { | ||
fn drop(self: Pin<&mut Self>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a few folks suggest that instead of using a drop implementation, that we should do have We decided against it back then, which I think was the right decision. But I think for the pinned/static case,the ergonomics of a method in the module to clean up (which takes a We should perhaps consider it. What do you all think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few problems with an explicit
We could change Why do you think that the ergonomics of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With pin-ini, we have to add These are all magic as far as I can tell with no easy way for someone who knows about regular There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point, however if you have an explicit I am not sure how we could improve the situation... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make it not callable from other places, we can have an extra argument of some type T whose constructor is unsafe. Note, however, that I'm not convinced yet that an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is how Another thing to consider with the |
||
pr_info!("My numbers are {:?}\n", self.numbers); | ||
pr_info!("Rust minimal inplace sample (exit)\n"); | ||
} | ||
} |
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 it would be beneficial to also put something in here that people can't put into non-in-place modules, e.g. a
Mutex
, of corusesync
would have to land first.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 believe the main motivation for this PR is indeed to be able to use a module-wide
Mutex
without having to use ctor tricks?