wlnirvana
wlnirvana

Reputation: 2047

Why the number of system calls is very limited?

I was playing with ioctl and this question occurred to me.

Background

  1. I was told that the primary motivation for system calls is that the number of interrupt handlers allowed is very limited. So many OSes implement the abstraction of system calls (a.k.a. traps), which occupies only one interrupt number (0x80 in case of Linux), but accept extra arguments to deliver different functionalities on demand.
  2. this thread suggests the the number of system calls is actually very limited too, so the same reasoning above is applied again to invent ioctl.

Hence my question. Why don't OSes just offer enough system calls and get rid of ioctl? (Or is it just merely to create a hierarchical structure to offer better scalability?)

Upvotes: 0

Views: 230

Answers (1)

Martin Drab
Martin Drab

Reputation: 697

My opinion about this is that system calls can be viewed as a set of services provided by the operating system kernel to user applications, whereas ioctl is just one of these services that allows you to send a custom command to specific device (or driver).

When developing a driver, you may write a handler for incomming ioctl requests. Managing the same thing by implementing your own system calls has several disadvantages:

  • your implementation is specific to your driver, other components probably will not use it,
  • adding new system calls is not that easy – on WIndows, it is practically impossible because of Patchguard (Kernel Patch Protection),
  • on Windows, the kernel may help you with "validation" of I/O buffers for an IOCTL request, you must do all the work by yourself when implementing your own system calls.

You can view ioctl as a generalization for read and write. Both input and output buffers can be provided, together with a control code defining the action requred from the target (usually a kernel driver).

Upvotes: 1

Related Questions