-
Notifications
You must be signed in to change notification settings - Fork 133
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
Add User Mode registers #119
Conversation
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.
Thanks a lot for the pull request! I left a few comments, but otherwise this looks good to me. Thanks especially for adding extensive documentation for everything!
src/registers/model_specific.rs
Outdated
SegmentSelector((raw.0 + 16 - 3).try_into().unwrap()), | ||
SegmentSelector((raw.0 + 8 - 3).try_into().unwrap()), |
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.
Could you clarify why you're doing - 3
here?
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 values in the registers are or'ed with 0b11 for sysret registers regardless of what the user specified. We are subtracting that back so that the user can directly match with their gdt's user mode entry rather
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 problem I see is that the user might also pass a segment selector with the requested privilege bits already set to 0b11
. In this case, it would be very strange to get a selector with requested privilege level 0 back, i.e. not the same that was written.
src/registers/model_specific.rs
Outdated
return Err("Syscall CS and SS is not offset by 8."); | ||
} | ||
|
||
Self::write_raw(((ss_sysret.0 - 8) | 0b11).into(), cs_syscall.0.into()); |
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'm not sure if automatically setting the RPL to 0b11
is the right solution. The alternative would be to require the caller to properly set these bits. What do you think is the better solution?
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 amd64 documentation says it is required but will not be tested. That is why i implicitly left it like this. This also provides direct one to one mapping to the user segment functions from gdt. Also the user can use write_raw to test it otherwise.
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 also provides direct one to one mapping to the user segment functions from gdt.
The user segment functions only return a GDT descriptor, not a segment selector. You mean the add_entry
function? If yes, there is currently an open issue about whether we should hardcode the requested privilege level in that function: #120
@phil-opp, updated as per comments |
Yeah, I think we should fix #120 and then assert for the bits, if set/not set at the corresponding places. Or maybe even better and idiomatic, have different SegmentSelector types according to the privilege bits |
Another option is to remove the read altogether and just go with read raw for now. What do you think @phil-opp? |
While we could merge this with only
What do you think about this, @vinaychandra? |
Makes sense, I updated the PR accordingly |
Thanks a lot! |
Published together with #118 as version 0.9.0. |
No description provided.