<aside>
🧠
Last time Prof. Eyolfson proved to us that virtual memory indeed exists!
</aside>
Summary
Kernel interfaces operate between CPU mode boundaries- in user mode, applications have restricted access that they cannot directly interact with hardware or critical system resources
- The kernel is part of the OS that interacts with hardware (it runs in kernel mode)
- System calls are the interface between user and kernel mode
- Every program must use this interface
- File format and instructions to define a simple “Hello world” (in 168 bytes)
- Difference between API and ABI
- APIs define how you can use a system, while ABIs ensure binary compatibility across different environments
- You can have multiple programs compiled with different compilers run on the same OS as long as they adhere to the same ABI
- How to explore system calls
- Using tools like
strace
in Linux to trace system calls made- shows which system calls are invoked when a program runs, and with what arguments
- Different kernel architectures shift how much code runs in kernel mode
- Linux is a monolithic kernel, entire OS runs in kernel mode
- Only essential services run in a microkernel
- Windows and macOS use hybrid kernels
System Calls
<aside>
☎️
System calls are functions provided by the kernel that allow user programs to make requests to the OS (i.e., file operations, memory allocation, process control, or communication with hardware).
We can represent them as regular C functions
</aside>
- The kernel interface ensures that only trusted system operations (usually via system calls) are allowed to transition from user mode to kernel mode, where the kernel can perform sensitive operations like managing memory or interacting with devices
- User applications cannot directly access hardware or perform privileged actions, so they must rely on system calls to request these services
Another abstraction: file descriptors
IPC: inter-process communication is transferring data between two processes
File descriptor: a resource that users may either read bytes from or write bytes to
- Identified by an index stored in a process
- Could represent a file, or your terminal
Expected File Descriptors:
0
- standard input (read)
1
- standard output (write)
2
- standard error (write)
ssize_t write(int fd, const void, void *buf, size_t count);
- Writes bytes from a byte array to a file descriptor
fd
- file descriptor
buf
- address of the start of the byte array (buffer)
count
- how many bytes to write from the buffer
void exit_group(int_status);
- Exits the current process and sets an exit status code
status
: exit code 0-255