Skip to content

Lecture No. 03

Dated: 24-04-2025

Memory Protection

Process Address Space

The area of memory which a process is allowed to access is called process address space.
A process must not be able to access memory outside of this space otherwise it can corrupt memory of other processes and even operating system.1

There are 2 registers used to provide memory protection.

Base Register

It holds the smallest legal physical memory address for a process.

Limit Register

It contains the size of the process.

cs604_e_3_1.svg

Hardware address protection with base and limit registers

cs604_e_3_2.svg

\(\text{address} \in [64, 64 + 128]\)

CPU Protection

We use a timer which interrupts the CPU to make sure that the user doesn't get stuck in an infinite loop and control remains in operating system1's hands.
The timer period can be fixed or variable.
A variable timer can be made by using a fixed rate clock and a counter.
The operating system1 sets the counter to some positive number \(N\) called the time slice which decrements over time with each clock impulse, using the clock interrupt service routine.
After the counter reaches \(0\), a timer interrupt is generated, operating system1 is invoked and control is transferred back to the CPU while it performs house keeping tasks.

Load-Timer is a privileged instruction.

OS1 Components

Process Management

A process can be though of a program in execution.

It needs certain resources to perform its task such as

  • CPU time
  • Memory
  • Files
  • I/O devices

The operating system1 is responsible for

  • Creating and terminating both user and system processes
  • Suspending and resuming processes
  • Providing mechanisms for
    • process synchronization
    • process communication
    • deadlock handling

Main Memory Management

Main memory is an array (a repository) of bytes, each with their own address which hold quickly accessible data by CPU and I/O devices.
It contains the code, data, stack and other parts of a process.
The CPU reads instruction during its machine cycle

  • Fetch
  • Decode
  • Execute

The operating system1 is responsible for following activities in connection with memory management.

  • Keeping track of free memory space
  • Keeping track of which parts of memory are currently being used and by whom
  • Deciding which processes are to be loaded into memory when memory space becomes available
  • Deciding how much memory is to be allocated to a process
  • Allocating and deallocating memory space as needed
  • Ensuring that a process is not overwritten on top of another

Secondary Storage Management

The programs alongside with the data they process, have to be loaded into the main memory or primary storage.
The computer system must provide a secondary storage for source and destination of programs and their data as the main memory is temporary.

The operating system1 does the following in this context

  • Free space management
  • Storage allocation and deallocation
  • Disk scheduling

I/O System Management

The I/O system consists of

  • A memory management component that includes
    • buffering
    • caching
    • spooling
  • A general device driver interface
  • Drivers for specific hardware devices

File Management

Computers can store information on several types of physical media, such as

  • Magnetic tape
  • Magnetic disk
  • Optical disk

The operating system1 maps these files onto the physical media and accesses these media via the storage devices.

The OS1 is responsible for the following activities with respect to file management

  • Creating and deleting files
  • Creating and deleting directories
  • Supporting primitives (operations) for manipulating files and directories
  • Mapping files onto the secondary storage
  • Backing up files on stable (nonvolatile) storage media

Protection System

There can be multiple users and processes running at the same time and the resources must be protected from each other's activities to prevent loss.

Networking

A distributed system is a collection of processors that do not share memory, peripheral devices or a clock.
Instead each processor has its own local memory and clock and the processors communicate with each other through various communication lines such as high speed buses or networks.

A distributed system collects physically separate and possibly heterogeneous systems, into a single coherent system providing the user with access to the various resources that system maintains.

Command line Interpreter (shells)

It is an interface between the users and the operating system.1
Some operating systems1 provide the interpreter in the kernel.
Other operating systems like Linux, Unix and DOS treat it like a special program.
It is also known as shell sometimes.
There are some examples

  • Bourne shell (sh)
  • C shell (csh)
  • Bourne Again shell (bash)
  • TC shell (tcsh)
  • Korn shell (ksh)

Operating System Services

Program Execution

The system must be able to do the following in regards to programs

  • Load
  • Execute
  • Terminate

I/O Operations

A running program may require a file or an I/O device.
For efficiency and protective reasons, users usually cannot directly access the I/O devices and need the middle man, that is operating system.1

File System Manipulation

Programs should be able to do the following operations on files.

  • Create
  • Modify
  • Delete

Communications

There can be communication between processes through shared memory or message passing.

Error Detection

Errors can occur in any part of the system and operating system1 should be able to know where the error has occurred and how to respond to them.


In order to assist the efficient operation of the system itself, the system provides the following functions

Resource Allocation

When multiple users and jobs are running on the system, resources must be allocated to each of them.

Accounting

We can keep track of which user accesses certain resources to later generate statistics.

Protection

When multiple users and processes are executing, the resources must be protected from corruption by each other.

Entry point into Kernel

There are 4 events that cause execution of a piece of code in the kernel.
These events are

  • Interrupt
  • Trap
  • System call
  • Signal

System Calls

These provide an interface between the process and the operating system.1 These calls are generally available as assembly language instructions.
The interface to system calls is the entry point of kernel code which is not usually and easily provided to the user for security reasons.
These are categorized into following groups

  • Process Control
  • File Management
  • Device Management
  • Information maintenance
  • Communications

Semantics of System Call Execution

Following sequence of events take place when a user invokes a system call.

  • The user process makes a call to a library function.
  • The library routine puts the appropriate parameters on a well known place such as registers or on the stack. These parameters include arguments for the system call, return address and call number. There are 3 general methods used to pass parameters between a running program and the operating system.
    • Pass parameters in registers
    • Store the parameters in a table which is stored on the main memory and the table address is passed as a parameter in a register.
    • Push the parameters onto the stack by the program and pop off the stack by operating system.1
  • A trap instruction is executed to change mode from user to kernel and give control to operating system.1
  • The operating system1 then determines which system call is to be carried out by examining one of the parameters (the call number) passed to it by library routine.
  • The kernel uses call number to index a kernel table (the dispatch table) which contains pointers to service routines for all system calls.
  • The service routine is executed and control given back to user program via return from trap instruction the instruction also changes mode from system to user.
  • The library function executes the instruction following trap interprets the return values from the kernel and returns to the user process.

cs604_i_3_1.png

Pictorial view of the steps needed for execution of a system call

Operating Systems Structures

cs604_i_3_2.png

Logical structure of DOS

cs604_i_3_3.png

Logical structure of UNIX

References