Question: #linux #operation system #c The program memory ( also called virtual memory ) is divided into pages which are brought to the main memory as

#linux #operation system #c The program memory (also called virtual memory) is divided into pages which are brought to the main memory as needed.
We will implement virtual memory of a computer with one program. The memory mapping system in the exercise is demonstrated in the figure below:
The main function of the exercise will consist of a sequence of load and store commands (random) according to the example at the end of the exercise. The heart of the exercise will deal with
In the implementation a page table that maps the logical to physical pages
The load function:
Receives a logical address that must be accessed for reading. The function ensures that the relevant page of the address is in memory. if the address
that the load function received is invalid, print an error message to stderr and continue the simulation.
The store function:
Receives an address to which one must access for writing. Here too, as in load, you must make sure that the page of the address in question is in memory. in any case of
Error An error message should be printed to stderr and return from the function and continue the simulation.
The flow chart of the program:
Explain the diagram
For each address we receive, first check in the page table if the page to which the address belongs is in the main memory.
If the page is already in the main memory, a conversion from a virtual address to a physical address must be made: it must be done only with the help of actions
binaries
o A virtual address consists of the page number + the offset within the page, so given a virtual address we would like to identify it first
All to which page the address belongs and what is the offset.
o The page table will return to us for the page we found what the appropriate frame is and thus we can access the appropriate frame in memory
the main one and advance in it according to the offset for reading or writing.
If the page is not in the main memory, it must be fetched from the appropriate place. There are several options here:
right-Access: check if this is a page with read-only permissions (text) or if it can be written (heap+stack+bss+data)
o In case there are no write permissions, then the page is in the executable file. (Why?)
o In case there are write permissions, i.e. it is a page of type stack_heap, bss, data then check:
o If the page is "dirty", that means things have been written on it and changes have been made to it (in other words, there was already a call with store to this page)
If so, then the page is in the swap file.
If not, check if it is a stack_heap, bss or data page
If stack_heap, bss we will allocate a new and empty page. (here a situation of malloc or a call to a function is simulated)
Otherwise, address data is read from the file
The data structures of the system
1) database_sim struct: the main data structure of the program. Will be defined in the c file of your program. Contains the following fields:
table_page the page table of the system. A pointer to an array of
.) struct page_descriptor is defined later
fd_swap the descriptor file of the swap file, to which we will refer pages from the main memory (received by open of
the file(.
fd_program the descriptor file of the program file that we "run" in the system and where the data resides (received on
by opening the file (..
memory_main - we will implement it as an array of characters of size 40
struct sim_database
{
page_descriptor page_table[NUM_OF_PAGES]; //pointer to page table
int swapfile_fd; //swap file fd
int program_fd; //executable file fd
char main_memory[MEMORY_SIZE];
int text_size;
int data_size;
int bss_heap_stack_size;
};
The table of pages (table_page) will be realized as an array of type descriptor_page with size PAGES_OF_NUM as follows:
typedef struct page_descriptor
{
unsigned int V; // valid
unsigned int D; // dirty
unsigned int P; // permission
unsigned int frame_swap; //the number of a frame/swap if in case it is page-mapped
} page_descriptor;
We initialize the sizes of the arrays like this:
#define PAGE_SIZE 8
#define NUM_OF_PAGES 25
#define MEMORY_SIZE 40
# define SWAP_SIZE 200
The functions you are required to write
1) system_init initializes the work environment
sim_database * sim_db = init_system(char exe_file_name[], char swap_file_name[], int text_size, int data_size, int
bss_heap_stack_size )
The function accepts
1. Executable file name
2. swap file name
3. The size of the size_text in bytes
4. The size of the size_ data in bytes
In bytes bss_heap_stack_size e size 5. void print_swap (struct sim_database * mem_sim);
6) Printing the table_page -
void print_page_table(struct sim_database * mem_sim);
clear_system )
7.void clear_system(struct sim_database * mem_sim);
Closes the open files and frees dynamic memory
#linux #operation system #c The program memory (

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!