File system
The goal of this lab is to implement the equivalent of the function mmap in xv6.
The system call (beginner level)
Start by getting the code from xv6:
- git clone https://gitlab.inf.telecom-sudparis.eu/csc4508/xv6-tsp.git if you start with a new copy
- or git checkout master if you already have a local copy of the repository
Then create a local branch to work:
- void* mmap(void* addr, int size, int prot, int flag, int fd, int offset). This function implements exactly mmap, but during the first part of the lab, you will ignore the prot and flag parameters.
- and void munmap(void* addr, int size)
These functions must be added in a new file named mmap.c.
For the moment, the mmap function must display its arguments on the terminal before returning the pointer -1, which means that an error has occurred, and the munmap function must display its arguments on the terminal. To simplify error handling, create a mmap.h file in which you will add the following macro:
- open the file README in read/write mode (remember to include fcntl.h to have access to the O_RDONLY flags, or O_RDWR),
- calculate the file size with the fstat function (remember to include stat.h to have the definition of the stat structure),
- map the whole file to the address 0x10000000,
- display the content of the memory mapped on the terminal,
- unmap the file.
For each system call, check the return value and stop the program in the case of an error. For now, the program should terminate with an error since the mmap function returns an error.
To access the solution, you must first add the repository which contains the solution with the following command sequence:
Then, you can access the solution with the following command:
You can show the difference to the original code with git diff master.
Initial implementation (advanced level)
- delete the entries in the page table that have already been associated,
- free the physical pages already allocated.
This function removes the association corresponding to the virtual address vaddr of the pgdir page table. This function also returns the virtual address in the kernel at which is associated the physical page which has just been dissociated from vaddr (this address is the one returned by kalloc).
To access the solution, if it is not already done, add the repository which contains the solution with the following command sequence:
Then, you can access the solution with the following command:
You can show the difference with the original code with git diff master (or git diff mmap-soluce-exo1 to see the difference with the previous exercise).
Software segment (adventurer level)
To access the solution, if it is not already done, add the repository which contains the solution with the following command sequence:
Then, you can access the solution with the following command:
You can show the difference with the original code with git diff master (or git diff mmap-soluce-exo2 to see the difference with the previous exercise).
Duplication of processes (guru level)
Modify the code accordingly. Consider that, in order to allocate a segment, it is necessary to find a free entry. For this, you can consider that if the segment address is 0, the entry is free.
Deleting a mapping (guru level)
Segmentation (guru level)
- A text segment containing the program code,
- A data segment containing the initialized data of the program,
- A bss segment containing the data not initialized, i.e. initialized with 0s, of the program,
- A stack segment of fixed size,
- A heap segment that can grow.
All these segments must be defined as not being of the type MAP_SHARED so that they are duplicated automatically during a fork().
To build these segments, you need to analyze and modify the exec function (file exec.c), especially starting from line 42.
Also modify the fork() function to stop calling copyuvm which takes care of copying the memory of a process (the memory of the segments which you have just defined). Instead, you should always call setupkvm() which allows to create a new page table in which the kernel is mapped. If your code is correct, depending on the MAP_SHARED flag, the parent's segments will all be copied to the child, are shared with the child.
Copy-on-write fork, (master guru level)
We only provide a solution to the first three exercises. To access the solution, if it is not already done, add the repository which contains the solution with the following command sequence:
Then, you can access the solution with the following command: