James Molloy's Tutorial Known Bugs: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
m (Minor grammatical fixes/changes.)
Line 49:
== Problem: Interrupt handlers corrupt interrupted state ==
 
This article previously told you to know the ABI. If you do you will see a huge problem in the interrupt.s suggested by the tutorial: It breaks the ABI for structure passing! It creates an instance of the <tt>struct registers</tt> on the stack and then passes it by value to the <tt>isr_handler</tt> function and then assumes the structure is intact afterwards. However, the function parameters on the stack belongs to the function and it is allowed to trash these values as it sees fit (if you need to know whether the compiler actually does this, you are thinking the wrong way, but it actually does). The solution is either to abide by the ABI and create a second copy of the structure that you pass to the function and then you restore the state using the original copy; or you can simply pass a pointer to the structure to <tt>isr_handler</tt> and let the function corrupt the pointer, but not the actual structure.
There are two ways around this. The most practical method is to pass the structure as a pointer instead, which allows you to explicitly edit the register state when needed - very useful for system calls, without having the compiler randomly doing it for you. The compiler can still edit the pointer on the stack when it's not specifically needed. The second option is to make another copy the structure and pass that.
 
== Problem: struct registers::esp is useless ==
1,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu