-
Notifications
You must be signed in to change notification settings - Fork 13.5k
compiler: Allow extern "interrupt" fn() -> !
#143075
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
base: master
Are you sure you want to change the base?
compiler: Allow extern "interrupt" fn() -> !
#143075
Conversation
This PR modifies cc @jieyouxu |
Now that the rules get more complex, I think the error on the return type should probably move to type Unit = ();
#[cfg(any(x64, i686))]
extern "x86-interrupt" fn x86_ret_unit() -> Unit {
unsafe { hint::unreachable_unchecked() }
} gives
The error message is also incorrect now: the function can have a return type (so long as it's |
765309e
to
b5ab966
Compare
I mean if I really want to get it right it should probably be even deeper, so we can check the actual layout. |
I don't think I want to do that level of correctness before we decide we actually want these interrupt ABIs, though, and I, at least, am not sold on them. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Fair enough. Then the error message should at least be correct though right? (so, there can be a return type, just literally
The x86 one gets a surprising (to me) amount of use https://github.com/search?q=extern+%22x86-interrupt%22&type=code. But in theory those could now use naked functions and compile on stable. |
@andrewoffenden what. |
Yes, Phil Opp espoused using them, so they gained some popularity. But they should not be used by a real OS, because an OS cannot support any debugger APIs if it uses them. |
I think there are valid use-cases for the "x86-interrupt" ABI even in a "real OS". Sometimes you don't need to look at the registers of the interrupted thread, and in that case, using "x86-interrupt" is completely fine and can even result in better code than a hand-written interrupt handler. For example, I use it for handling timer interrupts that happen while the kernel is executing in ring 0. That said, there are, of course, also use cases where this absolutely will not work: If you're going to write an |
Apart from convenience, my main motivation for using the That being said, I also agree that the Thanks a lot for this PR by the way! I appreciate it that you try to avoid breakage, even though it's a nightly feature! |
(Not directly related to this PR, but to discussion about whether we want to keep the I think if we had support for LLVM's |
We do support PreserveMost already as I agree that we really do need that as a prerequisite to any alternatives. That way any assembly can be a minimal shim sufficient to do whatever operations are needed between the machine and the OS and then jump into the main handler, instead of saving everything in the assembly. |
While reviewing #142633 I overlooked a few details because I was kind of excited.
Fixes #143072