Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Software interrupts VS System calls

I had a question I don't know if it makes completely sense: If there's an interrupt function in a Interrupt vector, where each address slot is a pointer to some function that handles the interrupt (kind of a service, and runs in kernel mode), then my question is:

Would make a difference making a software interrupt instead of using a System call (aka function)? Let's put an example: I can destroy a process in 2 ways in Windows:

  1. I just call "ExitProcess"
  2. I just use the interrupt "int80h" in assembly (well, at least in Linux. Is it possible in windows?)

Both would work and give the same result. The only different I think is that an interrupt stops the CPU, while the system call, since it is not an interrupt, it does not halt the CPU from doing other things (this allows multithreading and not to stop for something does not really needs halting the whole CPU).

Want I really mean is that all functions in WIN32API (or any other OS) can be implemented as interrupts instead and would make no difference. Then that that would render WIN32API an unncessary layer. Don't you think? Then, what is the difference between software interrupts and system calls? You just need to call the function in the WIN32API to request the service, and with interrupts, you just need to pass the parameters (be it via stack or register) and call the specified interrupt identified by a number. The only reason I can think of is that DLLs (instances of these) are created per process and you use only the functions you need.

This is not possible with interrupts and all processes would share the same data, which is not always what one desires.

PD: This is an extra question which is out of topic but is a little one: Where could I see a reference/list of all the interrupts I can call in an OS? I can't see any documentation anywhere.

like image 588
Hashirama Senju Avatar asked Aug 14 '14 01:08

Hashirama Senju


People also ask

What is the difference between system call and interrupt?

Difference Between System Call and Interrupt 1 Definition. A system call is a programmatic way in which a computer program requests a service from the kernel of the operating system it is executing on while an interrupt ... 2 Usage. ... 3 Conclusion. ...

What is a software interrupt?

Moreover, a software interrupt is caused by an executing program. It also helps to communicate with the kernel to invoke system calls. When an interrupt occurs, the CPU pauses the currently executing program and executes the corresponding Interrupt Service Routine (ISR).

What is the difference between subroutine call and interruption?

What is the difference between subroutine call and interruption.? Subroutine is a portion of code within a larger program, which performs a specific task and is relatively independent of the remaining code. Interrupt Service Routines (ISRs) are to handle hardware interrupts.

What exactly is a system call?

A system call basically just means a service provided by the OS is invoked. The actual mechanism may involve an interrupt, a call gate or other specialized instructions (syscall, sysenter, swi, trap) depending on architecture and OS. The winapi hides this mechanism, it's an implementation detail you don't have to worry about.


1 Answers

A system call basically just means a service provided by the OS is invoked. The actual mechanism may involve an interrupt, a call gate or other specialized instructions (syscall, sysenter, swi, trap) depending on architecture and OS.

The winapi hides this mechanism, it's an implementation detail you don't have to worry about. It also might be undocumented and subject to change, while the public API is supposed to be stable.

In 32 bit x86 linux, using interrupt 0x80 to perform system calls has been obsolete since more than a decade, for performance reasons. In 32 bit mode the kernel itself provides code that performs the system call using the mechanism the kernel thinks best. This code gets mapped into every process (read about the vdso here). In x86-64 linux, the specialized syscall instruction is used.

Also, there are OS functions that don't need to switch to kernel mode (which is a costly operation). An API layer can also hide this difference, and provide you with the most efficient way automatically.

like image 199
Jester Avatar answered Sep 28 '22 04:09

Jester