Document 2

docx

School

University of Texas *

*We aren’t endorsed by this school

Course

312

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

2

Uploaded by swethaprincess893

Report
XV6—MMAP-PART2 MMAP : We created a base address MMAPBASE (0x40000000) which is half of the KERNELBASE address. In mman.h we defined the flags for mmap and a struct maplist. Maplist keeps track of the memory mappings allocated by mmap. -#define PROT_WRITE 1 -#define MAP_FILE 1 -#define MAP_ANONYMOUS 0 -struct maplist { - struct maplist *next; - void *addr; - int len; - int prot; - int flags; - int offset; - int fd; - int allocated; -}; In proc.h , we add a reference to the head of the maplist as part of the struct proc. In proc.c, userinit() function we initialize the head of the map list to 0 and in fork() function, we added a logic such that the child processes inherit the map list from parent processes. We added a new file mmap.c containing the below methods. void *mmap(void *addr, uint length, int prot, int flags, int fd, int offset): Inputs: addr - suggestion for starting address, mmap will round up to page aligned addr if needed length- length of region to allocate (in bytes) prot - protection level on mapped region flags - info flags for mapped region fd - file descriptors offset- offset for a file-backed allocation Returns: starting address of the newly mapped Used flags (MAP_ANONYMOUS, MAP_FILE) to check the type of memory being mapped. If the memory being mapped is related to a file, then we checked for any errors in fd. Then we incremented the ref count of the file pointer using filedup and did a fileseek on the incremented ref count file pointer. int munmap(void *addr, uint length): munmap takes the address and length given. It will check the maplist to see if the address and the length are valid and match. If they match, it will deallocate the memory from the current process. We then added the deallocuvm() to unmap the
duplicate file descriptor and kmfree() to free the list element tracking the mapped regions. Decremented the open count using fileclose() Returns: 0 if successful, -1 in case of failiures. We also included few helper classes to manage the maplist data structure. ( ml_new_entry, ml_add, ml_remove, ml_find). int msync(void* start_addr, int length): this function writes changes to memory region back to file Returns: 0 if successful, -1 in case of failiures. We added system calls for kmalloc, kmfree, mmap, munmap and msync in sysproc.c . We defined the system calls in syscall.h, syscall.c, usys.s FileSeek : Added a new function in file.c int fileseek(struct file* f, uint offset); This function will change the offset field inside the struct file to allow xv6 to seek around in the file before doing a read or write operation. Implemented the INODE lock similar to the filestat function in the file.c PageFault Handler: Deleted the static in the declaration of mappages() in vm.c Added a switch case in trap function of trap.c for case T_PGFLT: pagefault_handler(tf); break; Added a new function pagefault_handller to trap.c void pagefault_handler(struct trapframe *tf): This function handles the page faults. Used PGROUNDDOWN(va) to round the faulting virtual address down to a page boundary. We added a logic to check if the fault address is can be found in the processes linked list of reserved mapped region and allocated memory for that region. Added few cprintf statements as suggested.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help