2

What is the difference between OS privilege levels and privilege levels of the underlying hardware? Do all system calls cause a trap to the kernel? Why do system calls cause a trap? Is it because of privileged instructions such as IN in their assembly code?

user541686
  • 205,094
  • 128
  • 528
  • 886
user1284064
  • 175
  • 2
  • 9

1 Answers1

3

To answer your questions directly:

What is the difference between OS privilege levels and privilege levels of the underlying hardware?

The privileges that must be enforced on a code level (ie privileged instructions) must be supported in hardware. Many OS security levels (ie permissions to access a specific hardware device) does not require hardware support for authenticating that very specific function, but it does at least require that there be hardware support to block code from accessing the device. So, in short, the ability of the OS to implement privilege levels depends on the underlying hardware, but the two need not be the same.

Do all system calls cause a trap to the kernel? Why do system calls cause a trap? Is it because of privileged instructions such as IN in their assembly code?

That's essentially correct. Trapping is the natural mechanism by which unprivileged code can transition to a privileged level. If, for example, a user program needs to access some piece of hardware, then IN and OUT are privileged so it must 'trap' to the Kernel and then the kernel will perform the required operations and return.

Dougvj
  • 6,409
  • 2
  • 23
  • 18
  • So it seems that system calls are functions the body of which contains call to privileged instruction. Am I right? – user1284064 Aug 31 '12 at 20:18
  • @user1284064 Pretty much, system calls are actuallly implemented through software interrupts, so for example, the client program to "call" the functions with privileged instructions uses the INT instruction which tells the kernel what to do. – Dougvj Aug 31 '12 at 21:22