HW4: xv6 system callsIn this homework you will modify xv6 to add a system call. You can use the same setup as for the HW2: Xv6 boot, and HW3: Xv6 hello world. Part One: dump() system callYour first task is to add a new system call to xv6. The main point of the exercise is for you to see some of the different pieces of the system call machinery. Your new system call will dump memory of a current process on the console Specifically, your new system call will have the following interface: int dump(void *addr, void *buffer, int size);Where addr is the address inside the process memory from where the memory is dumped, buffer is the user allocated buffer where content of the user memory is saved, and size is the size of the memory region to dump. You will have to dump the entire memory of the process on the console, i.e., starting from address 0 to proc->sz. You can find proc->sz by invoking the sbrk() system call and passing 0 as an argument. You will of course have to loop through the entire memory and dump it on the console in a format similar to how we dumped the stack in HW2. E.g., like this: 0x7bcc: 0x00007db7 0x00000000 0x00000000 0x00000000 0x7bdc: 0x00000000 0x00000000 0x00000000 0x00000000 0x7bec: 0x00000000 0x00000000 0x00000000 0x00000000 0x7bfc: 0x00007c4d 0x8ec031fa 0x8ec08ed8 0xa864e4d0 0x7c0c: 0xb0fa7502 0xe464e6d1 0x7502a864 0xe6dfb0fa 0x7c1c: 0x16010f60 0x200f7c78 0xc88366c0 0xc0220f01You should create a user-level program dump that calls your new system call; here's an example template for dump.c: #include "types.h" #include "stat.h" #include "user.h" #include "syscall.h" int main(int argc, char *argv[]) { // Dump memory here exit(); } In order to make your new dump program available to run from the xv6 shell, add _dump to the UPROGS definition in Makefile. Your strategy for making the dump system call should be to clone all of the pieces of code that are specific to some existing system call, for example the "uptime" system call. You should grep for uptime in all the source files, using grep -n uptime *.[chS]. When you're done, typing dump to the xv6 shell prompt should print entire memory of the process on the console. Extra credit (5%): annotate text, guard, stack, and heapChange your dump.c program to annotate which memory is which, i.e., text, guard, stack, and heap. You should be clever about detecting the section boundaries, i.e., look at the value of the stack pointer, rounding it to the page boundary, making a conclusion that above this page is heap, below is the guard page, etc. Extra credit (15%): implement ps, dump memory of a process with specific process idImplement the ps tool that lists all processes running on the system. For that you should implement yet another system call that returns information for a process.The new system call will get information about the processes running in the system and return it to the user program. Specifically, your new system call will have the following interface: int getprocinfo(int pid, struct uproc *up);Where pid is the process id of the target process, and struct uproc is a structure that describes the process, i.e., contains the following information about the process: process name, process id, parent process id, size of process memory, process state, whether process is waiting on a channel, and whether it's been killed. You will have to define the struct uproc and implement the ps utility by querying the system about all processes in the system. You should create a user-level program that calls your new date system call. When you're done, typing ps to an xv6 shell prompt should print all processes running in the system and information about them. Finally, change the dump system call to take the process id as an argument. Now you can use ps to enumerate all processes in the system, and then dump memory for one of them. Your new dump tool (dump.c) should also accept a command line parameter, a process id which memory is dumped. E.g., typing dump 2 on the shell command prompt should dump the memory of the process with id 2. Submit Submit your answers on Canvas HW4 Syscalls as a compressed tar file of your xv6 source tree (after running make clean). You can use the following command to create a compressed tar file vagrant@odin$ cd /vagrant/ics143a vagrant@odin$ make clean vagrant@odin$ tar -czvf hw4.tgz xv6-public |
|||
Updated: November, 2017
|