-2

I used to think of systemcalls as blackboxes, later I discovered that it sends an interrupt(0x80) to the kernel which calls the appropriate interrupt handler. However I'm still unable to understand what's really happening underneath the hood, what and how exactly does the interrupt handler work? Is the interrupt handler part of the kernel?

Trey
  • 474
  • 2
  • 9
  • 32
  • 2
    What was your research before asking this question? Have you tried to ask Google? I recall there being a bunch of really good articles outlining the details. – fuz Oct 23 '17 at 14:01
  • 1
    Different questions, but a duplicate IMO because the answer has an actual walk-through of Linux's `int 0x80` handling code for 64-bit kernels. (And comparison to the `syscall` handler for native 64-bit system calls). – Peter Cordes Oct 23 '17 at 21:45

1 Answers1

1

How would it be different than a function call? A function call has a set of rules. In this case the call contains a set of rules, inputs, outputs. Just how you invoke it is a little different. For good reason so you can cross a protection boundary. A software interrupt allows the logic to go from your application to kernel code, read the inputs, react, and return.

There is next to no magic here.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
old_timer
  • 69,149
  • 8
  • 89
  • 168
  • What I can't understand is how such functions are implemented. Most of the C functions will eventually turn into a systemcall, so how is the interrupt handler working if it depends on systemcalls? – Trey Oct 23 '17 at 14:09
  • 1
    the handler services the system calls. the c functions at the application layer cannot touch the resources directly in general they have to ask the kernel to do stuff. this is the mechanism. The kernel has a handler for these software interrupts and that handler is the system thus a system call. – old_timer Oct 23 '17 at 17:30
  • 1
    how they are implemented is that for a particular operating system you write inline or real assembly for these calls, it is part of the C or other library for this system. – old_timer Oct 23 '17 at 17:31
  • 1
    Linux, windows, macos, etc are going to have a different set of system calls and the C (or other) library for that system are customized for that system (assuming the system calls are not compatible, which is a safe assumption) – old_timer Oct 23 '17 at 17:32
  • 1
    Terminology: "superuser" is a privileged *user*, e.g. `root`. A system call passes your args to *kernel* code. Editing to correct. – Peter Cordes Oct 23 '17 at 21:47