Are the system calls the only way an Application/User program can request OS services for performing privileged operations?

261 Views Asked by At

I'm in a Linux environment even though I know this topic has a much broader scope

Let's say I'm writing a simple C program and I want to write "Hello" to the terminal. The obvious way is to use the C standard library printf which in turn uses the write system call (the wrapper function not the system call itself) which in turn calls the actual assembly syscall instruction (or int). The less obvious way is to use some inline assembly in my C source file or directly create an assembly file with the syscall instruction in it.

My questions

  1. It seems like at the end of the day, one way or the other we end up with the system call (instruction syscall or int). Is this the only way?

  2. Has the term Application the same meaning as User program has in the context of a modern PC?

  3. Is it correct to say that PowerPoint, Google Chrome, Visual Studio Code, Photoshop or a C program I write are all examples of Applications/User programs that need system calls to request OS services for performing privileged operations like writing a file?

1

There are 1 best solutions below

3
fuz On

On a conventional operating system, yes, almost all OS services are requested through system calls. However, there can be a number of exceptions:

  • On major page fault, the OS may retrieve the page your process was missing from background storage (swap space). This is a privileged operation your process cannot do on its own, but it's triggered through the page fault handler.
  • Some machine instructions might not be supported by the CPU or may only available to privileged code. For example, this affects the MRS instruction to read the CPU type and features on AArch64. When user software executes such an instruction, a trap occurs. An operating system (such as FreeBSD) may emulate the missing instruction or execute it in a privileged context and then continue execution.
  • Some operating systems support mailbox-style interfaces to user space where the user process can deposit instruction packages in a ring buffer with the kernel periodically checking for new work, executing the packages without having the user process explicitly trigger a system call.
  • Some systems support certain settings to be made through shared memory, like linux with it's vdso. I also dimly recall a UNIX where a process could manipulate its signal mask by writing the desired signal mask into a designated piece of memory. The OS would then read the signal mask from there when delivering a signal.

There are other examples as well, but almost all interaction with the operating system indeed happens through system calls.