forked from sahil2441/Nachos-Operating-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME_HW5
98 lines (66 loc) · 3.74 KB
/
README_HW5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
##################################################################
##################################################################
Sahil Jain
110281300
##################################################################
##################################################################
MAJOR CHANGES MADE:
Mmap System Call
-- void *Mmap(char *name, int *sizep);
Created a new system call that takes as arguments a string name and an integer pointer sizep.
From exception handler when this system call is made, the following method is called:
nachos.kernel.userprog.Syscall.mmap(String, int)
which in turn calls the method
nachos.kernel.userprog.AddrSpace.executeMmap(String, int)
This method checks whether a file with the given file name exists. If it doesn't the method return 0.
If it does it calls the method
nachos.kernel.userprog.AddrSpace.extendAddressSpace(int)
to extend the page table array in address space by the required size.
Then it copies the size of the size of the file in a byte buffer and copies that into the
Machine.mainmemory.
And finally, before returning that virtual address, it updates the map
nachos.kernel.userprog.AddrSpace.openFileMap
that keeps track of virtual address and OpenFile. This is done to handle cases in which Mmap syscall
is executed with multiple file names in sequence.
##################################################################
-- Handling Pagefault Exception
From exception handler the page fault occurs when:
which == MachineException.PageFaultException
and the following method is called that takes argument as the virtual address:
nachos.kernel.userprog.AddrSpace.handlePageFaultException(int)
This method allocates memory for physical page and sets the valid flag =true.
Then it copies the file at the given page into byte array and copies the byte array into the
Machine.mainmemory at the physical address.
We also maintain the map
nachos.kernel.userprog.AddrSpace.mapOfVirPNStartingIndex
that keeps track of the virtual page number and the starting index of the file, from where we started reading
data. We use this map in the Munmap syscall.
##################################################################
Munmap System Call:
-- int Munmap(void *addr);
Created a new system call that takes as its argument an address that was returned by a previous call to Mmap.
The method in syscall:
nachos.kernel.userprog.Syscall.Munmap(int)
is called from Exception handler and this method further calls:
nachos.kernel.userprog.AddrSpace.executeMunmap(int)
This method deallocates the memory from physical memory manager by iterating over the page table array and
checking which pages are dirty. And then copies the pages from main memory into the file.
The method:
nachos.kernel.userprog.AddrSpace.printBuffer(byte[])
can be used to check the contents of the buffer array and has been created for debugging purposes.
A successful call to Munmap returns 1, else returns 0.
##################################################################
-- Test Cases:
I've created a few test cases for testing the system calls:
mmap_test1,mmap_test2, and mmap_test3
mmap_test1 is a simple test case to evaluate the the basic functionality of the system calls.
mmap_test2 accesses the returned address several times to cause multiple page fault.
In mmap_test3 Mmap syscall return 0 and therefore Munmap call doesn'e execute successfully and returns 0.
To run these test cases, enter this in the Run configuration:
-d -f -x test/mmap_test1
-d -f -x test/mmap_test2
-d -f -x test/mmap_test3
The method:
nachos.kernel.Nachos.executeOpertions()
creates a file in the file system with the name as specified in the user programs.