System Calls
Compilation Process
When a userspace app wants to talk to the kernel, it must use the system call process. A simple fork or open call goes through C methods.
Native code is code compiled for a specific OS and CPU instruction set. It's mostly machine language built from the CPU's instruction set.

Linux is written in C. The kernel developers also ship userspace C libraries called glibc to talk to the kernel.
When you write C programs, other apps can use these libraries to make system calls.
Think of the methods in these libraries as wrappers over the real native functions.
Execution Process
To run a system call, the CPU registers are set with the ID of the system call handler. The kernel interrupt handler then uses this ID.

System Call Flow
The most important part of system calls is the context switching back from kernel space to userspace.
The kernel runs the SYSRET instruction to switch back to userspace. The CPU then changes the ring mode. It also updates the IP, the stack pointer, and the page tables to point to the userspace process.
