Note that there are some explanatory texts on larger screens.

plurals
  1. POOS development: How to avoid an infinite loop after an exception routine
    primarykey
    data
    text
    <p>For some months I've been working on a "home-made" operating system. Currently, it boots and goes into 32-bit protected mode. I've loaded the interrupt table, but haven't set up the pagination (yet).</p> <p>Now while writing my exception routines I've noticed that when an instruction throws an exception, the exception routine is executed, but then the CPU jumps back to the instruction which threw the exception! This does not apply to every exception (for example, a div by zero exception will jump back to the instruction AFTER the division instruction), but let's consider the following general protection exception:</p> <pre><code>MOV EAX, 0x8 MOV CS, EAX </code></pre> <p>My routine is simple: it calls a function that displays a red error message.</p> <p>The result: MOV CS, EAX fails -> My error message is displayed -> CPU jumps back to MOV CS -> infinite loop spamming the error message.</p> <p>I've talked about this issue with a teacher in operating systems and unix security. He told me he knows Linux has a way around it, but he doesn't know which one.</p> <p>The naive solution would be to parse the throwing instruction from within the routine, in order to get the length of that instruction. That solution is pretty complex, and I feel a bit uncomfortable adding a call to a relatively heavy function in every affected exception routine...</p> <p>Therefore, I was wondering if the is another way around the problem. Maybe there's a "magic" register that contains a bit that can change this behaviour?</p> <p>--</p> <p>Thank you very much in advance for any suggestion/information.</p> <p>--</p> <p><strong>EDIT</strong>: It seems many people wonder why I want to skip over the problematic instruction and resume normal execution.</p> <p>I have two reasons for this:</p> <ol> <li><p>First of all, killing a process would be a possible solution, but not a clean one. That's not how it's done in Linux, for example, where (AFAIK) the kernel sends a signal (I think SIGSEGV) but does not immediately break execution. It makes sense, since the application can block or ignore the signal and resume its own execution. It's a very elegant way to tell the application it did something wrong IMO.</p></li> <li><p>Another reason: what if the kernel itself performs an illegal operation? Could be due to a bug, but could also be due to a kernel extension. As I've stated in a comment: what should I do in that case? Shall I just kill the kernel and display a nice blue screen with a smiley?</p></li> </ol> <p>That's why I would like to be able to jump over the instruction. "Guessing" the instruction size is obviously not an option, and parsing the instruction seems fairly complex (not that I mind implementing such a routine, but I need to be sure there is no better way).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload