System calls

  • https://en.wikipedia.org/wiki/System_call
  • Programmatic way in which a computer program requests a service from the OS on which it is executed
  • Acts as the interface between user space (where applications run) and kernel space (where the OS has full hardware access)
  • It temporarily elevates privilege from user mode to kernel mode
  • Number of System calls depends on:
    • Kernel Version (OS version)
    • Hardware Architecture (x86, x86_64, ARM)
  • For Linux x86_64/AMD64, ~450 system calls defined
  • The CPU provides the mechanism for transitioning from user mode to a more privileged mode
  • The OS/kernel provides
    • syscall numbers
    • syscall table
    • syscall implementations
  • The syscall ABI/table can differ between CPU architectures

System Call Table

mov rax, 1      ; syscall number
                ; Linux: 1 = write
syscall         ; CPU enters kernel

Standard C Library

Windows and Unix System interfaces

Process ControlWindowsUnixComment
CreateProcessfork, execNot syscalls
ExitProcessexit
WaitForSingleObjectwait, waitpid
WaitForMultipleObjects
kill
File Management
CreateFileopen
ReadFileread
WriteFilewrite
CloseHandleclose
Communication
CreatePipepipeNot syscalls
CreateFileMappingshm_openNot syscalls
MapViewOfFilemmap
CreateNamedPipemkfifoWindows is more richer compared to Unix
socket (Winsock)socket
Protection
SetFileSecuritychmodNot equivalent
InitializeSecurityDescriptorumaskNot equivalent
SetSecurityDescriptorGroupchownNot equivalent
Device Manipulation
SetConsoleModeioctl
ReadConsoleread
WriteConsolewrite

Event I/O Multiplexing

  • Libraries:
    • libevent
    • libuv
  • Linux
    • select(), poll() — I/O multiplexing
    • epoll() — scalable I/O multiplexing
    • io_uring() — asynchronous I/O
  • macOS
    • select(), poll() — I/O multiplexing
    • kqueue() — scalable event notification
  • Windows
    • IOCP (I/O Completion Ports) APIs — asynchronous I/O
    • Not syscalls

strace

  • used in Linux
  • It can be used to print system calls getting called internally
strace ls -al