-
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 set_general_handler macro #285
Conversation
I'm not sure why ci is failing as I can't reproduce the error (running in a windows vm). I think I managed to track down where the error is reported though: |
If you change the generic handler function to be |
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 a cool idea, I'm wondering if we can make the macros less complex.
src/structures/idt.rs
Outdated
($idt:expr, $handler:ident, $range:expr) => {{ | ||
fn set_general_handler( | ||
idt: &mut $crate::structures::idt::InterruptDescriptorTable, | ||
range: impl core::ops::RangeBounds<usize>, |
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.
Why not a range of u8
? This removes the concerns about out of bounds indexing.
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.
Currently InterruptDescriptorTable
only uses usize
for indexing operations and doesn't allow indexing with u8
, so I tried to mirror that api. I agree that using u8
would make more sense. Perhaps we should also implement Index<u8>
and IndexMut<u8>
for InterruptDescriptorTable
in a seperate pr.
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 with implementing both Index<u8>
and Index<usize>
might be that type annotations are required in more cases. For example, idt[20]
leads to the non-helpful error message "idt::InterruptDescriptorTable
cannot be indexed by i32
" because integer literals default to i32
in these cases.
However, I'm happy to change the Index
impl from usize
to u8
in the next breaking release. We should do this separately though, since this PR is a non-breaking change otherwise. We can of course already use u8
for the macro if we want.
/// use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; | ||
/// | ||
/// let mut idt = InterruptDescriptorTable::new(); | ||
/// fn my_general_handler( |
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.
If we are going to impose such a constraint, we should define the relevant function pointer type, and have the macro check that the function passed is actually of the correct type.
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 agree, I'll add that next
c0efffd
to
8252697
Compare
No, it's still failing with the same error |
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.
Sorry for the long delay since the last review iteration. This adds quite a bit of macro trickery, which makes it less readable than #168, but keeping the proc macro dependencies out is worth it in my opinion. The only concern I had are the error messages, but they don't seem much worse than the proc macro errors.
Was https://github.com/rust-osdev/x86_64/pull/285/files#r677279319 resolved? It doesn't seem to point to the right part of the source code anymore (or I don't understand what it is about).
From my side this is ready to be merged. Thanks a lot for your work!
d654ade
to
d41756a
Compare
I finally figured out how to do a proper rebase from git rebase --onto upstream/master upstream/next Let's hope that in the future I will know ahead of time whether something is breaking the api and never have to use this git command again. |
8695b39 makes the errors pretty well behaved. For example adding an invalid parameter to a general handlers only results in this single error message:
I completely forgot about that thanks for reminding me! It's now fixed. |
This time the compiler on windows just straight up segfaulted: https://github.com/rust-osdev/x86_64/runs/4130900835?check_suite_focus=true#step:16:23 |
Oh wow, sounds like a bug in rustc. I'll try to look into it. |
Ok, I think this is a bug in the Since the |
Thanks again for all your work on this! |
This pr adds the
set_general_handler!
macro to set a general handler in an idt using only macro_rules. It's an alternative to #168 and all of the tests are taken from it.As already mentioned in #167 (comment) there are no loops in macro_rules macros, so I used recursion instead:
https://github.com/Freax13/x86_64/blob/8252697d6ef5b567ff6a8110656f9a50e00df051/src/structures/idt.rs#L936-L956
I believe this to be a relatively short and concise solution. The only major drawback with this approach is that we can't do the range checks a compile time, so the macro always has to expand to setting all 256 interrupts even if some of those will be skipped at runtime. The upside of this approach is that the range doesn't necessarily need to be known at compile time (
set_general_handler!
takes$range
as an expression).Closes #167