Andrew login ID please print in BLOCK capital letters Full Name Recitation Section or TA 15 213 18 243 Fall 2009 Final Exam Monday Dec 14 2009 Instructions Make sure that your exam is not missing any sheets then write your full name Andrew login ID and recitation section A H on the front The exam has a maximum score of 141 points This exam is OPEN BOOK You may use any books or notes you like No calculators or other electronic devices are allowed Please make sure we can read your andrew ID It needs to be in block capital letters Page 1 of 24 Multiple Choice 1 18 Virtual Memory 2 18 Stack 3 16 Signals 4 9 Assembly 5 12 Network Programming 6 12 Floats and Ints 7 10 Processes and Threads 8 12 Synchronization 9 14 Concurrency 10 10 File I O 11 10 Extra Credit 12 and 13 0 TOTAL 141 Page 2 of 24 Problem 1 Multiple Choice 18 points A Which of these uses of caching is not crucial to program performance a b c d e Caching portions of physical memory Caching virtual memory pages Caching virtual addresses Caching virtual address translations None of the above i e they are all crucial B For which values can X not be equal to Z in the code below circle all that apply int X CONSTANT float Y X int Z Y a b c d e For large positive values of CONSTANT e g 1 000 000 000 For large negative values of CONSTANT e g 100 For small positive values of CONSTANT e g 100 For small negative values of CONSTANT e g 1 000 000 000 None of the above i e X Z in all of these cases C What is the maximum number of page faults per second that can be serviced in a system with a disk that has the following characteristics 10 000 RPM rotation speed 6ms per full revolution average seek time of 7ms 1000 sectors per track Assume that all in memory pages that get replaced are clean a b c d 50 100 77 Not enough information to determine the answer D If a parent process forks a child process to which resources might they need to synchronize their access to prevent unexpected behavior a b c d file descriptors malloc ed memory stack None of the above E Which of the following is not a situation that results in a signal being sent to a process a b c d e A process terminates A process accesses an invalid memory address A new connection arrives on a listening socket A divide by zero None of the above i e all result in a signal being sent F Mr Fred says that if one of a process s memory addresses is bigger than a second one then its corresponding value must appear before the second one s value in physical memory True or False a True b False Page 3 of 24 Problem 2 Virtual Memory 18 points In this question you will write macros that will can be used to implement virtual memory on an x86 32 bit machine You won t be writing any virtual memory code just some helpful macros Here is the layout for our VM structure with 32 bit virtual and physical addresses and 4kb pages Virtual addresses are structured as such 31 22 21 12 11 0 PDI PTI PPO A Page Directory Entry PDE is structured as such 31 12 11 1 0 PTBA Unused W P Writable Present A Page Table Entry PTE is structured as such 31 12 11 1 0 PBA Unused W P Writable Present You do not need to know how these values connect for this question just know where each value is bitwise Page 4 of 24 Each of these should easily fit on a single line Do not make any assumptions about the type of the values passed to these macros Given a virtual address returns the Physical Page Offset define VA GET PPO virtual Given a virtual address returns the page table index define VA GET PTI virtual Given a virtual address returns the page directory index define VA GET PDI virtual Given a page directory entry returns the page table base address define PDE GET PTBA pde Given a page table entry returns the page base address define PTE GET PBA pte Returns one if this page table entry is present define IS PRESENT pte Returns one if this page table entry is writable define IS WRITABLE pte Returns a new Page Table Entry with the present bit set to the value in Present either 1 or 0 define SET PRESENT pte pres Returns a new Page Table Entry with the writable bit set to the value in Writable either 1 or 0 define SET WRITABLE pte write As a closing note you just wrote the hardest part of virtual memory translations congratulations Page 5 of 24 Problem 3 The Stack Question 16 points Answer the following questions about x86 stack convention in 32 bit mode A How does the call instruction modify the stack B How does the leave instruction modify the stack C How does the ret instruction modify the stack D How are arguments passed to a function E How are return values passed back to a calling function F Please draw a stack region that details how a function would call printf I lost d s n 5 marbles The first argument to printf the format string is located at 0xcafebeef and the string marbles is located at 0xbeefbabe Please draw the stack area modified created during this function call from the argument build area to the top of the stack as it exists just after the call instruction Page 6 of 24 G Why is this code potentially harmful Hint it has to do with the stack int fd accept server clientAddr clientlen pthread create tid NULL handle request void fd Confession time Did you do that on proxylab Page 7 of 24 Problem 4 Signals 9 points Consider the C code below Assume that no errors prevent any processes from running to completion and that a process terminated by an uncaught signal has an exit status of 0 int count 0 void killhandler int sig printf SIGKILL received n return void childhandler int sig int status wait status count WEXITSTATUS status return main int i for loop iterator pid t pid 3 pids of child processes Signal SIGKILL killhandler Signal SIGCHLD childhandler Fork 3 child processes for i 0 i 3 i pid i fork if pid i If child process Signal SIGKILL SIG DFL exit 5 Parent process only for i 0 i 3 i kill pid i SIGKILL sleep 5 printf count d n count exit 0 A What is the maximum number of times SIGKILL received could be printed B List all possible values of count that could be printed Page 8 of 24 Problem 5 Assembly Leaping to Conclusions 12 points Your classmate Meddie Tartan is trying to write a more advanced proxy Her goal is to write …
View Full Document