Why is it called a “trap” instruction

etymologyoperating systems

To execute a system call, a program must execute a special trap
instruction.

Why is it called a "trap" instruction? What is the etymology of this usage of the word "trap"?

Is it related to the usual English word trap? Is something is getting "trapped" as in "unable to escape"?

Best Answer

It's what we call kernel or system "trap", which triggers a kernel mode switch to execute the system call.

As to why that word was used, I haven't found definitive proof yet, so my current assumption is that it comes from either or both of these 2 options:

  • We used to say sometimes that the code "fell" into a different mode instead of "switching", which resembles the mental image of "falling into a trap".

  • A "trap" is meant to capture something, here a reaction to an interrupt, which can happen in case of a failure (which can have several levels of severity, including being "fatal").

Furthermore, and along the same lines of thinking, we usually think of a program's control flow as having a "normal" flow and having an "error" or "exceptional" flow for things that should not (or rarely) happen. And the point of the "trap" is to capture such events.

But I think the sentence you quote is strangely worded.

Related Topic