-
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2fd2dd1
Refactors regmgr_call
42d8f06
rename type
08b1c44
refactor
9d6bed8
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath f9568c7
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath 367a85f
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath 58759ea
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath 78f573c
refactor
951a4e8
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath 4f0abac
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath 35ec51b
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath a8739dc
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath 82803dc
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath 2a085e1
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath 2a0c859
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath 6d0a355
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath e09c939
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath ebc4001
Merge branch 'main' into regmgr-refactor
SuchAFuriousDeath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use super::RegError; | ||
use crate::syscalls::SysArg; | ||
use std::convert::Into; | ||
|
||
#[repr(u32)] | ||
pub(super) enum RegMgrCommand<'a> { | ||
SetInt(&'a SetIntArg) = 0x18, | ||
Unk1(&'a Unk1Arg) = 0x19, | ||
} | ||
impl<'a> RegMgrCommand<'a> { | ||
/// # Safety | ||
/// `arg` has to be a pointer to the correct value | ||
pub unsafe fn try_from_raw_parts(cmd: u32, arg: SysArg) -> Result<Self, RegError> { | ||
match cmd { | ||
0x18 => Ok(RegMgrCommand::SetInt(unsafe { | ||
&*(Into::<*mut _>::into(arg)) | ||
})), | ||
0x19 => Ok(RegMgrCommand::Unk1(unsafe { | ||
&*(Into::<*mut _>::into(arg)) | ||
})), | ||
0x27 | 0x40.. => Err(RegError::V800d0219), | ||
v => todo!("RegMgrCommand({v})"), | ||
} | ||
} | ||
} | ||
|
||
#[repr(C)] | ||
pub(super) struct SetIntArg { | ||
pub v1: u64, | ||
pub v2: u32, | ||
pub value: i32, | ||
} | ||
|
||
#[repr(C)] | ||
pub(super) struct Unk1Arg { | ||
pub v1: u64, | ||
pub v2: u32, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.