-
Notifications
You must be signed in to change notification settings - Fork 130
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
Feature: backup/restore registers #154
Conversation
This should make phil-opp/blog-os:post-13 a bit easier to write.
Compiler was throwing a fit upstream; see if this makes a difference
Was giving "malformed inline assembly" for Windows but not Linux (which I've got as a main host OS on my end) ― weird
This reverts commit b5db1d5.
Hopefully this solves the build issues
When I run |
Hopefully this gets us to pass the formatting checks
Let's see if this solves the formatting errors…
Merge all `unsafe` blocks into one per function ― there was just too much repetition there, and that repetition may be what was causing the format failures.
Thanks for the pull request! I'm not sure whether this approach works though. The problem is that the method code itself might overrwrite the register content before we backup it. |
That’s why each thread stack is protected by a mutex on most platforms — just take a look at Linux’s kthread.c for example: each stack is protected by, in that case, invoking As another reference, this is how Redox does it — in that case, by:
You could combine Step 1 with |
For the record, this is very similar to Nikos Filippakis’s approach. |
It has nothing to do with the stack. You're taking the current value of the CPU registers in the middle of a Rust function. The Rust function needs CPU registers itself, e.g. to store its variables, so it will probably back up some registers at the beginning of the function and then overwrite it with different content. So at the point when you look at the register values through inline assembly, their content might already have changed. The blog you linked takes a different approach for saving the registers:
While I think that this approach works, I don't think that adding such a function would be a good idea because it is very easy to get things wrong. The main limitation is that you can only safely call such a function from other naked functions because otherwise the outer function prologue would overwrite the registers contents again. This is the reason why the timer interrupt handler is a naked function too in the linked blog post. (While it seems that this work right now, it's using normal Rust code inside a naked function, which is neither supported nor recommended and can easily lead to undefined behavior.) |
There are other reasons why this code would not work:
Usually, Context switching is strongly dependent of what your kernel is doing. I am not sure it would ever be possible to devise a universal context-switch function that could be used by all the kernels using this crate. |
Closing, since the code does not work this way unfortunately. |
This should make blog-os:post-13 a bit easier to write.