0% found this document useful (0 votes)
8 views10 pages

Operating System 4

The document discusses system calls in operating systems, detailing their mechanism, implementation, and differences from function calls. It outlines the steps involved in making a system call, using the read call as an example, and highlights the types of system calls related to process control, file management, device management, information maintenance, communication, and protection. Additionally, it emphasizes the cost and complexity associated with system calls compared to standard library calls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Operating System 4

The document discusses system calls in operating systems, detailing their mechanism, implementation, and differences from function calls. It outlines the steps involved in making a system call, using the read call as an example, and highlights the types of system calls related to process control, file management, device management, information maintenance, communication, and protection. Additionally, it emphasizes the cost and complexity associated with system calls compared to standard library calls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

18-01-2025

Lecture 4: System Calls


Operating Systems
Dr. Anjali
Assistant Professor

System Call Mechanism

Assumptions
• User code can be arbitrary
• User code cannot modify kernel Memory
Design Issues
• User makes a system call with parameters
• The call mechanism switches code to kernel mode
• Execute system call
• Return with results

1
18-01-2025

System Call Implementation

System Calls versus Function Calls?

2
18-01-2025

System Calls versus Function Calls?

Function Call

Process

fnCall()

Caller and callee are in the same


Process
- Same user
- Same “domain of trust”

System Calls versus Function Calls?

Function Call System Call

Process Process

fnCall() sysCall()

OS

Caller and callee are in the same


Process
- Same user - OS is trusted; user is not.
- Same “domain of trust” - OS has super-privileges; user does not
- Must take measures to prevent abuse
6

3
18-01-2025

System Calls
 System Calls
 A request to the operating system to perform some activity

 System calls are expensive


 The system needs to perform many things before executing a
system call
 Store sys_call arguments in registers and switch to kernel
mode
 The OS code takes control of the CPU, privileges are updated,
and value of all registers is saved
 The OS examines the call parameters and type of sys_call

 The OS performs the requested function


 The OS restores value of all registers
7

 The OS returns control of the CPU to the caller

Privileged Instruction Examples

• Memory address mapping


• Flush or invalidate data cache
• Invalidate TLB entries
• Load and read system registers
• Change processor modes from kernel to user
• Change the voltage and frequency of processor
• Halt a processor
• Reset a processor
• Perform I/O operations

4
18-01-2025

Steps for Making a System Call (Example: read call)

Steps for Making a System Call


(Example: read call)

 A system call is implemented by a ``software interrupt'' that transfers control to kernel


code; in Linux/i386 this is ``interrupt 0x80''. The specific system call being invoked is
stored in the EAX register, and its arguments are held in the other processor registers.
In our example, the number associated to read is NR_read, defined in <asm/
unistd.h>.

 After the switch to kernel mode, the processor must save all of its registers and
dispatch execution to the proper kernel function, after checking whether EAX is out of
range. The system call we are looking at is implemented in the sys_read function. The
read finally performs the data transfer and all the previous steps are unwound up to
the calling user function.

10

5
18-01-2025

Steps for Making a System Call


(Example: read call)

 The cost of using a system call

 Each arrow in the figure represents a jump in CPU


instruction flow, and each jump may require flushing the
prefetch queue and possibly a ``cache miss'' event.

 Transitions between user and kernel space are especially


important, as they are the most expensive in processing
time and prefetch behavior.

11

Examples of System Calls


 Examples
 getuid() //get the user ID
 fork() //create a child process
 execve() //executing a program
 Don’t mix system calls with standard library
calls See man syscalls

 Differences?
 Is printf() a system call?
 Is rand() a system call?

12

6
18-01-2025

How do we know what is and what isn’t a


system call?

Library calls often


invoke system calls!

malloc(3) calls sbrk(2)

 2: System Call
 3: Library Call

13

Types of System Calls

14

7
18-01-2025

Types of System Calls

• Process control
• create process, terminate process
• end, abort
• load, execute
• get process attributes, set process attributes
• wait for time
• wait event, signal event
• allocate and free memory
• Dump memory if error
• Debugger for determining bugs, single step execution
• Locks for managing access to shared data between processes

15

Types of System Calls

• File management
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes
• Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices

16

8
18-01-2025

Types of System Calls (Cont.)

• Information maintenance
• get time or date, set time or date
• get system data, set system data
• get and set process, file, or device attributes
• Communications
• create, delete communication connection
• send, receive messages if message passing model to host name or process name
• From client to server
• Shared-memory model create and gain access to memory regions
• transfer status information
• attach and detach remote devices

17

Types of System Calls (Cont.)

• Protection
• Control access to resources
• Get and set permissions
• Allow and deny user access

18

9
18-01-2025

Examples of Windows and Unix System Calls

19

20

10

You might also like