Professional Documents
Culture Documents
System calls
• System calls are an operating system’s API
– The set of functions that the operating system exposes to processes
• If you want to the OS to do something, you tell it via a
Operating Systems system call
Week 2 Recitation: The system call • Examples
Windows Linux
NtOpenFile open
Paul Krzyzanowski NtReadFile read
Rutgers University NtCreateProcess fork
Spring 2015 NtGetCurrentProcessorNumber getpid
February 14, 2015 © 2014-2015 Paul Krzyzanowski 1 February 14, 2015 © 2014-2015 Paul Krzyzanowski 2
What are system calls used for? System calls are made via traps
• Anything to do with: • System calls request operating system services
– Accessing devices – Communicating with other processes • Operating system code executes with the processor running in kernel
– Accessing files – Stopping/starting processes (also known as supervisor or privileged) mode
– Requesting memory – Setting a timer
– Setting/changing access permissions – Privileged mode gives the CPU the rights to:
• Execute special instructions
• You need a system call to: (change interrupt masks, set hardware timers, halt the processor)
– Open a file • Access specific registers (e.g., private stack pointer)
– Get data from the network • Change the memory map
– Kill a process • Access regions of memory that have been restricted for kernel access only
• Access the processor’s I/O ports (if the architecture has them)
• You do not need a system call to:
– Replace data in a string • A trap takes has one parameter: index into an Interrupt Vector Table
– Create an object (instance of a class) – The table is in memory that only the kernel can access
– Call a function – All addresses in the table go to well-defined entry points in the OS
February 14, 2015 © 2014-2015 Paul Krzyzanowski 3 February 14, 2015 © 2014-2015 Paul Krzyzanowski 4
February 14, 2015 © 2014-2015 Paul Krzyzanowski 5 February 14, 2015 © 2014-2015 Paul Krzyzanowski 6
• Linux does a test to check which mechanisms exist before making a • System calls need to pass multiple parameters
system call: – E.g., read needs to identify the open file, starting byte, number of bytes
– Check if syscall exists (Intel architecture) – There are three ways to pass these parameters
– Check if sysenter exists (AMD architecture) 1. In the processor’s registers
– Otherwise use INT 80 (works on even the oldest processors) 2. On the stack
3. In some memory location whose address is passed to the kernel
February 14, 2015 © 2014-2015 Paul Krzyzanowski 7 February 14, 2015 © 2014-2015 Paul Krzyzanowski 8
February 14, 2015 © 2014-2015 Paul Krzyzanowski 9 February 14, 2015 © 2014-2015 Paul Krzyzanowski 10
Note: This is an example using Linux and an x86 architecture. x86-64 uses the 64-bit
version of the eax register: rax. Other processors will use totally different registers.
Other operating systems may use a different entry point.
February 14, 2015 © 2014-2015 Paul Krzyzanowski 11 February 14, 2015 © 2014-2015 Paul Krzyzanowski 12