The Wayback Machine - https://web.archive.org/web/20240910053748/https://www.geeksforgeeks.org/memory-protection-in-operating-systems/
Open In App

Memory Protection in Operating Systems

Last Updated : 18 Jan, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we will be discussing memory protection in operating systems. As we know that different operating systems use different forms of memory protection or separation which consists of Plan9 and Inferno, Microsoft Windows, etc. 

In Memory protection, we have to protect the operating system from user processes and which can be done by using a relocation register with a limit register. Here, the relocation register has the value of the smallest physical address whereas the limit register has the range of the logical addresses. These two registers have some conditions like each logical address must be less than the limit register. The memory management unit is used to translate the logical address with the value in the relocation register dynamically after which the translated (or mapped) address is then sent to memory.

Support for relocation and limit registers in process

Support for relocation and limit registers in process

In the above diagram, when the scheduler selects a process for the execution process, the dispatcher, on the other hand, is responsible for loading the relocation and limit registers with the correct values as part of the context switch as every address generated by the CPU is checked against these 2 registers, and we may protect the operating system, programs, and the data of the users from being altered by this running process.

Need of Memory protection:

Memory protection prevents a process from accessing unallocated memory in OS as it stops the software from seizing control of an excessive amount of memory and may cause damage that will impact other software which is currently being used or may create a loss of saved data. These resources of memory protection also help in detecting malicious or harmful applications, that may after damaged the processes of the operating system.

Methods of memory protection:

There are various methods for protecting a process from accessing memory that has not been allocated and some of the commonly used methods are given below:

Memory Protection using Keys: The concept of using memory protection with keys can be found in most modern computers with the purpose of paged memory organization and for the dynamic distribution between the parallel running programs. The keys are based on the use of special codes as we can verify the compliance between using arrays of memory cells and the number of running programs. This key method gives the users a process to impose page-based protections without any modification in the page tables.

Memory Protection using Rings: In CS, the domains related to ordered protection are called Protection Rings. This method helps in improving fault tolerance and provides security. These rings are arranged in a hierarchy from most privileged to least privileged. In the single-level sharing OS, each and every segment has a protection ring for the process of reading, writing, and executing operations of the process. If there is a use of a higher ring number by the process then the ring number for the segment creates a fault. But we do have some methods for calling the procedures safely that can run in a lower ring number and then return to the number of the higher ring.

Capability-based addressing: It is a method of protecting the memory that cannot be seen in modern commercial computers. Here, the pointers (objects consisting of a memory address) are restored by the capabilities objects that can only be created with the protected instructions and may only execute by a kernel, or by another process that is authorized to execute and therefore it gives an advantage of controlling the unauthorized processes in creating additional separate address spaces in memory.

Memory Protection using masks: The masks are used in the protection of memory during the organization of paging. In this method, before the implementation, the page numbers are indicated to each program and are reserved for the placement of its directives. Here the allocated pages for the program are now given the control of the operating system in the form of mask code (an n-bit binary code) which is formed for every working program that is determined by the bit number of OD pages.

Memory Protection using Segmentation: It is a method of dividing the system memory into different segments. The data structures of x86 architecture of OS like local descriptor table and global descriptor table are used in the protection of memory.

Memory Protection using Simulated segmentation: With this technique, we can monitor the program for interpreting the machine code instructions of system architectures. Through this, the simulator can help in protecting the memory by using a segmentation using the scheme and validating the target address of every instruction in real-time.

Memory Protection using Dynamic tainting: Dynamic tainting is a technique that consists of marking and tracking certain data in a program at runtime as it protects the process from illegal memory accesses. In tainting technique, we taint a program to mark two kinds of data i.e., memory in the data space and the pointers.



Similar Reads

Hardware Protection and Type of Hardware Protection
In this article, we are going to learn about hardware protection and its types. So first, lets take a look at the type of hardware which is used in a computer system. We know that a computer system consists of hardware components like processor, monitor, RAM and many more. The important thing is, that the operating system ensures that these devices
3 min read
Protection in OS : Domain of Protection, Association, Authentication
In this, we will cover the overview of Protection in OS, it's need and Goals of protection. And mainly will focus on Protection in OS like Domain of Protection, Association, Authentication in details. Let's discuss it one by one. Need of protection OS : To ensure data safety, process and program safety against illegal user access, or even program a
7 min read
Operating Systems | Memory Management | Question 1
Which of the following page replacement algorithms suffers from Belady’s anomaly? (A) FIFO (B) LRU (C) Optimal Page Replacement (D) Both LRU and FIFO Answer: (A) Explanation: Belady’s anomaly proves that it is possible to have more page faults when increasing the number of page frames while using the First in First Out (FIFO) page replacement algor
1 min read
Operating Systems | Input Output Systems | Question 5
Which of the following is major part of time taken when accessing data on the disk? (A) Settle time (B) Rotational latency (C) Seek time (D) Waiting time Answer: (C) Explanation: Seek time is time taken by the head to travel to the track of the disk where the data to be accessed is stored.Quiz of this Question
1 min read
System Protection in Operating System
Introduction: System protection in an operating system refers to the mechanisms implemented by the operating system to ensure the security and integrity of the system. System protection involves various techniques to prevent unauthorized access, misuse, or modification of the operating system and its resources. There are several ways in which an op
3 min read
Difference between Volatile Memory and Non-Volatile Memory
Volatile Memory: It is the memory hardware that fetches/stores data at a high-speed. It is also referred as temporary memory. The data within the volatile memory is stored till the system is capable of, but once the system is turned off the data within the volatile memory is deleted automatically. RAM (Random Access Memory) and Cache Memory are som
3 min read
Difference between Virtual memory and Cache memory
Cache Memory: Cache memory increases the accessing speed of CPU. It is not a technique but a memory unit i.e a storage device. In cache memory, recently used data is copied. Whenever the program is ready to be executed, it is fetched from main memory and then copied to the cache memory. But, if its copy is already present in the cache memory then t
2 min read
Random Access Memory (RAM) and Read Only Memory (ROM)
Memory is a fundamental component of computing systems, essential for performing various tasks efficiently. It plays a crucial role in how computers operate, influencing speed, performance, and data management. In the realm of computer memory, two primary types stand out: Random Access Memory (RAM) and Read-Only Memory (ROM). Understanding the diff
8 min read
Best Ways for Operating System Memory Management
Prerequisite - Partition Allocation Methods Contiguous Memory Allocation :Probably the least difficult technique for the memory portion is to isolate memory into a few fixed partitions. Each partition contains precisely one process. The level of multi-programming relies upon the number of partitions. In the different partition technique, when a par
7 min read
Memory Management in Operating System
The term memory can be defined as a collection of data in a specific format. It is used to store instructions and process data. The memory comprises a large array or group of words or bytes, each with its own location. The primary purpose of a computer system is to execute programs. These programs, along with the information they access, should be
14 min read
Levels of Memory in Operating System
Memory hierarchy of a computer system it handles differences in speed. "Hierarchy" is a great way to say "order of thinks" like top to bottom, fast to slow, most important to least important. If you look at the memory hierarchy inside the computer, according to the fastest to the slowest: 1. CPU Registers 2. Caches memory 3. Main or Primary Memory
3 min read
Virtual Memory in Operating System
Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of the main memory. The addresses a program may use to reference memory are distinguished from the addresses the memory system uses to identify physical storage sites and program-generated addresses are translated automatically to the cor
15 min read
Operating Systems - GATE CSE Previous Year Questions
Solving GATE Previous Year's Questions (PYQs) not only clears the concepts but also helps to gain flexibility, speed, accuracy, and understanding of the level of questions generally asked in the GATE exam, and that eventually helps you to gain good marks in the examination. Previous Year Questions help a candidate practice and revise for GATE, whic
4 min read
Operating Systems | Set 2
Following questions have been asked in GATE CS exam. 1. Consider a machine with 64 MB physical memory and a 32-bit virtual address space. If the page size is 4KB, what is the approximate size of the page table? (GATE 2001) (a) 16 MB (b) 8 MB (c) 2 MB (d) 24 MB Answer: (c) Explanation: A page entry is used to get address of physical memory. Here we
4 min read
Operating Systems | Set 4
Following questions have been asked in GATE CS exam. 1. Using a larger block size in a fixed block size file system leads to (GATE CS 2003) a) better disk throughput but poorer disk space utilization b) better disk throughput and better disk space utilization c) poorer disk throughput but better disk space utilization d) poorer disk throughput and
3 min read
Operating Systems | Set 5
Following questions have been asked in GATE 2012 exam. 1. A process executes the code fork (); fork (); fork (); The total number of child processes created is (A) 3 (B) 4 (C) 7 (D) 8 Answer (C) Let us put some label names for the three lines fork (); // Line 1 fork (); // Line 2 fork (); // Line 3 L1 // There will be 1 child process created by lin
3 min read
Operating Systems | Set 6
Following questions have been asked in GATE 2011 CS exam. 1) A thread is usually defined as a 'light weight process' because an operating system (OS) maintains smaller data structures for a thread than for a process. In relation to this, which of the followings is TRUE? (A) On per-thread basis, the OS maintains only CPU register state (B) The OS do
4 min read
Operating Systems | Set 10
Following questions have been asked in GATE 2008 CS exam. 1) The data blocks of a very large file in the Unix file system are allocated using (A) contiguous allocation (B) linked allocation (C) indexed allocation (D) an extension of indexed allocation Answer (D) The Unix file system uses an extension of indexed allocation. It uses direct blocks, si
3 min read
Operating Systems | Set 7
Following questions have been asked in GATE CS exam. 1) Let the time taken to switch between user and kernel modes of execution be t1 while the time taken to switch between two processes be t2. Which of the following is TRUE? (GATE CS 2011) (A) t1 > t2 (B) t1 = t2 (C) t1 2) A system uses FIFO policy for page replacement. It has 4 page frames with n
3 min read
Operating Systems | Set 8
Following questions have been asked in GATE 2009 CS exam. 1) In which one of the following page replacement policies, Belady’s anomaly may occur? (A) FIFO (B) Optimal (C) LRU (D) MRU Answer (A) Belady's anomaly proves that it is possible to have more page faults when increasing the number of page frames while using the First in First Out (FIFO) pag
3 min read
Operating Systems | Set 9
Following questions have been asked in GATE 2009 CS exam. 1) In the following process state transition diagram for a uniprocessor system, assume that there are always some processes in the ready state: Now consider the following statements: I. If a process makes a transition D, it would result in another process making transition A immediately. II.
3 min read
Operating Systems | Set 11
Following questions have been asked in GATE 2008 CS exam. 1) A process executes the following code for (i = 0; i The total number of child processes created is (A) n (B) 2^n - 1 (C) 2^n (D) 2^(n+1) - 1; Answer (B) F0 // There will be 1 child process created by first fork / \ F1 F1 // There will be 2 child processes created by second fork / \ / \ F2
3 min read
Operating Systems | Set 12
Following questions have been asked in GATE CS 2007 exam. 1) Consider a disk pack with 16 surfaces, 128 tracks per surface and 256 sectors per track. 512 bytes of data are stored in a bit serial manner in a sector. The capacity of the disk pack and the number of bits required to specify a particular sector in the disk are respectively: (A) 256 Mbyt
3 min read
Operating Systems | Set 13
Following questions have been asked in GATE CS 2007 exam. 1) A virtual memory system uses First In First Out (FIFO) page replacement policy and allocates a fixed number of frames to a process. Consider the following statements: P: Increasing the number of page frames allocated to a process sometimes increases the page fault rate. Q: Some programs d
4 min read
Operating Systems | Set 14
Following questions have been asked in GATE CS 2006 exam. 1) Consider three CPU-intensive processes, which require 10, 20 and 30 time units and arrive at times 0, 2 and 6, respectively. How many context switches are needed if the operating system implements a shortest remaining time first scheduling algorithm? Do not count the context switches at t
3 min read
Operating Systems | Set 15
Following questions have been asked in GATE CS 2006 exam. 1) Consider three processes (process id 0, 1, 2 respectively) with compute time bursts 2, 4 and 8 time units. All processes arrive at time zero. Consider the longest remaining time first (LRTF) scheduling algorithm. In LRTF ties are broken by giving priority to the process with the lowest pr
4 min read
Operating Systems | Set 16
Following questions have been asked in GATE CS 2005 exam. 1) Normally user programs are prevented from handling I/O directly by I/O instructions in them. For CPUs having explicit I/O instructions, such I/O protection is ensured by having the I/O instructions privileged. In a CPU with memory mapped I/O, there is no explicit I/O instruction. Which on
4 min read
Operating Systems | Set 17
Following question has been asked in GATE 2012 CS exam. Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location X, increments it by the value i, and returns the old value of X. It is used in the pseudocode shown below to implement a busy-wait lock. L is an unsigned integer shared variable initialized to
2 min read
Operating Systems | Process Management | Question 6
Consider the following code fragment: if (fork() == 0) { a = a + 5; printf("%d,%d\n", a, &a); } else { a = a –5; printf("%d, %d\n", a, &a); } Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE? (A) u = x + 10 and v = y (B) u = x +
2 min read
Operating Systems | CPU Scheduling | Question 1
Consider three processes (process id 0, 1, 2 respectively) with compute time bursts 2, 4 and 8 time units. All processes arrive at time zero. Consider the longest remaining time first (LRTF) scheduling algorithm. In LRTF ties are broken by giving priority to the process with the lowest process id. The average turn around time is: (A) 13 units (B) 1
1 min read