-
Notifications
You must be signed in to change notification settings - Fork 18
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
Refactors regmgr_call and privileges #663
Conversation
src/kernel/src/fs/ioctl.rs
Outdated
pub fn try_from_raw_parts(cmd: u64, arg: *mut u8) -> Result<Self, SysErr> { | ||
/// # Safety | ||
/// `arg` has to be a pointer to the correct value | ||
pub unsafe fn try_from_raw_parts(cmd: u64, arg: SysArg) -> Result<Self, SysErr> { |
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.
This is even dangerous than the pointer because it hide the fact that the returned value have a lifetime bind to some pointer.
I guess we should required every PRs that use unsafe to be reviewed by me (or someone else who can catch this kind of bug) so we don't have a dangerous bug get merged. Here is an example of what going to happen if we violate the Rust assumption due to unsafe: #48
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 tried something, take a look
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.
Better to use something like this: https://doc.rust-lang.org/std/ffi/struct.CStr.html#method.from_ptr
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.
It's that simple? :D
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.
Wait a minute. To be completely honest, sometimes I don't fully understand lifetimes. The CStr struct isn't lifetimed (which is why from_ptr has a lifetime parameter and returns a lifetimed reference), but our IoCmd and RegMgrCommand are. Doesn't that make any difference?
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.
The point is try_from_raw_parts
need to have an explicit lifetime and document it how it bind to the pointer.
We are closing this PR due to no any activities in the last 30 days. Feel free to re-open it if you would like to continue working on this. |
No description provided.